Summary
SourceCodester Pharmacy Sales and Inventory System 1.0 contains a SQL injection vulnerability in the /ajax.php?action=save_customer endpoint via the ID parameter.
A remote attacker can manipulate this parameter to inject arbitrary SQL queries, potentially accessing or modifying backend database data when the vulnerable code path is invoked.
Affected context
The vulnerability exists in the web-based Pharmacy Sales and Inventory System when handling customer-related AJAX requests through /ajax.php?action=save_customer.
It appears in deployments where user-controlled input (the ID argument) is directly incorporated into database queries without robust parameterization or sanitization.
The issue is typically exposed on internet- or intranet-facing instances where the application's AJAX endpoints are reachable over HTTP/S and customer data operations are performed dynamically.
Exploit preconditions
- Attack surface: HTTP/S endpoint at /ajax.php?action=save_customer
- Required access: Network-level access to the web application (no special privileges implied by the description)
- User-controlled input: The ID parameter supplied to the endpoint can be crafted by an attacker
- Trigger point: Execution of database queries that embed the ID value into SQL statements without safe parameterization
- Why exploitation is possible: The server-side logic constructs SQL queries by concatenating or interpolating the ID value directly into SQL, violating strong separation between code and data as described by CWE-89.
Why this happens
The root cause is improper neutralization of special elements used in SQL commands (CWE-89).
The backend logic for /ajax.php?action=save_customer relies on building SQL statements using raw request parameters, likely concatenating the ID argument into WHERE or INSERT/UPDATE clauses.
Because no parameterized queries, stored procedures with strict parameter binding, or equivalent defenses are applied, database interpreters treat crafted input as part of the SQL command itself.
This pattern aligns with command/markup injection (CWE-74), where untrusted data is introduced into a structured language context without appropriate escaping or binding, enabling arbitrary query manipulation.
Potential impact
- Unauthorized reading of sensitive customer or inventory records from the database
- Modification or deletion of customer, sales, or inventory data, affecting business integrity
- Creation of fraudulent records (e.g., fake customers or transactions)
- Potential extraction of authentication hashes or session-related data stored in the database
- Database service disruption via destructive queries (e.g., table drops or heavy, resource-intensive queries)
- Use of the database as a pivot point for further attacks if additional flaws (e.g., xp_cmdshell, file write capabilities) exist
General mitigation guidance
Effective mitigation focuses on eliminating direct injection channels and reducing trust in all external input:
- Prefer parameterized queries or prepared statements for all database access paths, ensuring that user data is always bound as data, not code.
- Centralize database access through a data access layer that enforces safe query construction patterns across the application.
- Apply strict server-side validation for parameters like ID (e.g., enforce numeric types, length, and format constraints) before they reach the database layer.
- Use context-appropriate escaping only as a secondary safeguard, not as the primary defense, when constructing dynamic fragments.
- Restrict database account privileges so the application can perform only necessary operations, limiting damage if a query is successfully manipulated.
- Adopt secure-by-default coding guidelines and development frameworks that encourage ORM usage or other safe abstractions for database interactions.
How teams detect issues like this
Detection typically combines code-level inspection with behavioral monitoring:
- Static analysis rules that flag any SQL query constructed via string concatenation or interpolation of request parameters (especially ID fields) within PHP or similar server-side code.
- Manual code review checklists that require verification of prepared statement usage for all queries in endpoints such as /ajax.php, with special attention to AJAX handlers that commonly evolve rapidly.
- CI/CD pipeline policies that block merges when unsafe SQL patterns are detected or when new endpoints bypass the shared database abstraction layer.
- Dynamic testing using web vulnerability scanners or custom fuzzers to probe parameters like ID for error-based, boolean-based, or time-based injection behaviors.
- Monitoring of database logs and application logs for anomalous query patterns (e.g., unexpected OR 1=1 clauses, stacked queries, or syntax errors involving user-controlled values).

