Summary
A SQL injection vulnerability in SourceCodester Hospitals Patient Records Management System 1.0 allows attackers to manipulate database queries via the ID parameter in /classes/Master.php?f=save_patient.
When reachable over the network, this flaw can enable remote attackers to read, modify, or delete patient records and other backend data by injecting crafted SQL into the vulnerable parameter.
Affected context
The vulnerability occurs in the patient management workflow exposed by /classes/Master.php?f=save_patient, where the ID argument is processed as part of database operations.
It is relevant in deployments where the application is accessible over a network and user-controlled ID values are incorporated into SQL statements without robust input handling or query parameterization.
Typical at-risk contexts include internet-facing or intranet hospital systems where authentication or input validation may be insufficient to prevent crafted requests.
Exploit preconditions
- Attack surface: HTTP endpoint
/classes/Master.php?f=save_patientexposed via the web server. - Required access: Network access to the application; depending on deployment, this may or may not require authentication.
- Trigger point: Submission of a request where the
IDparameter contains crafted SQL payloads that are concatenated into a query. - Why exploitation is possible: The server-side code appears to embed the
IDvalue directly into SQL statements without using prepared statements or rigorous sanitization, allowing injected SQL to be executed by the database engine.
Why this happens
The core issue aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Application logic likely constructs SQL statements by concatenating the ID parameter into query strings, treating external input as trusted and failing to neutralize SQL meta-characters or use parameterized queries.
Additionally, aspects of CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component are present, because untrusted data is passed into the downstream SQL interpreter without adequate normalization or context-aware escaping.
This insecure pattern allows attacker-controlled input to alter the structure and semantics of database commands.
Potential impact
- Attackers may extract sensitive patient records and other confidential medical data.
- Attackers could modify or delete records, impacting data integrity and clinical workflows.
- Attackers can potentially create or escalate user accounts, altering authorization states.
- Attackers may leverage SQL injection to execute database-level functions or pivot to other parts of the infrastructure, depending on DB configuration and privileges.
General mitigation guidance
Effective mitigation centers on removing direct string concatenation between user input and SQL and enforcing strict trust boundaries for database operations.
Recommended defensive patterns include:
- Using parameterized queries or prepared statements for all database interactions involving user-controlled values, especially
IDparameters. - Applying strict server-side validation of identifiers and numeric fields (e.g., accepting only expected formats and ranges) before they reach the data access layer.
- Centralizing data access logic in a repository or ORM layer that enforces safe query construction by default.
- Limiting database permissions for the application account to only the operations and tables required, reducing blast radius if a query is subverted.
- Implementing contextual output encoding or escaping at the database boundary when parameterization is not possible, while treating this as a fallback rather than a primary control.
How teams detect issues like this
Detection often relies on a combination of code-level analysis and runtime observation:
- Static analysis: Configure SAST rules to flag dynamic SQL construction patterns (string concatenation, interpolation) involving request parameters like
$_GET['ID'],$_POST['ID'], or equivalent framework inputs. - Code review signals: During manual review, look for inline SQL in controller or handler code, lack of prepared statements, and direct use of request variables in query strings.
- Policy enforcement: Enforce secure coding guidelines that require prepared statements and prohibit raw concatenation in database access code, with automated checks in CI.
- Runtime monitoring: Use web application firewalls (WAF) or RASP solutions configured with SQL injection signatures and anomaly detection on endpoints such as
/classes/Master.php, correlating alerts with unusual database query patterns.

