Repository navigation
A call with org or namespace "-" runs under the org the gate authorized - #195
Merged
Merged
Conversation
… 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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
…" as absent 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]>
… run on the ClickHouse fake 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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
… tested 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]>
…espace 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]>
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 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]>
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]>
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]>
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]>
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]>
…scope names a code.repo.* write's repository 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]>
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]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: zlareb1 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
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
orgis blank or"-"now runs under the org the gate authorized (the token's org, or the plane's default forcode.*andtracker.*); acode.*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_targetreads 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 refusedORG_MISMATCHby the pre-dispatch screen (mcp_auth._screen_tool_callread 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 emptyorgas absent.Failing case, against a server with auth on:
globexwriter sendsmemory.set {"org": "-", "namespace": "-", ...}. The row is stored withorg = '-'.acmeviewer sendsmemory.getormemory.searchwith{"org": "-", "namespace": "-"}and gets theglobexvalue back.globexnever 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 asglobexbut was stored as' globex ', out of reach of an erasure ofglobex).Fix, in two shared gate helpers that HTTP and MCP both call, so the transports cannot diverge:
gates.with_resolved_orgsets anorgsent 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 forcode.*/tracker.*, else the token's single org;authz_targetuses the same function). A body that leavesorgout, 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.registerchecks thatwebhook_secret_refnames the call's org, and used to check it against"-".gates.with_targetsets an absentnamespaceto the one the gate authorized (target.register_namespace, which is a plane default only forcode.*), right afterauthorize. 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: onmaina namespace sent as"-"reached the mentor as"-"and could draw a hint; now such a memory call gets none. Another visible change: acode.*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 refusedORG_MISMATCH),X-Loom-Code-Scopefills a"-"namespace and org as it already filled an empty one (apply_code_scope; the scope names the checkout's repository, so this includes thecode.repo.*writes over MCP, as""did onmain), 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 refusedIDENTITY_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 anamespacesfan-out list a"-"namespace no longer leads that list (_lead_namespaces). A namespace the op requires (thecode.repo.*admin writes) is never filled, socode.repo.set_access {"namespace": "-"}over HTTP reaches its handler with namespace"-", as onmain, 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 requiresorgand skipping required fields would leave the leak open:code.repo.set_access {"org": "-", "namespace": "repo@main"}now acts onrepo@mainin the code plane's org, which is the org the gate already authorized it against (authz_targetresolves an absent org to the plane's forcode.*andtracker.*). Onmainthe same call was authorized there but answeredNOT_A_REPOfor org'-'.Scope and risk
server/transport/gates.py,http.py,mcp_call.py,mcp_auth.py,mcp_outcome.pyand_common.py,apply_code_scopeinserver/code/domain/scope.py, the onepresenthelper now inserver/core/naming.py, theplane_org_fordocstring inserver/code/app/common.py,_lead_namespacesinserver/code/api/models_common.py, plus one sentence ofdocs/reference/http-api.md, which now names blank and"-"as absent. An input whoseorg/namespaceis named and present is unchanged. An absent value is filled only when the gate resolved one. With auth off and no plane default,target.orgis 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 aboutcheck_authorized, inside one org.Compatibility, rollout and rollback
"-"now reads and writes its token's org.Idempotency-Keythat lands on the other build hashes a different input, so it answersIDEMPOTENT_CONFLICTinstead of replaying. This affects calls that leaveorgornamespaceabsent while N-1 and N both serve: a"-"or""org on any op, and acode.*ortracker.*write that names no org or namespace (code.outcome,code.scip_ingest,code.repo.*, tracker writes). The window closes when the rollout finishes."-"-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 refusedIDENTITY_INCOMPLETE. So find and read them with SQL:WHERE org = '-'on every tabletests/unit/test_every_table_is_classified.pyclassifies 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 sendserasure.requestwithorg: "-"and anamespaceornamespace_listscope naming the namespaces the SQL found. A deployment that never received a"-"-org call has none.Tests
tests/unit/test_absent_org_runs_under_target.py:memory.getwith org"-",""and" ", andmemory.setwith org"-", reach the handler with orgglobex;loom_memory_getwith org"-"and" "reaches the handler with orgglobex;inbox.registerwith org"-"and the token org's webhook secret ref is admitted under that org; with a"-"-org ref it is a 422;with_targetfills 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;tracker.*read with org"-"takes the tracker org and keeps its namespace;*token naming org"-"with a namespace isIDENTITY_INCOMPLETEat the gate, and over MCP takes the caller's default org for"-"as for"";globex, namespacens1and sessionglobex/ns1/afor an org-"-"call over HTTP, onglobex/ns1/aover MCP too, and gets namespace""for a call naming none;ledger_identityrecords them stripped;"-"(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,0or[]org is still refused 422.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. Onmainits first read fails, because the row lands under org'-'(reproduced by hand below).*admin'serasure.request {"org": "-", "scope_type": "namespace", "scope_value": "-", ...}completes and tombstones the'-'/'-'row themainreproduction left behind, so the operator step works as written.globexwrite lands inglobex/ns1, and theacmeread of org"-"answersfound: 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 typecheckandmake test-unitpass; the integration suite passes if server behaviour changed.docs/describe the system as it now is, and this description names any operator steps and wire changes.git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code