Severity:

HIGH RISK

(7.3)

SQL Injection in SourceCodester Pharmacy Sales and

CVE-2026-7128

Deferred

Vulnerability type

Category:

SQL Injection

CWE:

CWE-74, CWE-89

Impact:

Data Exfiltration and Integrity Compromise 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 Pharmacy Sales and Inventory System 1.0 contains a SQL injection vulnerability in the /ajax.php?action=save_type endpoint, where the ID parameter is not safely handled before being used in database queries.

A remote attacker can send crafted requests to manipulate backend SQL statements, potentially accessing, modifying, or deleting pharmacy inventory and sales data when the application is exposed over a network.

Affected context

This vulnerability arises in deployments of SourceCodester Pharmacy Sales and Inventory System 1.0 where the /ajax.php?action=save_type endpoint is reachable (e.g., from the internal LAN or internet-facing web server).

The issue manifests when the ID argument supplied to this AJAX action is incorporated into SQL queries without robust parameterization or sanitization.

Typical scenarios include administrative or staff workflows that trigger save_type operations for managing medicine or product types via the web UI, where user-controllable input can reach the database layer directly.

Exploit preconditions

  • Attack surface: HTTP(S) interface exposing /ajax.php?action=save_type
  • Required access: Network access to the web application; depending on configuration, either unauthenticated or low-privileged authenticated access to the affected endpoint
  • User input vector: The ID parameter in AJAX requests, supplied via query string or POST body
  • Trigger point: Server-side processing of ajax.php handling the save_type action and building SQL statements with the ID value
  • Why exploitation is possible: The ID parameter is concatenated or interpolated directly into SQL queries (or otherwise insufficiently constrained), aligning with CWE-89, and possibly combined with improper input neutralization (CWE-74) before reaching the database

Why this happens

The core issue is the construction of SQL queries using user-controlled data from the ID parameter without enforcing strict separation between code and data.

Rather than using parameterized queries or prepared statements, the application appears to interpolate the raw ID value into the SQL string, allowing an attacker to alter the intended query structure.

This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), and may also reflect CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component, because the web layer passes unvalidated input directly to the database engine, a downstream component that interprets special characters as commands.

At an abstract level, the insecure pattern is: taking untrusted input from HTTP parameters and embedding it in SQL without robust binding or whitelisting, creating an injection channel anytime the save_type functionality is invoked.

Potential impact

  • An attacker may read sensitive application data, including inventory, sales records, and customer-related information stored in the database.
  • An attacker could modify or delete pharmacy product types and related records, corrupting operational data and reports.
  • An attacker may create or manipulate application accounts or permissions if user management data is accessible via the same database.
  • An attacker could perform database-level operations such as truncating tables or, depending on DBMS configuration, executing system-level functions.
  • An attacker may chain the SQL injection with other weaknesses (e.g., weak authentication or file write primitives) to escalate to remote code execution in some environments.

General mitigation guidance

Effective mitigation focuses on eliminating the injection channel and tightening how data is passed to the database:

  • Use parameterized queries / prepared statements for all database interactions involving user-supplied values, including the ID parameter in save_type operations.
  • Apply strict input validation on all server-side parameters, especially identifiers, enforcing expected types (e.g., integer-only) and ranges, and rejecting anything that doesn't conform.
  • Centralize database-access logic behind a data access layer that enforces parameter binding and disallows raw query string concatenation.
  • Employ least-privilege database accounts, ensuring that the application's DB user has only the minimal permissions required, reducing impact if injection occurs.
  • Consider adding a server-side allowlist for actions and IDs, especially for management endpoints, to further constrain what parameters can represent.
  • Implement a secure-by-default coding standard that forbids dynamic SQL construction with raw user input, supported by internal code templates and guidelines.

How teams detect issues like this

Organizations can use a combination of static and dynamic techniques to detect and monitor for similar issues:

  • Static analysis: Configure SAST tools or linters to flag direct string concatenation involving SQL keywords and HTTP parameters, especially in files like ajax.php handling dynamic actions.
  • Code review: During manual reviews, look for patterns where request parameters (e.g., $_GET, $_POST, $_REQUEST) are used directly in SQL query strings without binding, as well as ad-hoc query building in AJAX handlers.
  • Security testing: Use application security testing (DAST) to send crafted payloads to /ajax.php?action=save_type and monitor for database errors, anomalous responses, or time delays indicative of SQL injection.
  • Database monitoring: Enable logging or monitoring on the database side to detect suspicious queries, such as those containing unexpected concatenated expressions or classic injection patterns.
  • Policy enforcement: Introduce CI/CD policies that block deployments if SQL calls do not go through approved, parameterized query helpers or ORM layers that enforce binding.

Sources

SourceLink
github.comgithub.com/lonelyuan/vunls/issues/13
vuldb.comvuldb.com/submit/800973
vuldb.comvuldb.com/vuln/359727
vuldb.comvuldb.com/vuln/359727/cti
sourcecodester.comsourcecodester.com/

Frequently asked

questions

Exploitability depends on how exposed /ajax.php?action=save_type is. If reachable over the internet or by untrusted users on a network, a remote attacker could reliably exploit the SQL injection, especially because public exploit details are available.

Not necessarily. If the affected endpoint is reachable without authentication, anonymous attackers can exploit it. In some deployments, the route might require a logged-in user role, in which case any user with access to the save_type function could be a potential attacker.

The safest pattern is to refactor all affected database operations to use parameterized queries or prepared statements exclusively, combined with strict server-side validation of all parameters (e.g., ensuring ID is a numeric identifier) and removing any direct concatenation of user input into SQL.

Prevention typically involves adopting a standard data access layer that enforces parameter binding, establishing coding guidelines that prohibit raw SQL string concatenation with user input, integrating SAST/DAST checks into CI, and conducting regular security-focused code reviews for all new endpoints and AJAX handlers.

Find out what's already
exploitable in your codebase.