A decade after Eloquent, Doctrine and Prisma became the default, SQL injection is still in the OWASP top risks and still gets exploited in production. It is not that teams don't understand the concept, it is that ORMs protect the paved road very well (standard CRUD through a query builder) and leave gaps exactly where developers step off it: advanced search, dynamic sorting, reporting tools, stored procedures, internal admin panels built in a hurry. This post walks through where those gaps actually live today, how to find them, and how to close them properly instead of papering over them.
The mechanism everyone forgets
SQL injection happens when untrusted input gets concatenated into a query string that the database engine then parses as code, instead of being passed as a bound parameter. Modern ORMs solve this by default for standard operations: User::where('email', $email) always produces a prepared statement with a placeholder. The risk hasn't gone away, it has simply moved to the places where a developer has to step outside that abstraction.
Why placeholders don't cover everything
A bound parameter substitutes a value in a query (WHERE email = ?), never an identifier - a column name, a table name, a sort direction (ASC/DESC). The SQL driver simply has no placeholder syntax for that. The moment a feature needs dynamic sorting, a "filter by any field" search, or a variable table name (schema-per-tenant multi-tenancy), explicit application-level validation becomes mandatory. This is precisely the blind spot most developers discover too late, because the ORM stops protecting them there and gives no warning either.
Where it still hides in 2026
In practice, injection survives in a handful of recurring, very specific spots:
whereRaw,DB::raw,selectRawcalls in Laravel, used for aggregations or complex conditions.- Doctrine DQL built through string concatenation instead of
setParameter. - Dynamic sorting or filtering by column name, taken straight from an HTTP query parameter.
- Stored procedures that build SQL dynamically internally (
EXEC(@sql)on SQL Server,EXECUTEon PostgreSQL), which stay vulnerable even when the application calls the procedure with bound parameters. - Reporting or admin tools built quickly, often with more direct database access and less rigor than the core business code.
- Generic "filter by any field" APIs that turn a client-supplied field name into an SQL column through reflection.
// Vulnerable: direct string concatenation in a raw query
$email = $request->input('email');
$users = DB::select("SELECT * FROM users WHERE email = '" . $email . "'");
// Safe: parameter binding, the driver escapes and types the value
$users = DB::select('SELECT * FROM users WHERE email = ?', [$email]);
Dynamic sorting is the most deceptive example, because the code already "looks like" it is using the query builder safely:
// Vulnerable: the column name comes straight from the client
$sort = $request->query('sort', 'created_at');
$users = DB::table('users')->orderBy($sort)->get();
// Safe: explicit allow-list of permitted columns
$allowedColumns = ['name', 'email', 'created_at'];
$sort = in_array($request->query('sort'), $allowedColumns, true)
? $request->query('sort')
: 'created_at';
$users = DB::table('users')->orderBy($sort)->get();
On the Doctrine side, the classic trap is building a WHERE clause as a string instead of going through the QueryBuilder:
// Vulnerable
$dql = "SELECT u FROM App\Entity\User u WHERE u.email = '" . $email . "'";
$query = $em->createQuery($dql);
// Safe
$qb = $em->createQueryBuilder();
$qb->select('u')
->from(User::class, 'u')
->andWhere('u.email = :email')
->setParameter('email', $email);
Diagnosing before fixing
The first step isn't patching at random, it's mapping the real attack surface. Three complementary levers:
# Search the codebase for risky patterns
grep -rn "whereRaw\|DB::raw\|selectRaw\|->raw(" src/
grep -rn "createQuery(\"" src/
# Targeted static analysis with injection-specific rules
semgrep --config p/sql-injection src/
On top of that, reviewing query logs (temporarily enabled in a staging environment) helps spot suspicious patterns: unescaped quotes, unexpected unions, SQL comment markers (--, /* */) inside values that should never contain them. Running sqlmap against a staging environment seeded with disposable data remains the most direct way to confirm that an entry point is actually exploitable, but it should never be pointed at production.
The fix, and its tradeoffs
Parameter binding everywhere a value flows into a query resolves the vast majority of cases. For identifiers (columns, tables, sort direction), the only reliable answer is an explicit allow-list - a known, enumerated set of what's permitted, never an attempt to escape the identifier itself. Escaping an identifier is fragile and engine-dependent; validating it against a known list is not.
A second lever, often overlooked because it's invisible in application code, is the principle of least privilege at the database level: the account used by the application should have no DDL rights (CREATE, DROP, ALTER) and no access to other tenants' schemas in a multi-tenant setup. If an injection still slips through, it's then contained by the database's own permissions rather than relying solely on the application layer. The tradeoff is operational: finer-grained service accounts to manage, migrations that need a separate, more privileged role, and extra discipline around ad hoc admin scripts.
The performance side nobody mentions
Parameter binding isn't free of friction either, and pretending otherwise causes its own production incidents. PostgreSQL caches a query execution plan per prepared statement on a given physical connection, which is a net win for repeated queries, but it clashes with connection poolers running in transaction pooling mode (PgBouncer being the common case): a prepared statement created on one physical connection can't be reused once the pooler hands the client a different connection for the next transaction. Teams that enable transaction-level pooling while using an ORM or driver that silently prepares every parameterized query have hit "prepared statement already exists" or "prepared statement does not exist" errors that look completely unrelated to the original security fix. The right fix lives at the infrastructure layer - switching to session pooling, or disabling statement-level caching on the driver's side - not in reverting to string concatenation to make the error go away, which would quietly reopen the original vulnerability to paper over an unrelated infrastructure mismatch.
Keeping the fix from regressing
A fix applied once tends to erode over the following months, as new endpoints get added by developers who never saw the original incident. Two cheap safeguards keep it from silently regressing:
# .github/workflows/security.yml
# Fail CI on any new raw-query pattern introduced in a diff
- name: SQL injection static check
run: semgrep --config p/sql-injection --error src/
Pairing that CI gate with a short, written rule in the team's code review checklist ("any whereRaw, DB::raw or string-built DQL requires a second reviewer and an explicit allow-list for identifiers") turns a one-time fix into a durable team habit, which matters more than the fix itself once the codebase has more than a handful of contributors.
When the easy fix isn't enough
Parameter binding protects the immediate entry point, but not necessarily later uses of that same data. That's the principle behind second-order injection: a value stored safely through a parameterized query (a saved search term, for instance) can later be fed, unprotected, into a reporting generator or an ad hoc SQL export that concatenates directly. The fix has to cover every place the data comes back out, not just the point where it went in.
Schema-per-tenant multi-tenant architectures raise a structurally different problem: the schema name is often built dynamically from a tenant identifier, and no placeholder can protect a schema name. The only solid option is to validate that identifier against the list of actually provisioned tenants in the database, before any query gets built, never after.
Finally, a web application firewall (WAF) can reduce exposure by blocking known attack patterns, but that's defense in depth, not a fix. A poorly tuned WAF lets encoding variants through, and its presence never excuses leaving the underlying vulnerable query unpatched.
Takeaway
SQL injection in 2026 isn't a legacy-framework problem, it's a surface problem: every time code steps off the ORM's paved road (raw query, dynamic identifier, stored procedure, internal tool), it needs the same rigor as the core business logic. Allow-lists for identifiers, parameter binding for values, least privilege at the database level: those three habits cover the vast majority of cases actually exploited in the wild.
