Summary
Ash contains an unsafe keyset-pagination cursor handling issue that lets an unauthenticated attacker inject an expression through a forged page cursor. Depending on the configured data layer, this may result in SQL injection or execution of attacker-controlled function calls within the application process.
Affected context
The vulnerability occurs in Ash read actions that use keyset pagination and accept client-supplied page[:after] or page[:before] cursors. It is relevant when the cursor is decoded and incorporated into filters without the same expression visibility checks applied to expressions created through the normal Ash API. AshPostgres may inline the resulting expression into SQL, while ETS and Simple data layers may evaluate it in-process.
Exploit preconditions
- Attack surface: Publicly reachable Ash read actions using keyset pagination
- Required access: No authentication may be required when the affected read action is exposed to unauthenticated clients
- Trigger point: Decoding and processing a forged
page[:after]orpage[:before]cursor - Why exploitation is possible: The cursor decoder permits certain already-interned Ash struct values, allowing an expression to bypass normal public/private expression checks and enter keyset filter processing
- Data-layer dependency: The resulting impact depends on whether the application uses AshPostgres, ETS, Simple, or another affected data layer
Why this happens
The issue combines unsafe deserialization with expression injection. Although non_executable_binary_to_term/2 is invoked with safe-mode restrictions, those restrictions do not prevent construction of certain structs from atoms already present in the running application. A forged cursor can therefore carry an Ash.Query.Call expression that bypasses the normal Ash.Expr validation path. The expression is then treated as a filter value and evaluated or incorporated into a query, mapping to CWE-502: Deserialization of Untrusted Data and CWE-89: Improper Neutralization of Special Elements used in an SQL Command.
Potential impact
- An attacker may alter query behavior or access data outside the intended result set
- An attacker could inject SQL expressions when the AshPostgres data layer is used
- An attacker may cause arbitrary function calls within the application process on affected in-process data layers
- Application confidentiality, integrity, or availability could be affected
- Database or application credentials may be exposed if the compromised process has access to them
General mitigation guidance
Mitigation generally focuses on treating pagination cursors as strictly untrusted data and preventing serialized values from becoming executable query expressions.
Defensive patterns include:
- Use a narrowly defined, schema-validated cursor format containing only expected scalar pagination values
- Reject structs, function references, expression nodes, and unexpected terms before filter construction
- Ensure cursor-derived values cannot bypass the same authorization and expression-visibility checks used by normal query APIs
- Prefer parameterized database queries and typed query builders that keep values separate from SQL syntax
- Limit database and application-process privileges so a compromised query path has reduced reach
- Avoid exposing keyset-paginated actions anonymously unless the returned data and query capabilities are intentionally public
How teams detect issues like this
Detection can combine application review, static analysis, and runtime policy controls:
- Search for deserialization of client-controlled pagination tokens or cursors
- Review code paths where decoded terms are converted into query expressions, filters, or function calls
- Flag use of broad term decoding, dynamic struct reconstruction, or cursor formats that preserve internal framework objects
- Add tests using malformed, unexpected, and structurally valid-but-unauthorized cursor values
- Monitor database queries for unexpected predicates, functions, or changes in query shape associated with pagination requests
- Apply policy checks requiring explicit cursor schemas and forbidding executable or framework-internal terms in external request data
Automated security review tools may help identify unsafe deserialization and query-construction patterns, but framework-specific validation remains important.

