SQL Injection in 2026: Why an Old Bug Still Breaks Systems
SQL injection is more than 25 years old, yet it powered one of the largest data theft campaigns of the decade. Here is how it works, where it hides today, and how to stop it for good.

In mid-2023, a criminal group exploited a previously unknown SQL injection flaw in MOVEit Transfer, a file transfer product used by thousands of organizations. They automated the attack across every internet-facing server they could find. Government agencies, universities, banks, and hospitals were hit, and data on tens of millions of people was exposed.
The vulnerability class behind it is older than many of the developers who maintain web applications today. So why is SQL injection still here, and what actually stops it?
How SQL injection works
SQL injection happens when untrusted input is concatenated into the text of a query, so that the input can change the query’s structure instead of just supplying a value.
# VULNERABLE: user input becomes part of the SQL text
query = "SELECT * FROM users WHERE email = '" + email + "'"
If someone submits ' OR '1'='1 as the email, the query’s logic changes. The database is not broken. It is doing exactly what it was told. The problem is that the attacker got to write part of the instructions.
That is why a single quote is the classic first probe: if a lone ' produces a database error or a different response, the input is probably being glued into SQL text.

The many shapes of SQLi
Not every injection prints data on the page. The main variants are:
- In-band: results or errors come back in the response, for example through
UNIONqueries. - Blind (boolean): the page changes subtly depending on whether an injected condition is true or false.
- Blind (time-based): the response never changes, but an injected delay reveals the answer one bit at a time.
- Out-of-band: the database is made to contact an external server, carrying data with it.
- Second-order: input is stored safely, then later concatenated into a different query somewhere else.
Where it hides in modern apps
Login forms are well tested. The injection that survives code review usually lives somewhere less obvious:
- Sort and column parameters.
ORDER BYclauses cannot use bound parameters for identifiers, so developers often concatenate them. - HTTP headers such as
User-AgentorX-Forwarded-Forwritten to analytics tables. - Stored data that is later reused in a report or admin query.
- Search, filter, and export features with hand-built query fragments.
The impact ranges from bypassing authentication to dumping entire databases, and in some configurations to running commands on the server.
The fix: separate code from data
The real fix has not changed in 20 years, which is good news. Use parameterized queries everywhere.
# FIXED: the query structure is fixed; email is only ever a value
cursor.execute("SELECT * FROM users WHERE email = %s", (email,))
With a prepared statement, the database receives the query structure and the values separately. No input, however strange, can turn into SQL syntax.
For the cases where parameters cannot help, such as column names in ORDER BY, use an allowlist:
SORTABLE = {"name": "name", "created": "created_at", "price": "price"}
column = SORTABLE.get(request.args.get("sort"), "created_at")
query = f"SELECT * FROM products ORDER BY {column}"
Then layer on defense in depth:
- Least-privilege database accounts. The web app should not connect as an administrator, and should only reach the tables it needs.
- Input validation as a second layer, not the main defense.
- Generic error messages so database errors do not leak schema details.
- Static analysis in your pipeline to catch string-built queries before they ship.
ORMs help a lot, but most have raw-query escape hatches. Those are exactly where reviewers should look.
Same pattern, different databases
The injection pattern is not unique to SQL. NoSQL databases have their own version: a MongoDB login that passes a JSON body straight into a query can be bypassed with an operator like {"$ne": null}. LDAP, XPath, search engines, and even vector database filters can all be injected the same way. The fix is always the same idea: build queries with structured APIs, validate types, and never let raw input become query syntax.
The new frontier: text-to-SQL
Many products now let users “ask the database a question” in plain English and have an LLM write the SQL. That is an injection surface by design. The model is writing query text from untrusted input, and a cleverly worded prompt can steer it.
You cannot reliably prompt your way out of this. The controls that work live in the database itself:
- Run generated queries as a read-only role with access only to approved views.
- Use row-level security so the role can only ever see the current customer’s rows, no matter what SQL the model writes.
- Enforce timeouts and row limits.
If the database will refuse a query, it does not matter how persuasive the prompt was.
Key takeaways
- SQL injection still causes mass breaches, as MOVEit showed.
- It appears in blind, out-of-band, and second-order forms, and hides in sort parameters, headers, and stored data.
- Parameterized queries everywhere, plus allowlists for identifiers, is the fix.
- The same pattern affects NoSQL, LDAP, search, and vector databases.
- Text-to-SQL features need database-enforced limits such as row-level security, not prompt rules.
Practice only on your own lab or on intentionally vulnerable training apps, never on systems you are not authorized to test.
Go deeper with the book
This article is adapted from Web Security in the Age of AI: Attacks, Defenses, Tools, and Bug Hunting for Modern Web Applications and LLM Systems by Rupak (see Chapter 5, “SQL Injection and Data Store Attacks”).
The book pairs every attack with its fix across 27 chapters, from core vulnerabilities and professional tools to bug bounty hunting, attacking and defending LLM applications, and lessons from real breaches. It includes hands-on labs, review questions, a full testing checklist, a security headers reference, and an LLM red teaming playbook.
Related reading
- 7 Real-World Breaches and the Security Lessons They Teach
- AI Code Review and Autofix: Can AI Fix Your Security Bugs?







