Summary
A SQL injection vulnerability in the Users deletion functionality of SourceCodester Hospitals Patient Records Management System 1.0 allows crafted ID parameters to alter backend database queries.
When exploited over the network, this can enable attackers to access, modify, or delete sensitive application and patient-related data through the /classes/Users.php?f=delete endpoint.
Affected context
The vulnerability exists in the web-based Hospitals Patient Records Management System, specifically in the code handling user deletion requests at /classes/Users.php?f=delete.
It appears when the ID request parameter is passed directly into SQL statements without sufficient validation, sanitization, or use of parameterized queries.
Deployments where this endpoint is exposed to untrusted networks or where user management is accessible to low-privileged or untrusted users are more likely to be at risk.
Exploit preconditions
- Attack surface: HTTP(S) endpoint
/classes/Users.php?f=delete - Required access: Ability to send requests to the application (often remote, potentially authenticated depending on deployment configuration)
- Input vector: The
IDparameter in the request query string or body - Trigger point: Server-side SQL query construction in
Users.phpduring processing of delete requests - Why exploitation is possible: User-supplied
IDis concatenated into SQL queries without using prepared statements or robust input handling, allowing attacker-controlled syntax to be executed by the database
Why this happens
This issue is a classic example of CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
The application constructs SQL statements by directly embedding the ID parameter into a query string, relying on ad-hoc filtering (if any) instead of parameter binding.
Because SQL metacharacters and control tokens in the ID value are not properly neutralized, the database interprets attacker-supplied content as part of the command, not as data.
The mention of CWE-74 (Improper Neutralization of Special Elements in Output Used by a Downstream Component) reflects that unsafe data flows from the HTTP layer to the database without a trust boundary check or transformation that constrains it to a safe subset.
Potential impact
- Attackers may extract or infer sensitive data stored in the database, including user or patient-related records depending on schema design.
- Malicious actors could delete or modify user accounts, impacting administrative control and system integrity.
- Compromised queries can lead to broader data tampering, including alteration of permissions or configuration records.
- In some environments, chained attacks might leverage SQL injection to achieve remote code execution via database-level features.
- The availability of a public exploit may increase the likelihood of automated or opportunistic attacks.
General mitigation guidance
Effective mitigation focuses on constraining how application code interacts with the database and treating all inputs as untrusted:
- Prefer parameterized queries or prepared statements for all database operations, especially for CRUD operations on users and other security-sensitive entities.
- Apply strict server-side validation and type enforcement on identifiers like
ID, ensuring they conform to expected formats (e.g., integers) before use. - Centralize database access patterns in a data access layer that disallows ad-hoc string concatenation of SQL fragments.
- Implement least-privilege database accounts so that even if a query is manipulated, the account cannot perform destructive or administrative operations beyond its intended scope.
- Consider using an ORM or query builder that encourages safe-by-default query construction practices.
How teams detect issues like this
Organizations can approach detection through a combination of code-focused and behavior-focused techniques:
- Static analysis rules targeting dynamic SQL construction, string concatenation in SQL contexts, or direct interpolation of request parameters into queries.
- Manual code review focusing on controller and class methods that handle deletion or administrative actions, checking that all query parameters are bound safely.
- Runtime protections such as a web application firewall (WAF) tuned to flag and optionally block common SQL injection patterns on endpoints like
/classes/Users.php?f=delete. - Logging and monitoring of database errors and unusual query patterns (e.g., sudden spikes in DELETE or UNION SELECT statements) that may indicate probing or exploitation attempts.

