Summary
Online Hospital Management System 1.0 contains a SQL injection vulnerability in the /viewappointment.php endpoint, where the delid parameter is used unsafely in database queries.
A remote attacker can manipulate this parameter to interfere with the application's SQL logic, potentially accessing, modifying, or deleting sensitive hospital and patient data when the vulnerable code path is invoked.
Affected context
The vulnerability occurs in the Online Hospital Management System 1.0 within the /viewappointment.php page, specifically when handling the delid request parameter.
It is most relevant in deployments where the application is exposed over a network (e.g., internet or intranet) and where database queries are constructed dynamically using request parameters.
The risk increases when the database user has broad privileges, or when patient, appointment, or staff records are stored within the same database without strict access separation.
Exploit preconditions
- Attack surface: HTTP interface of /viewappointment.php.
- Required access: Network-level access to the application; no special local system access is required.
- User interaction: Typically none beyond sending crafted HTTP requests to the vulnerable endpoint.
- Trigger point: Handling of the delid parameter when building SQL queries for viewing or deleting appointments.
- Why exploitation is possible: User-controlled input is directly concatenated or interpolated into SQL statements without robust parameterization, escaping, or input validation, allowing attackers to alter the intended query structure.
Why this happens
The underlying issue aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command (SQL Injection).
The application constructs SQL queries in /viewappointment.php using the delid parameter without enforcing strict separation between data and SQL syntax.
This is commonly implemented via string concatenation or templating of raw request values into the SQL command.
This insecure pattern also reflects CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component, where untrusted data is passed to the database (a downstream component) without proper neutralization, allowing attackers to inject additional SQL operators, clauses, or statements.
Potential impact
- Attackers may read sensitive data from appointment or related tables, potentially including patient identifiers and scheduling information.
- An attacker could modify or delete appointment records, impacting data integrity and operational workflows.
- Under permissive database privileges, attackers may create, alter, or drop tables, affecting wider parts of the application.
- In some configurations, SQL injection may be leveraged to run database-specific functions that could lead to further compromise of the application or host environment.
General mitigation guidance
Effective mitigation focuses on enforcing strict separation between user input and SQL logic.
Common defensive patterns include:
- Using parameterized queries or prepared statements for all database access involving user-supplied data.
- Applying strict server-side validation and canonicalization of identifiers like delid (e.g., enforcing numeric-only input where appropriate).
- Centralizing database access through a data access layer that prohibits raw query string concatenation.
- Applying least privilege to the database user account so that even if a query is abused, it cannot perform high-impact operations such as dropping tables or accessing unrelated schemas.
- Encoding or neutralizing special SQL characters where dynamic query elements are unavoidable, while still preferring parameterization.
How teams detect issues like this
Detection can combine code-level analysis with runtime monitoring:
- Static analysis: Configure SAST tooling to flag string-based SQL construction that uses request parameters (such as delid) without prepared statements.
- Code review: Look for patterns where $_GET, $_POST, or other request sources are concatenated into SQL queries in PHP scripts like /viewappointment.php.
- Security testing: Use automated and manual penetration testing to send crafted input in database-related parameters, verifying whether unexpected SQL errors or behavioral anomalies occur.
- Runtime monitoring: Enable database query logging and anomaly detection rules to identify unusual query patterns, such as injected logical operators or UNION queries originating from web requests.
- Policy enforcement: Establish coding guidelines and CI checks that reject new code introducing ad-hoc SQL concatenation.

