An SQL Injection (SQLi) vulnerability was discovered in the login functionality of the OWASP Juice Shop application. This vulnerability allows an unauthenticated attacker to bypass the authentication mechanism and log in as the Administrator without knowing the valid credentials, effectively taking over the administrative account.
To reproduce this vulnerability and confirm the exploit, please follow these steps:
/#/login).A common payload for bypassing the login is:
' OR '1'='1' --
The injected clause '1'='1' always evaluates to true, causing the authentication query to return the first user record (the administrator).
This vulnerability is classified as Critical due to the following reasons:
The vulnerability exists because the application concatenates user input directly into the SQL query string without proper sanitization or parameterization.
Backend Logic Simulation: Assuming the vulnerable backend code looks something like this:
query = "SELECT * FROM users WHERE email = '" + email + "' AND password = '" + password + "'";
When the payload ' OR '1'='1' -- is injected, the query becomes:
SELECT * FROM Users WHERE email = '' OR '1'='1' --' AND password = 'random';
Here, the condition '1'='1' always evaluates to true, and the -- comments out the password check. This forces the database to return the first user (Admin).
To mitigate this vulnerability, the following coding practices should be implemented:
? or :param) to ensure the database treats user input as data, not executable code.
db.get("SELECT * FROM Users WHERE email = ? AND password = ?", [email, password], (err, row) => { ... });