SQL injection is the oldest vulnerability on the OWASP Top 10, and it refuses to die. In assessments I still find it in login forms, search boxes, and — most often — in forgotten internal tools and admin panels that nobody has looked at in years. The fix has been known for two decades. The bug survives because applications keep building SQL queries by gluing strings together.
How a login bypass works
Consider a login that builds its query like this:
SELECT * FROM users WHERE username = '$user' AND password = '$pass'
If the username field receives ' OR '1'='1, the query becomes:
SELECT * FROM users WHERE username = '' OR '1'='1' AND password = ''
The OR '1'='1' makes the condition true for every row. Depending on how the application handles the result, the attacker may log in as the first user in the table — often an administrator. No password, no brute force, one request.
From there it escalates. UNION SELECT lets an attacker read other tables — users, emails, password hashes, payment records. In some database configurations, stacked queries or built-in functions can even write files or execute commands on the server. A single injection point can become a full compromise.
Why it still happens
- String concatenation. Queries built with
+or f-strings instead of parameters. This is the root cause in nearly every case. - Old code nobody owns. Legacy admin panels, plugins, and internal tools written years ago and never reviewed.
- False confidence in filters. Blocking quotes or keywords is trivially bypassed with encoding, comments, and alternative syntax.
- Over-permissive database accounts. The web application connects as a database user that can read — and sometimes write — every table, instead of only what it needs.
The fix, in order of importance
- Use prepared statements with bound parameters — everywhere. This is the fix. The query structure and the data travel separately, so user input can never change the query’s meaning.
- Apply least privilege to the database account. The application’s database user should only have the permissions it needs — usually
SELECT,INSERT,UPDATEon specific tables, nothing more. - Validate input, but never rely on it. Type checks and allowlists are good hygiene; they are not a substitute for parameterization.
- Treat a WAF as a seatbelt, not a fix. A web application firewall can slow an attacker down, but bypasses exist for every rule set. Fix the code.
If your application builds even one query from user input, assume it is injectable until a test proves otherwise. Prepared statements take minutes to implement and remove an entire class of vulnerability permanently. There is no excuse left for string-built SQL in 2026.