PT-2026-168042

CVE-2026-128360

·

Published

2026-12-04

·

Updated

2026-12-04

Description by

CVSS 4.0
2.1
Low
MetricsAV:L/AC:L/AT:P/PR:N/UI:N/VC:L/VI:N/VA:N/SC:N/SI:N/SA:N

Summary

Incorrect Authorization vulnerability in ash sql allows a caller in a multitenant application to receive aggregate values computed from another tenant's rows.
An aggregate can be given a tenant with the tenant option of Ash.Query.aggregate/5. AshSql.Aggregate.Lateral.add aggregates/6 read only part of such an aggregate in that tenant. A field that is an aggregate or calculation, and what the aggregate's filter and sort refer to, were read in the tenant of the enclosing query, and with no tenant on that query they were read across every tenant. Aggregates over the same relationship were grouped into one lateral join without regard to their tenants, and with strategy(:context) multitenancy the aggregate was read in the schema of the enclosing query.
This issue affects ash sql: from 0.1.0 before 0.9.1.

Details

1. Grouping. AshSql.Aggregate.Lateral.add aggregates/6 groups the aggregates of a query by relationship path, resource, join filters, read action and multitenancy bypass, and builds one lateral subquery per group from the query of the first aggregate. The tenant is not part of that key, so aggregates that were given different tenants share the subquery of the first one.
2. Nested reads. The subquery is built from the bindings of the enclosing query. What is resolved inside it (a field that is an aggregate or a calculation, and the aggregates and calculations in the aggregate's filter and sort) takes context[:private][:tenant] from those bindings, which is the tenant of the enclosing read and not the tenant of the aggregate. AshSql.Join.handle attribute multitenancy/3 adds no tenant filter when that tenant is nil, so with no tenant on the read these nested reads cover every tenant. Ash itself refuses the same aggregate when no tenant is given anywhere.
3. Joined first aggregates. optimizable first aggregate?/3 lets a first aggregate over a to-one relationship be added as a join on the enclosing query, which reads the relationship in that query's tenant.
4. Schema multitenancy. With strategy(:context) the observed effect covers the aggregate as a whole: its subquery is read in the schema of the enclosing query's tenant, or in the repo's default schema when that query has no tenant.

Proof of concept

  1. With AshPostgres, define Group (has many :orgs) and Org (has many :notes, aggregate count :notes count, :notes) without multitenancy, and Note with multitenancy using strategy :attribute and attribute :tenant id.
  2. Create one group with two orgs. Give the first org one note in tenant "a" and two in tenant "b", and the second org two notes in tenant "a".
  3. Without a tenant on the read, run Group |> Ash.Query.aggregate(:n, :sum, :orgs, field: :notes count, tenant: "a") |> Ash.read!(). The value for tenant "a" is 3; an affected version returns 5, the count over both tenants.
  4. Run the same query with Ash.read!(tenant: "b"). An affected version returns 2, the value of tenant "b".
  5. Again without a tenant on the read, add the aggregate twice, as :a with tenant: "a" and as :b with tenant: "b". The values are 3 and 2; an affected version returns 5 for both.
  6. For comparison, the aggregate without its tenant option in a read without a tenant is refused by Ash with a tenant-required error.

Impact

A user of the application receives counts, sums, lists or first values computed from rows of a tenant other than the one the application asked for, and from the rows of every tenant when the enclosing read has no tenant. No input from the user is needed beyond reaching the read that builds the aggregate.

Workarounds

Set the tenant on the read (Ash.Query.set tenant/2 or the tenant option of the read) instead of on the aggregate, so that both are read in the same tenant. Aggregates that have to be read in different tenants can be run as separate reads, one per tenant.

Configurations

An application must use a data layer built on ash sql (verified with AshPostgres), have a resource with multitenancy, and build an aggregate with the tenant option (Ash.Query.aggregate/5 or Ash.Query.Aggregate.new/4) inside a read that has no tenant or a different tenant. With the :attribute strategy the aggregate must also have a field, filter or sort that refers to an aggregate or calculation over the multitenant resource, or share its relationship with an aggregate that was given a different tenant. With the :context strategy any such aggregate over the multitenant resource is affected. Aggregates that take their tenant from the read are not affected.
Exploitability
Exploit
Fix
Impacts
Vendors
Affected products
Related identifiers
GHSA-3496-VM79-25Q9
Found an issue in the description? Have something to add? Feel free to write us 👾