Summary
A critical SQL injection flaw in the Fruits Bazar PHP/Mysqli ecommerce project allows attackers to manipulate database queries through unvalidated product ID parameters.
When user-supplied input is directly concatenated into SQL in show_price_by_pdtId.php, an attacker can bypass application logic, exfiltrate data, or modify database contents.
Affected context
The vulnerability occurs in the price lookup functionality of the Fruits Bazar ecommerce project when product IDs from HTTP requests are used to build SQL queries without proper sanitization.
It is most relevant in deployments where:
- The application is publicly accessible over the internet
- The database account used by the PHP application has broad read/write privileges
- Input validation or parameterization is missing or inconsistently applied in
show_price_by_pdtId.php
Exploit preconditions
- Attack surface: Web endpoint
/show_price_by_pdtId.phpaccepting product identifiers via query string, form data, or AJAX requests - Required access: Network access to the web application; no special privileges are typically needed beyond reaching the endpoint
- Trigger point: Execution of SQL queries that incorporate the attacker-controlled product ID directly into the query string
- Why exploitation is possible: The application interpolates raw user input into SQL without prepared statements or robust escaping, allowing crafted input to alter the intended query structure
Why this happens
The root cause aligns with CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
In this case, the PHP code in show_price_by_pdtId.php constructs SQL statements by concatenating request parameters (such as product IDs) into query strings.
Without using prepared statements with bound parameters or strict input validation, special characters introduced by an attacker are interpreted as part of the SQL syntax, enabling injection of additional clauses or entirely different queries.
Potential impact
- Attackers may read sensitive customer and order information from the database
- Attackers could modify product prices, inventory records, or user data
- Attackers can potentially create or escalate user accounts, including administrative roles
- Attackers may delete or corrupt tables, leading to loss of availability and data integrity issues
- Attackers could chain this access to further compromise the underlying server or other connected systems, depending on database permissions and configuration
General mitigation guidance
Effective mitigation focuses on treating all external input as untrusted and ensuring SQL queries are constructed safely by design.
Common defensive patterns include:
- Consistently using prepared statements (parameterized queries) for all database operations instead of concatenating strings
- Applying strict server-side validation and normalization for product IDs and similar parameters (e.g., enforcing numeric types)
- Minimizing database privileges for the application account so that even a successful injection has limited effect
- Centralizing data access logic in a well-reviewed layer to avoid ad hoc query construction across multiple PHP files
- Adopting secure-by-default database access abstractions or ORM layers that discourage direct string-based query building
How teams detect issues like this
Organizations can detect SQL injection risks in applications like Fruits Bazar using a combination of:
- Static analysis rules that flag dynamic SQL creation, especially concatenation of
$_GET,$_POST, or other user-controlled variables - Code review checklists that require verification of prepared statements and proper validation for every database interaction
- Runtime monitoring and logging for anomalous query patterns, such as unexpected use of
UNION,OR 1=1, or comment sequences originating from web inputs - Security testing (including automated scanners and manual penetration testing) focused on input vectors reaching
show_price_by_pdtId.phpand similar endpoints - CI/CD integration of automated tools that enforce policies against unsafe query construction before code is merged

