Summary
CakePHP through 5.4.3 contains a SQL injection vulnerability in window-expression handling when frame offsets and directions are not properly validated. If an application forwards attacker-controlled values into the SQL OVER clause, an attacker may alter generated SQL and execute statements with the database connection's privileges.
CakePHP through 5.4.3 contains a SQL injection vulnerability in window-expression handling when frame offsets and directions are not properly validated. If an application forwards attacker-controlled values into the SQL OVER clause, an attacker may alter generated SQL and execute statements with the database connection's privileges.
Affected context
The issue occurs in applications using CakePHP's WindowExpression::range() or frame() methods to construct window functions. Risk is present when user-controlled or otherwise untrusted frame offsets and directions reach these methods without strict allowlisting, type validation, or query-construction safeguards.
The issue occurs in applications using CakePHP's WindowExpression::range() or frame() methods to construct window functions. Risk is present when user-controlled or otherwise untrusted frame offsets and directions reach these methods without strict allowlisting, type validation, or query-construction safeguards.
Exploit preconditions
- Attack surface: Application endpoints or services that build SQL window expressions through CakePHP
- Required access: Ability to influence request or other input values forwarded to frame offsets or directions
- Trigger point: Generation and execution of a query containing an affected
OVERclause - Why exploitation is possible: Unvalidated expression components may be incorporated into SQL syntax rather than treated only as constrained values
- Attack surface: Application endpoints or services that build SQL window expressions through CakePHP
- Required access: Ability to influence request or other input values forwarded to frame offsets or directions
- Trigger point: Generation and execution of a query containing an affected
OVERclause - Why exploitation is possible: Unvalidated expression components may be incorporated into SQL syntax rather than treated only as constrained values
Why this happens
The underlying bug is insufficient validation of SQL expression components supplied to WindowExpression::range() and frame(). When application-controlled strings are accepted as frame offsets or directions and incorporated into generated SQL, attackers may influence query structure. This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command, commonly known as SQL injection.
The underlying bug is insufficient validation of SQL expression components supplied to WindowExpression::range() and frame(). When application-controlled strings are accepted as frame offsets or directions and incorporated into generated SQL, attackers may influence query structure. This behavior maps to CWE-89: Improper Neutralization of Special Elements used in an SQL Command, commonly known as SQL injection.
Potential impact
- An attacker may read unauthorized database records
- An attacker could modify or delete application data
- Database credentials or sensitive metadata may be exposed
- SQL statements could execute with the privileges of the configured database account
- Availability may be affected through destructive or resource-intensive queries
- An attacker may read unauthorized database records
- An attacker could modify or delete application data
- Database credentials or sensitive metadata may be exposed
- SQL statements could execute with the privileges of the configured database account
- Availability may be affected through destructive or resource-intensive queries
General mitigation guidance
Mitigation generally focuses on preventing untrusted input from controlling SQL syntax.
Common defensive patterns include:
- Use allowlisted, typed representations for frame directions and offsets
- Prefer secure-by-default query APIs that separate SQL structure from data values
- Reject unexpected, oversized, or malformed inputs before query construction
- Avoid forwarding request parameters directly into window-expression builders
- Apply least privilege to database accounts and limit access to unnecessary schemas and operations
- Add centralized validation and authorization controls around query-building boundaries
Mitigation generally focuses on preventing untrusted input from controlling SQL syntax.
Common defensive patterns include:
- Use allowlisted, typed representations for frame directions and offsets
- Prefer secure-by-default query APIs that separate SQL structure from data values
- Reject unexpected, oversized, or malformed inputs before query construction
- Avoid forwarding request parameters directly into window-expression builders
- Apply least privilege to database accounts and limit access to unnecessary schemas and operations
- Add centralized validation and authorization controls around query-building boundaries
How teams detect issues like this
Detection approaches commonly include:
- Static analysis rules for request data reaching
WindowExpression::range()orframe() - Code review checks for dynamic SQL fragments, unchecked strings, and missing allowlists
- Runtime monitoring for anomalous SQL syntax, unexpected window clauses, and unusual database errors
- Database activity monitoring to identify unauthorized reads, writes, or schema changes
- Policy enforcement requiring parameterization or constrained enums for SQL expression inputs
- Automated security review tools that flag tainted data flows into query construction
Detection approaches commonly include:
- Static analysis rules for request data reaching
WindowExpression::range()orframe() - Code review checks for dynamic SQL fragments, unchecked strings, and missing allowlists
- Runtime monitoring for anomalous SQL syntax, unexpected window clauses, and unusual database errors
- Database activity monitoring to identify unauthorized reads, writes, or schema changes
- Policy enforcement requiring parameterization or constrained enums for SQL expression inputs
- Automated security review tools that flag tainted data flows into query construction

