Summary
A SQL Injection vulnerability in the save_customer action of Actions.php in SourceCodester Online Food Ordering System v1.0 allows unsanitized user input in the username parameter to be embedded directly into SQL queries.
Under typical deployments, this can let an attacker execute arbitrary SQL commands against the application's database, potentially leading to data theft, modification, or complete compromise of the backend data store.
Affected context
This vulnerability appears in the server-side logic handling customer registration or updates via the save_customer action in Actions.php.
It is relevant where:
- User-supplied data (such as
username) reaches SQL query construction, and - The application uses string concatenation or interpolation instead of parameterized queries, and
- Database accounts used by the application have broad privileges (e.g., read/write on customer tables).
The issue is most impactful in internet-facing deployments where attackers can freely submit crafted HTTP requests to the affected endpoint.
Exploit preconditions
- Attack surface: HTTP endpoint invoking
Actions.phpwithsave_customeraction - Required access: Ability to send HTTP requests to the application (typically unauthenticated or low-privileged access to the customer-related form/API)
- Trigger point: Submission of a crafted
usernameparameter that is incorporated into an SQL statement without proper escaping or binding - Why exploitation is possible: The backend constructs SQL queries by directly embedding the
usernamevalue without using prepared statements, robust input validation, or output encoding, enabling attacker-controlled tokens to modify query structure.
Why this happens
The core issue is dynamic SQL query construction that directly concatenates user-controlled input into the query string.
This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Instead of treating username as data bound via parameters, the application appears to interpolate it into SQL code, allowing metacharacters (such as quotes, operators, and comment markers) to alter the intended query logic.
The absence of a strict separation between query structure and user-supplied data thus permits injection of arbitrary SQL fragments.
Potential impact
- Unauthorized reading of sensitive data such as customer records, order details, or credentials stored in the database
- Modification or deletion of application data, including user accounts or order history
- Creation of new administrative or privileged accounts within the application data model
- Potential database server compromise if the DBMS supports dangerous features (e.g., file access, command execution) and the application's DB user has elevated privileges
- Application instability or denial of service by manipulating queries to lock tables or drop essential schema components
General mitigation guidance
Effective mitigation focuses on enforcing a strict separation between SQL code and user input.
Common defensive patterns include:
- Using parameterized queries or prepared statements for all database interactions, treating
usernameand similar fields strictly as bound parameters - Applying conservative server-side validation and normalization for input fields, constraining them to expected formats (e.g., length, allowed character sets)
- Centralizing data access logic through a database abstraction layer that defaults to safe query-building APIs
- Restricting database account permissions to the minimum required for application functionality, reducing the blast radius of a successful injection
- Implementing generic error handling to avoid exposing detailed SQL error messages that aid exploitation
How teams detect issues like this
Detection typically combines code-level analysis and runtime observation:
- Static analysis rules to flag dynamic SQL string concatenation involving HTTP parameters such as
usernameinActions.php - Secure code review checklists focusing on database access layers, verifying use of prepared statements everywhere
- Pattern-based scanning of the codebase for string interpolation or concatenation near SQL keywords and query execution functions
- Web application firewall (WAF) rules or API gateways configured to detect and log suspicious SQL metacharacters or patterns in parameters targeting the
save_customeraction - Automated security testing (e.g., SAST/DAST) integrated into CI/CD to surface injection sinks and vulnerable endpoints early

