Summary
SourceCodester Pharmacy Sales and Inventory System 1.0 contains a SQL injection vulnerability in the /ajax.php?action=delete_customer endpoint, where the ID parameter is not safely handled before being used in a database query.
A remote attacker can manipulate this parameter to inject arbitrary SQL, potentially reading, modifying, or deleting data within the application's database.
Affected context
The issue occurs in the web application's AJAX handler at /ajax.php?action=delete_customer, specifically when processing the ID argument used to identify a customer record.
The vulnerability is present when incoming request parameters are directly concatenated into SQL statements without robust input validation, parameterization, or output encoding at the database boundary.
Any deployment that exposes this endpoint over a network and relies on a relational database backend is potentially affected, especially where database privileges are broad or shared across multiple tables.
Exploit preconditions
- Attack surface: HTTP interface of the Pharmacy Sales and Inventory System, particularly the
/ajax.php?action=delete_customerendpoint. - Required access: Ability to send crafted requests to the vulnerable endpoint; this may be unauthenticated or low-privileged depending on application access controls.
- Trigger point: Submission of a malicious
IDparameter value that is incorporated into an SQL query. - Why exploitation is possible: The application constructs SQL queries using string concatenation or interpolation with the raw
IDparameter instead of using parameterized queries or strict type handling. As a result, attacker-controlled input can alter the structure of the SQL statement executed by the database.
Why this happens
This vulnerability stems from improper neutralization of special elements used in SQL commands (CWE-89) and insufficient output encoding or escaping in dynamically constructed queries (related to CWE-74).
In the delete_customer flow, the ID parameter appears to be trusted and embedded directly into a SQL statement, such as in a DELETE or SELECT query, without binding as a typed parameter.
This insecure pattern allows attacker-supplied input to break out of the intended query context and inject additional SQL operations, reflecting the classic SQL injection bug class where application logic blurs the boundary between data and code.
Potential impact
- An attacker may delete arbitrary customer records from the database.
- An attacker could extract sensitive information from other database tables, depending on the query and schema.
- An attacker may modify or corrupt application data, impacting inventory accuracy and transaction integrity.
- An attacker could escalate impact to full database compromise if the database user has extensive privileges.
- An attacker may chain SQL injection with other weaknesses (e.g., weak authentication) to gain broader control over the application environment.
General mitigation guidance
Effective mitigation centers on strictly separating data from SQL command logic and minimizing trust in client-supplied parameters.
Recommended defensive patterns include:
- Consistently using parameterized queries or prepared statements for all database operations, including simple
DELETEcalls based on IDs. - Enforcing strict server-side validation and type checking for identifier parameters (e.g., ensuring
IDis a numeric value within expected bounds) before interacting with the database layer. - Centralizing database access through a data access layer that prohibits ad hoc string-built SQL and enforces safe query construction APIs.
- Applying least-privilege principles to the database account used by the application, limiting its ability to access or modify unrelated tables or perform administrative operations.
- Implementing defense-in-depth controls such as application-level error handling that avoids exposing raw SQL errors and database structure in responses.
How teams detect issues like this
Detection generally involves combining code-centric analysis with runtime monitoring:
- Static analysis: Configure SAST tools or linters to flag dynamic SQL construction patterns (e.g., string concatenation with request parameters,
$_GET/$_POSTusage in query strings) and enforce the use of prepared statements. - Code review: During manual review, focus on AJAX handlers and CRUD endpoints to identify where request parameters like
IDare directly interpolated into SQL queries without parameter binding or validation. - Security testing: Use targeted dynamic testing (DAST) to send crafted payloads through the
/ajax.php?action=delete_customerendpoint, observing for anomalous responses, SQL errors, or data changes that indicate injectable queries. - Operational monitoring: Monitor database logs and web server logs for suspicious query patterns, such as unexpected operators, comment markers, or always-true conditions in WHERE clauses, which may suggest exploitation attempts.

