CVE-2026-124283: Code execution and SQL injection via struct-wrapped values in a forged keyset pagination cursor in Ash

Published Nov 24, 2026
·
Updated

Summary

Deserialization of Untrusted Data vulnerability in ash-project ash allows an unauthenticated attacker to execute arbitrary code or inject SQL through a forged keyset pagination cursor.

Ash.Page.Keyset.filter/4 in lib/ash/page/keyset.ex decodes the client-supplied page[:after] or page[:before] cursor from Erlang external term format and rejects decoded expressions with Ash.Expr.expr?/1. That check does not examine the fields of a struct. The cast of each value against the type of its sort field accepts structs for the :cistring, :map, :struct and :term types. A struct in the cursor value for such a sort field therefore reaches the data layer. With AshPostgres, the read passes such a struct to inspect/1, which runs the Inspect implementation of the struct module that the attacker selected. A chain of struct modules from ecto and dbconnection then calls a function that the cursor names, which permits OS command execution. An %Ash.Query.Function.Fragment{} inside an %Ash.CiString{} value is written into the SQL query as raw text.

This issue affects ash: from 3.31.3 before 3.38.0.

Details

1. Cursor decoding

A keyset cursor is the Base64 form of :erlang.termtobinary/1 over the list of sort values of one record. decodevalues/3 in lib/ash/page/keyset.ex decodes a client-supplied cursor with Ash.Helpers.nonexecutablebinarytoterm/2 and [:safe]. This refuses functions and new atoms. It accepts a map with a struct key, so the client selects the struct module of each decoded value. When keysetsigningsecret is unset, Ash does not authenticate the cursor.

2. Expression check

checknoexpression/1 calls Ash.Expr.expr?/1 on the decoded term. Ash.Expr.expr?/1 in lib/ash/expr/expr.ex returns true for expression structs and descends into lists, tuples and maps that are not structs. For a struct that is not an expression it returns false and does not examine the fields. Such a struct passes the check, and so does any value inside it.

3. Type cast

castvalues/3 casts each decoded value with Ash.Type.castinput/3 against the type of its sort field. Strict types such as :integer reject a struct. Four built-in types accept one. Ash.Type.CiString.castinput/2 returns any %Ash.CiString{} unchanged, and its string field can hold any term. Ash.Type.Map.castinput/2 and Ash.Type.Struct.castinput/2 accept any map, which includes any struct. Ash.Type.Term.castinput/2 accepts any term.

4. Query construction

dofilters/4 puts the value into the keyset filter as the right side of a comparison with the sort field. In ashsql, the clause of AshSql.Expr for an %Ash.CiString{} value compiles the string field as a nested expression.

5. Code execution

A value that holds a struct inside a map, or inside a tuple in an %Ash.CiString{}, becomes a query parameter. Parameter encoding fails, and the read passes the value to inspect/1 before Ash.read/2 returns. inspect/1 runs the Inspect implementation of each struct module in the value. An %Ecto.Query.DynamicExpr{} whose binding field holds a %DBConnection.Stream{} makes Inspect call Enum.map/2 on the stream. The Enumerable implementation of DBConnection.Stream calls DBConnection.reduce/3, which applies the :log module, function and arguments from the opts field of the struct. The cursor supplies that field. A function from the OTP standard library that applies a further module, function and argument list makes the call fully attacker-controlled, which includes OS command execution.

6. SQL injection

An %Ash.CiString{} whose string field holds an %Ash.Query.Function.Fragment{} with raw: arguments becomes literal SQL text in the WHERE clause. This works for each of the four types, because each accepts the %Ash.CiString{} struct.

Proof of concept

1. Define an AshPostgres resource with a :cistring attribute and a read action with pagination keyset?: true. Leave keysetsigningsecret unset. 2. Read one page sorted on the :cistring attribute and decode the keyset of a record with Base.decode64!/1 and :erlang.binarytoterm/1. The term is a list with the %Ash.CiString{} sort value and the primary key. 3. Build an %Ecto.Query.DynamicExpr{} whose binding field is a %DBConnection.Stream{}. Set the query field of the stream to an atom, and put a :log entry with a module, function and argument list into its opts field. 4. Replace the first element of the list with an %Ash.CiString{} whose string field is a one-element tuple that holds the struct from step 3. 5. Encode the list with :erlang.termtobinary/1 and Base.encode64/1, and pass the result as page: [after: cursor] to the same read. 6. The read returns an invalid filter value error. Before it returns, the application calls the function from the :log entry.

For the SQL injection, use an %Ash.Query.Function.Fragment{} with raw: arguments as the string field in step 4. The read succeeds, and the query contains the raw text in the WHERE clause.

Impact

An unauthenticated client that can supply a keyset cursor selects the struct modules of the decoded values. Through protocol implementations in ecto and dbconnection, the client makes the application call a function of its choice, and can execute OS commands with the privileges of the BEAM OS user.

An unauthenticated client that can supply a keyset cursor adds SQL text to the query of the read action. The text runs with the database privileges of the application.

Workarounds

On ash 3.37.0 or later, set config :ash, keysetsigningsecret to a long random string. Ash then rejects each cursor that it did not sign, before it decodes the cursor. Cursors issued before the change become invalid.

Configurations

A read action must declare keyset? true in its pagination block, and the application must pass a client-supplied value as the :after or :before page option. The sort must include a field of type :cistring, :map, :struct or :term. config :ash, :keysetsigningsecret must be unset, which is the default. Both results were demonstrated with the AshPostgres data layer. The code execution was demonstrated with ecto 3.14.3 and dbconnection 2.10.2 loaded.

Other sources

Deserialization of Untrusted Data vulnerability in ash-project ash allows an unauthenticated attacker to execute arbitrary code or inject SQL through a forged keyset pagination cursor.

Ash.Page.Keyset.filter/4 in lib/ash/page/keyset.ex decodes the client-supplied page[:after] or page[:before] cursor from Erlang external term format and rejects decoded expressions with Ash.Expr.expr?/1. That check does not examine the fields of a struct. The cast of each value against the type of its sort field accepts structs for the :cistring, :map, :struct and :term types. A struct in the cursor value for such a sort field therefore reaches the data layer. With AshPostgres, the read passes such a struct to inspect/1, which runs the Inspect implementation of the struct module that the attacker selected. A chain of struct modules from ecto and dbconnection then calls a function that the cursor names, which permits OS command execution. An %Ash.Query.Function.Fragment{} inside an %Ash.CiString{} value is written into the SQL query as raw text.

This issue affects ash: from 3.31.3 before 3.38.0.

— MITRE

Affected Software

2 affected componentsFixes available
hex/ash>=3.31.3<3.38.0
erlang/ash>=3.31.3<3.38.0
3.38.0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade erlang/ash to a version that resolves this vulnerability.

    Fixed in 3.38.0
  2. Upgrade

    Upgrade to a fixed release to a version that resolves this vulnerability.

    Fixed in 3.38.0
  3. Configuration

    On Ash 3.37.0 or later, set config :ash, keyset_signing_secret to a long random string.

    Ash keyset_signing_secret = long random string

Event History

Nov 24, 2026
CVE Published
via MITRE·02:34 AM
Data Sourced
via MITRE·02:34 AM
DescriptionWeakness
Data Sourced
via OSV·02:34 AM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

Which deployments are exposed to this issue?

Deployments using ash versions from 3.31.3 up to, but not including, 3.38.0 are affected. Exploitation is relevant where an attacker can supply keyset pagination after or before cursor values to a read operation.

2

Does an attacker need an account or other prior access?

No. The issue is described as exploitable by an unauthenticated attacker who can provide a forged keyset pagination cursor.

3

What application conditions make exploitation possible?

The vulnerable cursor must contain a value for a sort field whose type accepts structs: :ci_string, :map, :struct, or :term. SQL injection through the described path involves AshPostgres and an Ash.Query.Function.Fragment wrapped in an Ash.CiString value.

4

What version should be used to remediate the issue?

Upgrade ash to version 3.38.0 or later. Versions before 3.31.3 are not identified as affected by the provided advisory data.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203