Severity:

HIGH RISK

(7.3)

SQL Injection in chk_prod_availability Endpoint of Pharmacy

CVE-2026-6187

Deferred

Vulnerability type

Category:

SQL Injection

CWE:

CWE-74, CWE-89

Impact:

Data Exposure and Database Compromise

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

A SQL injection vulnerability in SourceCodester Pharmacy Sales and Inventory System 1.0 allows untrusted input from the ID parameter in /ajax.php?action=chk_prod_availability to be concatenated directly into SQL queries.

A remote attacker can manipulate this parameter to interfere with database operations, potentially accessing or modifying sensitive pharmacy and inventory data when the vulnerable endpoint is exposed.

Affected context

This vulnerability occurs in deployments of SourceCodester Pharmacy Sales and Inventory System 1.0 where the /ajax.php?action=chk_prod_availability endpoint is reachable over the network.

The issue manifests when the ID argument is taken from HTTP requests and used in backend SQL queries without proper parameterization or validation.

It is most relevant in environments where the application connects to a database with privileges to read and write inventory, sales, customer, or related business data.

Exploit preconditions

  • Attack surface: HTTP(S) interface exposing /ajax.php?action=chk_prod_availability
  • Required access: Network access to the application (no prior authentication may be required, depending on deployment)
  • Input vector: User-controlled ID parameter passed to ajax.php
  • Trigger point: Execution of dynamically constructed SQL queries that embed ID directly
  • Why exploitation is possible: The backend logic interpolates the ID value into SQL statements without using prepared statements or adequate input neutralization, enabling crafted input to alter query structure.

Why this happens

The root cause aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection') and is related to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component.

Application code handling /ajax.php?action=chk_prod_availability appears to build SQL commands by concatenating the ID parameter directly into the query string.

Because SQL control characters (such as quotes, comment markers, or operators) are not reliably neutralized and no parameterized query mechanism is enforced, an attacker can inject additional SQL clauses or entirely new statements.

This pattern represents a broader class of vulnerabilities where downstream interpreters (here, the database engine) are given mixed data and control input without clear separation.

Potential impact

  • Extraction of pharmacy inventory records and potentially sensitive business data
  • Unauthorized modification of product availability, pricing, or stock information
  • Deletion or corruption of database tables, impacting application availability
  • Bypassing of application-level authorization checks enforced by SQL conditions
  • Use of the database as a pivot point for further compromise, depending on configuration and underlying platform

General mitigation guidance

Effective mitigation focuses on preventing untrusted input from altering SQL command structure and minimizing the blast radius of any injection that does occur.

Recommended defensive patterns include:

  • Using parameterized queries / prepared statements for all database access, ensuring the ID value is always treated strictly as data.
  • Applying strict server-side validation and type enforcement on the ID parameter (e.g., enforcing numeric-only IDs or whitelisting expected formats).
  • Centralizing data access logic so that raw SQL construction is avoided in controller or AJAX handlers.
  • Employing least-privilege database accounts with only the minimum required permissions for the operations performed by the AJAX endpoint.
  • Implementing consistent input handling policies that treat all client-supplied data as untrusted, regardless of perceived sensitivity of the endpoint.

How teams detect issues like this

Detection typically involves a combination of code-centric and behavior-centric approaches:

  • Static analysis: Configure SAST rules to flag dynamic SQL construction where request parameters (e.g., $_GET['ID'], $_POST['ID'], or similar) flow directly into query strings.
  • Code review: During manual reviews, scrutinize AJAX handlers such as ajax.php for any SELECT, INSERT, UPDATE, or DELETE statements built via string concatenation or interpolation.
  • Dynamic testing: Use web application security testing tools or custom test harnesses to send crafted ID values (including quotes and SQL control characters) and monitor for error messages, anomalies, or unexpected responses.
  • Runtime monitoring: Enable database query logging or use database firewalls / query anomaly detection to identify suspicious patterns such as always-true conditions, stacked queries, or unusual access from the application account.

Sources

SourceLink
github.comgithub.com/lingzezzz/lingze/issues/3
vuldb.comvuldb.com/submit/797375
vuldb.comvuldb.com/vuln/357109
vuldb.comvuldb.com/vuln/357109/cti
sourcecodester.comsourcecodester.com/

Frequently asked

questions

Yes. If the /ajax.php?action=chk_prod_availability endpoint is accessible over the network, a remote attacker can send crafted requests containing malicious ID values.

Not necessarily. Exploitation depends on how the application is deployed and whether access to the AJAX endpoint is gated by authentication. If the endpoint is reachable without login, anonymous exploitation may be possible.

The most robust fix is to replace any dynamically built SQL using the ID parameter with parameterized queries or prepared statements, combined with strict server-side validation that enforces the expected data type and format.

Adopt a development standard that forbids direct string concatenation for SQL, mandates the use of parameterized APIs, and enforces centralized input validation. Complement this with automated static analysis, security-focused code review checklists, and regular application security testing.

Find out what's already
exploitable in your codebase.