Summary
SQL::Abstract can skip its documented injection_guard check for function names supplied through the explicit -func form. If an application relies on that guard while passing an untrusted function name through this form, the name may be included in generated SQL without the expected check, enabling SQL injection.
Affected context
The issue affects SQL::Abstract versions from 1.90_01 up to, but not including, 2.000001_04. It arises when an application uses the explicit { -func => [...] } form to generate SQL and expects injection_guard to validate the supplied function name. The documented guard behavior applies to function names, but this form does not pass the name through the check.
Exploit preconditions
- Attack surface: Application code that builds SQL using SQL::Abstract's
-funcform - Required access: Ability to influence the function name supplied to that code; authentication requirements depend on the application
- Trigger point: SQL generation using the explicit
{ -func => [...] }form - Why exploitation is possible: The function name is inserted into generated SQL without the expected
injection_guardcheck
Why this happens
This is an inconsistent input-validation path. The -name shorthand applies injection_guard, while the explicit -func form does not apply it to the function name. When an application treats this guard as the security boundary for untrusted input, unchecked SQL construction can result. This maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection').
Potential impact
- An attacker may alter the structure or behavior of generated SQL.
- Queries could return, modify, or delete data beyond the application's intended scope.
- Depending on database permissions and application behavior, unauthorized database operations could occur.
General mitigation guidance
Defensive patterns focus on ensuring that SQL structure is not derived from untrusted input. Use fixed or allowlisted function names, and apply consistent validation to every API form that accepts SQL identifiers or expressions. Prefer parameterized query mechanisms for values, while recognizing that parameters generally do not replace validation for SQL structure such as function names. Limit database-account privileges so a compromised query path has less authority.
How teams detect issues like this
- Review call sites that construct SQL with
-func, especially where function names can be influenced by requests, configuration, or other external input. - Use static analysis to identify untrusted data flowing into SQL-construction APIs and checks that apply to one API form but not another.
- Add code-review checks and policy enforcement for dynamic SQL identifiers, requiring fixed values or explicit allowlists.
- Test query-generation paths to confirm untrusted function names are rejected or constrained before SQL is constructed.

