Summary
A SQL injection vulnerability in the save_category action of Actions.php in SourceCodester Online Food Ordering System v1.0 allows untrusted data in the name parameter to be embedded directly into database queries.
An authenticated attacker who can submit crafted category names may inject arbitrary SQL, potentially leading to data exfiltration, modification, or application compromise.
Affected context
This issue arises in the category management functionality of the Online Food Ordering System when processing requests to Actions.php with the save_category action.
The vulnerability is present when the application constructs SQL statements using the name parameter directly (e.g., from POST or GET data) without proper parameterization or robust input handling.
It primarily affects deployments where authenticated users can create or edit categories and where the application's database account has broad permissions on the backing database.
Exploit preconditions
- Attack surface: Web application HTTP interface (typically via POST/GET requests to
Actions.php). - Required access: Authenticated access with the ability to invoke the
save_categoryaction (e.g., user roles allowed to add or edit categories). - Trigger point: Submission of a specially crafted
nameparameter value during category creation or update. - Why exploitation is possible: The application interpolates the
namevalue directly into SQL queries without using parameterized statements or adequate escaping, allowing attacker-controlled input to alter the structure of the SQL command.
Why this happens
The root cause is the dynamic construction of SQL queries using string concatenation that directly incorporates user-supplied data from the name parameter.
This corresponds to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection'), where inputs containing SQL metacharacters (such as quotes, operators, or comment markers) are not properly separated from query logic.
Instead of relying on parameterized queries or prepared statements, the code trusts that the incoming name field is benign, allowing attackers to extend or modify the intended query.
Potential impact
- Unauthorized reading of sensitive data stored in the application's database (e.g., user details, orders, menus).
- Modification or deletion of data, including categories, menu items, or orders.
- Creation of new accounts or modification of existing user roles, depending on schema and query context.
- Bypassing application-level authorization checks enforced at the data layer.
- In extreme cases, execution of database-specific administrative commands that could impact database availability or integrity.
General mitigation guidance
Effective mitigation centers on treating all user-controlled data as untrusted and separating it from query logic:
- Use parameterized queries or prepared statements for all database operations involving external input, including the
nameparameter insave_category. - Apply strict server-side validation and normalization for category names (e.g., length constraints, allowed characters) to reduce the attack surface.
- Enforce least-privilege on the database account used by the application so that compromise of a single query has limited impact.
- Centralize database access patterns (e.g., via a data access layer or ORM) to make it easier to apply and audit safe query construction patterns.
- Avoid constructing ad-hoc SQL strings from request parameters; prefer stored procedures or ORM query builders where appropriate.
How teams detect issues like this
Organizations can detect and monitor for SQL injection risks using a combination of code-level and operational approaches:
- Static analysis: Configure SAST rules to flag dynamic SQL building in PHP files, especially concatenation patterns involving
$_POST,$_GET, or other request variables flowing into database APIs. - Code review: During manual reviews, look for SQL statements assembled with string concatenation in
Actions.phpand related controllers, and verify that parameter binding is consistently used. - Dynamic testing: Use automated scanners or manual penetration testing to send crafted input in the
nameparameter and observe for SQL error messages, anomalous responses, or unexpected data leakage. - Runtime monitoring: Enable database and application logging to detect unusual query patterns, especially those containing concatenated literals, comment markers, or always-true predicates.
- Policy enforcement: Integrate automated tools in CI/CD pipelines that block new code introducing raw SQL with unbound parameters.

