Skip to content

A call with org or namespace "-" runs under the org the gate authorized - #195

Merged
zlareb1 merged 35 commits into
mainfrom
fix/http-absent-org-runs-under-token-org
Nov 3, 2026
Merged

zlareb1 merged 35 commits into
mainfrom
fix/http-absent-org-runs-under-token-org

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):

A request (HTTP or MCP) whose org is blank or "-" now runs under the org the gate authorized (the token's org, or the plane's default for code.* and tracker.*); a code.* request with namespace blank or "-" reads the code namespace it is authorized against. Before, it ran under the literal "-", so a token of any org could read what a token of another org wrote that way.

Why

gates.authz_target reads a blank or "-" org as absent. It authorizes the call against the token's org, or the plane's default. Both transports then handed the handler the unchanged input, so the handler wrote and read the literal "-" org. Over MCP, an org-scoped token's "-" org was refused ORG_MISMATCH by the pre-dispatch screen (mcp_auth._screen_tool_call read any non-empty org as named), and an org-* token's reached the handler as sent, because the default filling treated only a missing or empty org as absent.

Failing case, against a server with auth on:

  1. A globex writer sends memory.set {"org": "-", "namespace": "-", ...}. The row is stored with org = '-'.
  2. An acme viewer sends memory.get or memory.search with {"org": "-", "namespace": "-"} and gets the globex value back.
  3. Erasing globex never reaches the row.

Pattern: the authorization target and the input the handler runs with can disagree whenever the gates normalise the body's identity field: an absent (blank or "-") org, and a padded org or namespace (" globex " is authorized as globex but was stored as ' globex ', out of reach of an erasure of globex).

Fix, in two shared gate helpers that HTTP and MCP both call, so the transports cannot diverge:

  • gates.with_resolved_org sets an org sent as a blank or "-" string, on the copy of the arguments the input model validates (the raw body a refusal's ledger row reads stays as sent), to the org the call acts in (gates.resolve_org: the plane's for code.* / tracker.*, else the token's single org; authz_target uses the same function). A body that leaves org out, or sends it null or as a non-string, is still refused 422 as before. A padded org or namespace is stripped there too, and the ledger row (ledger_identity) records it stripped. Resolving before validation matters for a validator that reads the org: inbox.register checks that webhook_secret_ref names the call's org, and used to check it against "-".
  • gates.with_target sets an absent namespace to the one the gate authorized (target.register_namespace, which is a plane default only for code.*), right after authorize. It copies rather than re-validates, so an absent namespace still leads no code fan-out list.

The handler and the idempotency hash now name the authorized tenant, as the ledger row (ledger_identity) already did. The mentor hint on both transports is keyed on the admitted tenant too (ledger_identity): its org, namespace and fallback session key, so "-"-org calls of two tenants no longer share one mentor session (its shown-hint count and its per-key write tally). A field that stays absent reaches the mentor as "", so a call naming no namespace reads no profile. That is also a visible change: on main a namespace sent as "-" reached the mentor as "-" and could draw a hint; now such a memory call gets none. Another visible change: a code.* call over MCP that names no org or namespace now gets the mentor's hint for the code plane's namespace, as the same call over HTTP already did when it named them.

Over MCP, the pre-dispatch screen now reads a blank or "-" org or namespace as absent (an org-scoped token's "-" call runs under its org instead of being refused ORG_MISMATCH), X-Loom-Code-Scope fills a "-" namespace and org as it already filled an empty one (apply_code_scope; the scope names the checkout's repository, so this includes the code.repo.* writes over MCP, as "" did on main), and the caller's default org fills a "-" or blank org, as it already filled an empty one. So an org-* token sending "-" runs in its default org, as it does with "", instead of being refused IDENTITY_INCOMPLETE.

The namespace fill also changes code.*: a code read naming namespace "-" was authorized against the code namespace but read namespace "-". It now reads the code namespace, and with a namespaces fan-out list a "-" namespace no longer leads that list (_lead_namespaces). A namespace the op requires (the code.repo.* admin writes) is never filled, so code.repo.set_access {"namespace": "-"} over HTTP reaches its handler with namespace "-", as on main, which looks up a repository named - rather than the shared code index. Over MCP, a connection's code scope names the repository first (above). The org is filled even where the op requires it, since every memory op requires org and skipping required fields would leave the leak open: code.repo.set_access {"org": "-", "namespace": "repo@main"} now acts on repo@main in the code plane's org, which is the org the gate already authorized it against (authz_target resolves an absent org to the plane's for code.* and tracker.*). On main the same call was authorized there but answered NOT_A_REPO for org '-'.

Scope and risk

server/transport/gates.py, http.py, mcp_call.py, mcp_auth.py, mcp_outcome.py and _common.py, apply_code_scope in server/code/domain/scope.py, the one present helper now in server/core/naming.py, the plane_org_for docstring in server/code/app/common.py, _lead_namespaces in server/code/api/models_common.py, plus one sentence of docs/reference/http-api.md, which now names blank and "-" as absent. An input whose org / namespace is named and present is unchanged. An absent value is filled only when the gate resolved one. With auth off and no plane default, target.org is None and the input keeps "-", as before.

Left out: a flat token that names no namespace still reaches its own org's "-" namespace without a namespace check. That is a separate question about check_authorized, inside one org.

Compatibility, rollout and rollback

  • Wire: no op or field changes. A caller that sent "-" now reads and writes its token's org.
  • Idempotency: the request hash covers the filled input. During a rolling upgrade, a retry carrying an Idempotency-Key that lands on the other build hashes a different input, so it answers IDEMPOTENT_CONFLICT instead of replaying. This affects calls that leave org or namespace absent while N-1 and N both serve: a "-" or "" org on any op, and a code.* or tracker.* write that names no org or namespace (code.outcome, code.scip_ingest, code.repo.*, tracker writes). The window closes when the rollout finishes.
  • Operator steps: once every replica runs this build (a "-"-org call that lands on N-1 still writes under '-'), look for rows under org '-'. They hold some tenant's content where any token could read it, and an erasure of the writer's org misses them. A namespaced op no longer reaches them: an org-scoped token's "-" now means its own org, and an org-* token naming "-" with a namespace is refused IDENTITY_INCOMPLETE. So find and read them with SQL: WHERE org = '-' on every table tests/unit/test_every_table_is_classified.py classifies as holding memory content (memory, memory_versions, memory_embeddings, memory_chunks, the entity tables, documents, conversations, tasks, among others). The ledger (loom.agent_events) names the authorized org of each write. Re-home what belongs to a tenant by writing it again under that org, then erase what remains: an org-* admin token sends erasure.request with org: "-" and a namespace or namespace_list scope naming the namespaces the SQL found. A deployment that never received a "-"-org call has none.
  • Rollback: reverting restores the old behaviour; nothing is left behind.

Tests

  • New tests/unit/test_absent_org_runs_under_target.py:
    • over HTTP, memory.get with org "-", "" and " ", and memory.set with org "-", reach the handler with org globex;
    • over MCP, loom_memory_get with org "-" and " " reaches the handler with org globex;
    • inbox.register with org "-" and the token org's webhook secret ref is admitted under that org; with a "-"-org ref it is a 422;
    • with_target fills the code namespace for namespace "-", and leaves a named or unresolved one as sent; code.search {"org": "-", "namespace": "-"} reaches the handler with the code plane's org and namespace over HTTP and over MCP;
    • a tracker.* read with org "-" takes the tracker org and keeps its namespace;
    • an org-* token naming org "-" with a namespace is IDENTITY_INCOMPLETE at the gate, and over MCP takes the caller's default org for "-" as for "";
    • the mentor hint is keyed on org globex, namespace ns1 and session globex/ns1/a for an org-"-" call over HTTP, on globex/ns1/a over MCP too, and gets namespace "" for a call naming none;
    • a padded org and namespace reach the handler stripped over HTTP, a padded org over MCP, and ledger_identity records them stripped;
    • a required namespace sent as "-" (code.repo.set_access) is left as sent, and an absent org on that op takes the code plane's;
      The admission path runs on tests/unit/ch_fake.py, not on failing ClickHouse calls. Before the fix, the HTTP case failed with [('MemoryGetInput', '-', 'ns1')] != [('MemoryGetInput', 'globex', 'ns1')] and the MCP case with ['-'] != ['globex']; after it, all thirty-one pass (including the MCP screen admitting "-", blank and padded orgs while still refusing another org, the code scope filling "-", and a padded org and namespace reaching the handler stripped), and a null, 0 or [] org is still refused 422.
  • The transport, gate, MCP, identity, idempotency, tenant, mentor and inbox unit tests pass: 1442 passed.
  • tests/integration/test_cross_principal_leakage.py::test_a_dash_org_is_the_tokens_own_org: tenant A writes with org "-", reads the row back by id under its own org and compares its id, namespace, agent, key, value, user and session, and another org's token naming "-" gets nothing. Passes against a local server on this branch. On main its first read fails, because the row lands under org '-' (reproduced by hand below).
  • By hand against a local server with this branch: an org-* admin's erasure.request {"org": "-", "scope_type": "namespace", "scope_value": "-", ...} completes and tombstones the '-'/'-' row the main reproduction left behind, so the operator step works as written.
  • By hand against a local server with this branch: the globex write lands in globex/ns1, and the acme read of org "-" answers found: false.

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. I reproduced the HTTP leak against a local server before and after the change, and the MCP one with the unit test.

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

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand: no generated file changes.
  • Docs under docs/ describe the system as it now is, and this description names any operator steps and wire changes.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

zlareb1 and others added 2 commits November 3, 2026 09:47
… authorized

The gate read a blank or "-" org as absent and authorized the call against the token's org, but the handler received the literal "-": a token of one org wrote rows under org "-" and a token of any other org read them back. The input now carries the resolved org and namespace before the handler runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…e shared gate helper

gates.with_target fills an absent org or namespace from the target the gate authorized; HTTP and MCP both call it right after authorize, so the two transports cannot diverge. HTTP's @me resolution reads an absent org as absent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1 zlareb1 changed the title An HTTP call with org or namespace "-" runs under the org the gate authorized A call with org or namespace "-" runs under the org the gate authorized Nov 3, 2026
zlareb1 and others added 27 commits November 3, 2026 10:04
…" as absent

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… run on the ClickHouse fake

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ce is not

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tracker cases go through authz_target and validation

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…eads the row back by id

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… the row's identity fields

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ss and type

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…he writer's org

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A validator that reads the org (an inbox's webhook secret names it) ran against the literal "-". The raw arguments now carry the org the call acts in before validation; with_target fills only the code namespace after authorization.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…is still a 422

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…l's ledger row reads stays as sent

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…names the strip

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]>
…e as absent

The pre-dispatch screen refused a "-" org as ORG_MISMATCH before the gate ran, and X-Loom-Code-Scope did not fill a "-" namespace.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit f9bbda2 into main Nov 3, 2026
22 checks passed
@zlareb1
zlareb1 deleted the fix/http-absent-org-runs-under-token-org branch November 3, 2026 17:54
@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