Severity:

HIGH RISK

(7.3)

SQL Injection in SourceCodester Hospitals Patient Records

CVE-2026-9355

Deferred

Vulnerability type

Category:

SQL Injection

CWE:

CWE-74, CWE-89

Impact:

Unauthorized data access and modification via SQL Injection

Severity:

HIGH RISK

(7.3)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

SourceCodester Hospitals Patient Records Management System 1.0 contains a SQL injection vulnerability in the patient history save functionality, where the ID parameter is not safely handled before being used in database queries.

A remote attacker can manipulate this parameter to inject arbitrary SQL, which may lead to unauthorized access, modification, or disclosure of patient records when the vulnerable endpoint is reachable.

Affected context

The issue occurs in the /classes/Master.php?f=save_patient_history endpoint responsible for saving patient history records.

It affects deployments where user-controlled input (specifically the ID argument) is passed into SQL queries without robust validation or parameterization.

Any environment that exposes this functionality over a network, such as internet-facing or intranet hospital deployments, can be at risk if no protective controls (e.g., prepared statements, strict input validation, or WAF rules) are in place.

Exploit preconditions

  • Attack surface: HTTP(S) endpoint /classes/Master.php?f=save_patient_history
  • Required access: Ability to send web requests to the affected application; authentication may or may not be required depending on local configuration
  • Trigger point: Supplying crafted values in the ID parameter (e.g., via query string or POST data) that are subsequently embedded into SQL queries
  • Why exploitation is possible: The application dynamically constructs SQL statements using user input without proper parameter binding or escaping, allowing attacker-controlled content to alter query structure

Why this happens

The underlying bug is improper construction of SQL statements from untrusted input, mapping directly to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').

The ID parameter is likely concatenated into a SQL query string or interpolated directly, without using prepared statements, bound parameters, or rigorous input sanitization.

Additionally, this fits the broader pattern described by CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component, because data intended as simple values is treated as part of a command for the downstream database engine.

This insecure pattern allows an attacker to switch from providing data to providing executable query fragments.

Potential impact

  • Unauthorized reading of patient records and related medical data
  • Modification or deletion of patient history entries, potentially impacting clinical decisions
  • Extraction of user account data, including password hashes or session-related information
  • Escalation of privileges within the application via manipulation of authentication or authorization tables
  • Potential pivot to underlying database server features (e.g., file read/write or command execution) depending on configuration

General mitigation guidance

Effective mitigation focuses on removing direct string concatenation and treating all external input as untrusted:

  • Use parameterized queries or prepared statements for every database interaction involving user input, including the ID field
  • Apply strict server-side validation and type enforcement (e.g., ensuring IDs are numeric and within expected ranges) before touching the database layer
  • Centralize query construction in a data access layer that enforces safe patterns by default
  • Implement least-privilege database accounts so the application can only access the minimum required tables and operations
  • Add defense-in-depth controls such as input normalization and, where appropriate, a web application firewall (WAF) with rules for SQL injection patterns

How teams detect issues like this

Detection typically combines code-centric review with runtime monitoring:

  • Static analysis rules that flag dynamic SQL construction, string concatenation with $_GET, $_POST, or similar request variables, and APIs known for unsafe query building
  • Manual code review focusing on controller and model methods handling patient histories, validating that every query uses bound parameters
  • Central logging of database errors and suspicious query patterns (e.g., presence of tautologies, UNION clauses, or stacked statements), coupled with anomaly detection
  • CI/CD integration that runs automated security scanning tools against the codebase and, optionally, DAST scanners against test instances to identify injectable parameters

Sources

SourceLink
github.comgithub.com/yan-124/yan/issues/3
vuldb.comvuldb.com/submit/813020
vuldb.comvuldb.com/vuln/365318
vuldb.comvuldb.com/vuln/365318/cti
sourcecodester.comsourcecodester.com/

Frequently asked

questions

Yes. As long as the /classes/Master.php?f=save_patient_history endpoint is accessible over the network, an attacker can attempt to exploit the SQL injection remotely.

The attacker needs the ability to send HTTP requests to the affected endpoint. Whether they must be authenticated depends on how the application is configured; if the patient history function is exposed to unauthenticated users, no login is required.

Replace all dynamically constructed queries that use user-supplied input with parameterized queries or prepared statements, and ensure that inputs like ID are strictly validated and typed before being passed to the database.

Adopt secure coding standards mandating parameterized queries, introduce automated static analysis for injection patterns, centralize database access in a hardened data layer, and require security review for any new or modified endpoints handling critical data such as patient records.

Find out what's already
exploitable in your codebase.