Severity:

HIGH RISK

(7.3)

SQL Injection in SourceCodester Pharmacy Sales and

CVE-2026-7087

Deferred

Vulnerability type

Category:

SQL Injection

CWE:

CWE-74, CWE-89

Impact:

Unauthorized Database Access and Modification

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_sales endpoint through improper handling of the ID parameter.

A remote attacker can manipulate this parameter to inject arbitrary SQL, potentially accessing, modifying, or deleting backend database data when the vulnerable code path is invoked.

Affected context

The vulnerability occurs in the server-side processing of AJAX requests to /ajax.php?action=save_sales, where user-controlled input in the ID parameter is incorporated into database queries without sufficient sanitization or parameterization.

This typically manifests in deployments where the application trusts request parameters coming from the browser, and where the database account used by the application has broad privileges over the pharmacy sales and inventory data.

Exploit preconditions

  • Attack surface: HTTP(S) endpoint /ajax.php?action=save_sales
  • Required access: Ability to send crafted requests to the web application (usually over the network); authentication requirements depend on how the endpoint is exposed in each deployment
  • Trigger point: Server-side code that builds and executes SQL statements using the ID argument from the request
  • Why exploitation is possible: The application concatenates the ID parameter directly into SQL queries without using prepared statements or robust input validation, enabling injection of attacker-controlled SQL fragments

Why this happens

The underlying issue is a classic instance of CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').

Application logic in /ajax.php?action=save_sales appears to construct SQL queries by interpolating the ID parameter directly into the query string.

Because special characters and SQL control tokens are not correctly neutralized and no parameterized queries are used, the database interprets parts of the user input as executable SQL rather than as data.

CWE-74 (Improper Neutralization of Special Elements in Output) is related in that unsanitized data flows into a downstream interpreter (the SQL engine), but the primary pattern here is direct SQL injection through unsafe query construction.

Potential impact

  • Disclosure of sensitive pharmacy sales, customer, and inventory records
  • Unauthorized modification or deletion of sales and inventory data
  • Creation or manipulation of user accounts and roles stored in the database
  • Corruption of transactional records leading to financial or compliance issues
  • Potential execution of database-specific functions that could facilitate further compromise of the hosting environment, depending on database configuration and privileges

General mitigation guidance

Effective mitigation typically focuses on eliminating direct string concatenation in SQL statements and reducing trust in client-supplied data:

  • Use parameterized queries or prepared statements for all database operations involving user input, especially the ID parameter in save_sales logic
  • Enforce strict server-side validation and type-checking on identifiers (e.g., ensuring ID is numeric and within expected ranges before use)
  • Implement a centralized data access layer that abstracts query building and enforces safe patterns by default
  • Restrict the database account used by the application to the least privileges necessary (no superuser/admin roles) to limit impact if an injection occurs
  • Apply defense-in-depth with input normalization, allowlists for expected values, and consistent encoding when data crosses trust boundaries

How teams detect issues like this

Detection commonly combines secure SDLC practices with targeted testing:

  • Static analysis: Configure SAST tools and linters to flag dynamic SQL construction, string concatenation involving request parameters, and direct use of $_GET/$_POST variables in query strings
  • Code review: Look for patterns where ID or other request parameters flow into SQL without parameter binding; verify that all data access paths in ajax.php use prepared statements and constrained types
  • Dynamic testing: Use automated scanners and manual penetration testing to probe the ID parameter on /ajax.php?action=save_sales for injection behavior (e.g., time delays, error-based responses, or Boolean-based differences)
  • Runtime monitoring: Enable database logging for anomalous or malformed queries and monitor web application logs for unusual error messages or patterns that suggest tampering with SQL syntax

Sources

SourceLink
github.comgithub.com/nidieaaa/test/issues/2
vuldb.comvuldb.com/submit/800060
vuldb.comvuldb.com/vuln/359662
vuldb.comvuldb.com/vuln/359662/cti
sourcecodester.comsourcecodester.com/

Frequently asked

questions

Yes. An attacker who can reach the /ajax.php?action=save_sales endpoint over the network and send crafted requests can attempt to exploit the SQL injection, subject to any authentication or access controls placed in front of the endpoint.

It depends on how the application is configured. If the vulnerable AJAX endpoint is accessible to unauthenticated users, then anonymous exploitation is possible. If it is only reachable after login, an attacker would first need valid credentials or a separate way to bypass authentication.

Replace any dynamic SQL construction involving the ID parameter (and other user inputs) with parameterized queries or prepared statements, combined with strict server-side validation of types and allowed values. Centralizing database access logic and enforcing these patterns framework-wide significantly reduces the chance of recurrence.

Adopt a secure coding standard that forbids string concatenation in SQL, mandate use of prepared statements, and integrate static analysis and security-focused code review into the development lifecycle. Additionally, design APIs so that only validated, typed parameters reach the data access layer, and ensure database roles follow least-privilege principles.

Find out what's already
exploitable in your codebase.