Summary
A SQL Injection vulnerability in SourceCodester Online Food Ordering System v1.0 allows untrusted data from the id parameter in admin/view_product.php to be embedded directly into SQL queries.
Under typical deployments, an attacker who can control this parameter may manipulate database queries, potentially leading to data exfiltration, modification, or full compromise of the underlying database.
Affected context
The vulnerability occurs in the administrative product viewing functionality (admin/view_product.php) of the Online Food Ordering System v1.0.
It is exposed when the application builds SQL statements using the id request parameter without proper parameterization or input validation.
In many installations, this page may be reachable after authentication, but weak access controls, shared accounts, or reused endpoints can widen exposure beyond intended administrators.
Exploit preconditions
- Attack surface: HTTP(S) interface of the Online Food Ordering System, specifically requests handled by
admin/view_product.php. - Required access: Ability to send crafted requests that influence the
idparameter; in some configurations this may require admin or staff credentials, in others misconfigurations or shared links may expose it more broadly. - Trigger point: Server-side execution of a dynamically constructed SQL query where the
idvalue is concatenated directly into the query string. - Why exploitation is possible: The application trusts the
idparameter and incorporates it into SQL without using prepared statements or robust input handling, matching the pattern described in CWE-89 (Improper Neutralization of Special Elements used in an SQL Command).
Why this happens
The root cause is the construction of SQL statements using string concatenation with untrusted input from the id parameter in admin/view_product.php.
Instead of using bound parameters or prepared statements, the code likely interpolates the id value directly into the query (e.g., in a WHERE clause), allowing SQL control characters and fragments supplied by an attacker to alter the intended query structure.
This is a classic instance of SQL Injection as described by CWE-89, where data and control planes are not separated, enabling external input to influence the logic of database commands.
Potential impact
- Extraction of sensitive customer information, including orders and associated personal data.
- Unauthorized viewing, modification, or deletion of product, order, and user records.
- Creation of new administrative or application accounts within the database.
- Bypassing of authentication or authorization checks enforced at the application or data layer.
- Potential execution of database-specific functions leading to file read/write or code execution on the underlying server, depending on DBMS configuration.
- Disruption of service availability through destructive queries, such as dropping or truncating tables.
General mitigation guidance
Effective mitigation centers on consistently separating untrusted input from SQL command structure and hardening database interactions:
- Adopt parameterized queries or prepared statements for all database operations, ensuring the
idand other user-controlled fields are always passed as bound parameters. - Apply strict server-side validation and type enforcement for identifiers like
id(e.g., ensuring they conform to expected numeric or UUID formats rather than arbitrary strings). - Introduce a minimal data access layer or repository pattern that centralizes query construction and prohibits ad-hoc string-concatenated SQL.
- Limit database privileges for the application account to only the operations truly required (least-privilege), reducing impact if injection occurs.
- Where feasible, segment sensitive data across schemas or databases and restrict cross-access to limit blast radius.
- Consider using stored procedures designed to accept only typed parameters and not dynamic SQL fragments as a defense-in-depth measure.
How teams detect issues like this
Detection can combine static code inspection, dynamic testing, and runtime monitoring:
- Use static analysis rules or secure code scanning tools to flag string concatenation in SQL queries and direct interpolation of request parameters such as
$_GET['id']or$_POST['id']. - During code review, explicitly check data access layers and controller code for any query fragments built from request parameters, ensuring all queries use parameter binding.
- Integrate automated security testing (DAST) that attempts SQL Injection payloads against endpoints, including authenticated admin paths like
admin/view_product.php. - Configure logging around database errors and anomalous query patterns (e.g., unexpected UNIONs, OR 1=1 clauses) and feed them into SIEM systems for correlation.
- Apply Web Application Firewall (WAF) rules tuned to detect common SQL Injection patterns while monitoring for false positives, using them as an additional detection and mitigation layer.

