Skip to content

memory.owner_report for a wildcard or delegated token covers only what the token can read - #232

Merged
zlareb1 merged 11 commits into
mainfrom
fix/owner-report-wildcard-restricted
Nov 4, 2026
Merged

zlareb1 merged 11 commits into
mainfrom
fix/owner-report-wildcard-restricted

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Critical Bug Fix (data loss, cross-tenant read, auth bypass)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

memory.owner_report called with a flat * token no longer counts rows, readers or usage from restricted namespaces or collections that the token cannot read. A delegated * token's report is now limited to the namespaces where its creator holds a live grant. Before, it covered every namespace of the org.

Why

Failing case: a flat VIEWER token with namespaces=["*"] calls memory.owner_report with no namespace. The handler set the scope to ["*"], so all three statements ran with no namespace predicate. The answer then included the owner's row counts, the readers (actor, agent) and the usage totals from a restricted namespace. That token cannot read there, because authz.names_namespace never counts a wildcard toward a restricted namespace. The same gap also covered collections the token cannot read.

Pattern: the scoped-token branch filters through the gate (rollup_member_namespaces). The wildcard branch skipped that step. An org admin's rollup (resolve_org_scope) already excludes these namespaces by name (ns_hidden) and leaves out unreadable collections.

Fix: the exclusion step from resolve_org_scope's admin branch is now auth.context.every_namespace_scope, and the owner report's wildcard and auth-off path calls it. When classification cannot be read, the report comes back empty, as an org admin's rollup does. The helper also leaves out the namespaces the token's claim names but the gate refuses. A typical case is a claim capped at a revoked grant (authz.claim_cap), which applies even next to * and even for an org admin. Org-admin rollups through resolve_org_scope get the same exclusion. A delegated token with a * claim reaches only where its creator holds a live grant (authz._check_delegated), so it now takes the member path (rollup_member_namespaces), not the every-namespace one. owner_report now takes one predicate (an OrgScopeFilter, built with namespace_scope(...) for a list) in place of a namespace list with a * sentinel, and the sentinel path is gone. In the reads statement namespace is e.namespace through the SELECT alias, so the same predicate covers both the ledger and the memory subquery.

Scope and risk

Touches server/auth/context.py. There, resolve_org_scope's admin branch now also leaves out a named claim that the gate refuses, at the cost of one cached grant-map read per rollup. Also touches server/memory/app/exposure.py and server/memory/app/owner_report.py. Scoped tokens and calls that name a namespace read the same rows as before. A wildcard token now sees less: nothing from a restricted namespace it holds no grant for, and nothing from a collection it cannot read. A delegated * token now sees only what its creator's live grants reach.

Compatibility, rollout and rollback

  • Wire: no op or field changed.
  • Operator steps: none.
  • Rollback: a plain revert. No rows or migrations.

Tests

  • test_a_wildcard_token_leaves_out_the_restricted_namespaces_it_cannot_read marks ns-r restricted, calls the handler with a wildcard VIEWER token and asserts that all three statements carry NOT IN {ns_hidden} bound to ["ns-r"]. It failed before the fix, because the SQL had no namespace predicate.
  • The same test also asserts the collection clause. test_a_delegated_wildcard_token_takes_the_member_path asserts that a delegated * token's report is bounded by nss to its member namespaces. On main the report had no nss predicate. test_a_wildcard_token_gets_nothing_when_classification_is_unreadable asserts that the report is empty, runs no statement and marks the request answered-unverified. test_with_auth_off_the_report_reads_every_namespace takes the place of the old sentinel test.
  • The reads statement with the alias-scoped predicate was run through clickhouse local (26.9) and returned only the unhidden namespace.
  • test_a_wildcard_scope_excludes_a_named_claim_capped_at_a_revoked_grant uses a claim of *, x and shop, with a revoked grant on x, and asserts ns_hidden == [restricted, "x"].
  • pytest tests/unit/test_owner_report.py tests/unit/test_request_sli.py tests/unit/test_context_restricted_resolution.py tests/unit/test_package_contracts.py passed. make format lint typecheck passed.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. Checked: the gate rule for wildcard claims, that resolve_org_scope keeps its output, and that the new test failed before the fix.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

🤖 Generated with Claude Code

@zlareb1 zlareb1 changed the title memory.owner_report for a wildcard token leaves out restricted namespaces it cannot read memory.owner_report for a wildcard or delegated token covers only what the token can read Nov 3, 2026
zlareb1 and others added 4 commits November 3, 2026 22:23
…aces it cannot read

A flat token with a `*` claim got an owner report with no namespace
predicate, so it counted rows, readers and usage in restricted namespaces
and collections the gate refuses it (a `*` never counts toward those).
The wildcard path now applies the same exclusion an org admin's rollup
does: `auth.context.every_readable_namespace`, factored out of
`resolve_org_scope`. The report takes a predicate (`NamespaceScope`)
instead of a namespace list with a `*` sentinel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A delegated token reaches only the namespaces where its creator holds a
live grant, so it takes the member path rather than the every-namespace
one. The report resolves its scope once: in the reads statement,
`namespace` is `e.namespace` by the SELECT alias, so a single predicate
covers both the ledger and the memory subquery. The wildcard test now
asserts the collection clause, and a new test covers a delegated token.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
With classification unreadable, a wildcard token's report is empty, runs
no statement and marks the request the server's. The delegated-token test
is named for what it checks (the member path), and the resolve_org_scope
docstring says what an admin's filter holds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the fix/owner-report-wildcard-restricted branch from 1ffb320 to a7b950f Compare November 3, 2026 22:23
zlareb1 and others added 7 commits November 3, 2026 22:31
A flat token whose claim names `x` next to `*`, and whose grant on `x`
was revoked, is capped at nothing there (`authz.claim_cap`), so the gate
refuses `x`. The scope that an org admin's rollup and a wildcard owner
report use now adds those named claims to `ns_hidden`, asked through
`CachedGate`. The projection-failure tests route the grant read this
adds, and stub `may_be_restricted` the gate now consults.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The empty predicate of an inaccessible OrgScopeFilter would read every namespace, so owner_report answers empty for it instead of trusting its caller to check; the handler's two early returns go.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ate admits

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 5474897 into main Nov 4, 2026
22 checks passed
@zlareb1
zlareb1 deleted the fix/owner-report-wildcard-restricted branch November 4, 2026 00:26
@pufit pufit mentioned this pull request Nov 4, 2026
9 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant