Summary
SQL::Abstract can mishandle values in certain nested statements, placing values from clauses such as where, having, and set into generated SQL instead of the bind list. If an application supplies untrusted input in those positions expecting it to be bound, the input may alter the SQL query; subselects in a WHERE condition are not affected.
Affected context
The issue affects applications using SQL::Abstract versions from 1.90_01 before 2.000001_04 when they build nested statements in identifier positions, including the select list, ORDER BY, GROUP BY, and RETURNING. With the ExtraClauses plugin, affected positions also include FROM (-as) and JOIN (to). Risk arises when untrusted input is supplied as a value in a nested statement and the application expects it to be safely bound; subselects in a WHERE condition are not affected.
Exploit preconditions
- Attack surface: Application code that constructs SQL using SQL::Abstract nested statements in an affected identifier position.
- Required access: Ability to influence input used as a
wherevalue within such a nested statement; direct database or server access is not necessarily required. - Trigger point: The application generates or executes a query containing the affected nested statement.
- Why exploitation is possible: Some nested-statement values are inserted into SQL text rather than the bind list, and may be unescaped when
quote_charis not set.
Why this happens
The query builder does not consistently preserve value-binding semantics when processing nested statements in identifier positions. Plain scalars in the nested statement are treated as identifiers, while values from clauses such as where, having, set, and -values can be emitted into SQL text instead of being represented as bound parameters. This is a SQL injection weakness (CWE-89) because input that an application expects to be treated as data can affect the structure or meaning of a query.
Potential impact
- An attacker may alter the meaning of queries that include attacker-influenced values.
- Depending on the query and database permissions, data could be disclosed, modified, or deleted.
- Database availability or integrity could be affected.
General mitigation guidance
Defensive approaches focus on preserving the distinction between SQL structure and data:
- Use query-building patterns that bind values consistently, including within nested statements.
- Treat identifiers and other SQL structure as trusted inputs; select them from explicit allowlists rather than accepting arbitrary user input.
- Validate nested query structures against an expected schema before building or executing SQL.
- Apply least-privilege permissions to database accounts so query execution is limited to necessary operations.
- Avoid relying on quoting alone as a substitute for parameter binding and input validation.
How teams detect issues like this
Review query-building code for nested statements in identifier positions and trace whether user-controlled values reach their where, having, set, or -values clauses. Static analysis and code review can flag SQL construction that places values into query text rather than a bind list, as well as identifiers derived directly from untrusted input. CI policies can require parameter binding for values and allowlist validation for SQL identifiers.

