Parameterized Queries
Replace dynamically constructed SQL statements with prepared statements and bound parameters.
Ensure that user input is treated as data rather than executable SQL syntax.
Modern web applications and APIs frequently process user-supplied information and use backend databases to authenticate users, retrieve records, and perform application operations. If this input is directly incorporated into dynamically constructed SQL statements, an attacker may manipulate the application's database query logic.
This vulnerability is known as SQL Injection (SQLi). OWASP identifies SQL injection as an injection attack in which attacker-controlled input can alter the intended SQL operation executed by the application.
In this use case, OWASP WebGoat is deployed as the controlled web application environment instead of the OWASP Juice Shop used in the previous use case. WebGoat is specifically designed as a deliberately insecure application for safely practicing common application vulnerabilities and evaluating application-security tools.
The application is deployed in an isolated environment using Docker on an Ubuntu virtual machine. Kali Linux is used as the security-testing environment.
A controlled SQL injection assessment is performed against the WebGoat authentication functionality. Burp Suite Community Edition is used to intercept and modify HTTP requests, while OWASP ZAP is used for additional application-security assessment.
The assessment determines whether attacker-controlled input can influence backend SQL processing.
The defensive implementation replaces unsafe dynamic query construction with parameterized queries / prepared statements, combined with server-side input validation, least-privilege database access, and controlled error handling.
After implementing the security controls, the same controlled SQL injection assessment is repeated to verify that malicious database-query manipulation is rejected while legitimate authentication functionality continues to operate.
OWASP WebGoat is used as the controlled application environment for testing SQL injection against authentication-related functionality. WebGoat provides deliberately vulnerable application components specifically intended for security testing and training.
The security problem occurs when application code constructs SQL queries by directly combining SQL statements with untrusted user input. If the backend does not separate SQL instructions from user-supplied data, specially crafted input may alter the intended database operation.
The security problem occurs when application code constructs SQL queries by directly combining SQL statements with untrusted user input.
The security problem is therefore:
The proposed solution replaces unsafe dynamic SQL construction with parameterized queries / prepared statements, combined with server-side input validation, least-privilege database access, controlled database error handling, and security logging.
SQL injection occurs when untrusted application input is incorporated into a dynamically constructed SQL query in a way that allows the input to influence the query's intended logic.
In this controlled assessment, the attacker interacts with the WebGoat authentication functionality and analyzes how supplied input affects the backend authentication query. The objective is to determine whether application input can alter the expected authentication logic.
The primary security concept is to separate SQL instructions from user-controlled data.
Instead of constructing SQL statements by concatenating untrusted input into the query, the application uses parameterized queries / prepared statements. The database receives the SQL structure separately from the user-provided values.
The secure processing flow is:
Replace dynamically constructed SQL statements with prepared statements and bound parameters.
Ensure that user input is treated as data rather than executable SQL syntax.
Validate user input on the application server before database processing. Validation considers expected data type, maximum length, required fields, and accepted input format.
Prevent unexpected input from reaching sensitive application operations.
The application separates SQL query structure from user-provided values.
Prevent attacker-controlled input from modifying the intended SQL structure.
The application uses a dedicated database account with only the permissions required for normal application functionality.
Limit the impact of a successful database-layer attack.
Database errors are handled internally rather than exposing detailed database information to the client.
Prevent database schema, query structure, table information, or implementation details from being unnecessarily disclosed.
Authentication failures and relevant database-related security events are recorded. Sensitive credentials and complete SQL statements containing user data should not be unnecessarily written to logs.
Support security investigation and identify repeated injection attempts.
Burp Suite Community Edition is used from Kali Linux to intercept and analyze WebGoat HTTP requests.
OWASP ZAP is used for additional application-security assessment.
WebGoat provides the deliberately vulnerable application environment.
Ubuntu hosts the WebGoat environment.
Docker is used to deploy WebGoat in an isolated environment. OWASP provides Docker-based deployment as one of the standard ways to run WebGoat.
Kali Linux is used as the controlled security-testing environment.