Skip to content

code.search authorizes a one-entry namespaces list, a tracker is linked only by its admin, and a taken inbox hides its owner - #310

Merged
zlareb1 merged 17 commits into
mainfrom
sec/code-search-one-namespace
Nov 7, 2026
Merged

zlareb1 merged 17 commits into
mainfrom
sec/code-search-one-namespace

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 6, 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):

code.search with a one-entry namespaces list authorizes that namespace before searching it, as it does each entry of a longer list; a caller who cannot read it gets 403. code.repo.set_source stores a link only to a tracker the caller administers, unless the repository's own links already hold it; a reader of the tracker gets 403, anyone else NOT_A_TRACKER_NAMESPACE. Keeping, reordering or dropping a link the repository's stored links already hold is unchanged; a tracker only the deployment's map links counts as new. inbox.register names the namespace that owns an inbox only to a caller who can read it.

Why

The transport gate authorizes the request's org and namespace. code.search takes namespaces for a fan-out, and a list of two or more goes through search_fanout.authorize, which checks each entry. A one-entry list instead went to normalize, which made the entry the request's namespace after the gate had run, so the search ran on a namespace nobody had authorized, a restricted one included.

A second case of the same class: code.repo.set_source checked that each tracker namespace it links exists, not that the maintainer can read it. A linked tracker is read by whoever may read the repository (binding._gated gates a standard tracker on the code namespace), and self-service code.repo.add makes its viewer the new repository's admin, so linking a tracker decided who reads it, which is the tracker admin's call: a viewer of a tracker under an approval join policy could link it to a repository anyone may join. And inbox.register named the owning namespace of a taken inbox to an admin of any namespace, where every other inbox path answers as for a missing inbox.

Design

  • search_fanout.normalize is async and authorizes the entry (authorize, the fan-out's own fail-closed check over row_in_scope) before it rewrites the input.
  • repo_admin._tracker_or_refuse also requires row_in_scope(org, tracker, ADMIN) for a tracker the repository's stored maintainer links do not already hold, restricted or not. A tracker only the operator map links counts as new, since storing it would outlive a later change to the map. The stored links are the repository's own row, read for its org (CodeRepo.get_state, which raises when unread), not the deployment-wide link snapshot, which is keyed by namespace name alone and could hold another org's row under the same name. Two concurrent set_source calls still race read-then-write, as every maintainer setting does. A caller who reads the tracker is told it needs its admin (403); anyone else gets NOT_A_TRACKER_NAMESPACE, the code a missing tracker gets (it is not a secrecy guarantee: tracker.source.add's taken-name answer still tells an existing tracker apart). Keeping, reordering or dropping a stored link needs no admin of it, so the dashboard's whole-list updates keep working for those; on a repository whose links come only from the deployment's map, the first save stores them and so needs each tracker's admin, and the 403 says why. A link is a lasting delegation: it stays in force if the maintainer later loses the tracker, and the repository's admins then decide who reads it, including through a later code.repo.set_access join-policy change, as the tracker overview now says.
  • inbox.register's INBOX_OWNED_ELSEWHERE says "another namespace" unless the caller can read the owner.
  • Not in this change: the deployment's tracker map (LOOM_TRACKER_CODE_NAMESPACE_BINDINGS_JSON) and the stored-link snapshot are keyed by code namespace name alone, so a self-service repository whose name matches a map glob, or another org's repository of the same name, picks up links without the tracker admin's consent. That read path is older than this PR; Tracker links are read per org, and the operator's map links only the operator's repositories #331 keys the stored-link snapshot by (org, namespace), which also closes set_source's previous_tracker_namespaces, still read here from that snapshot and so able to name another org's links under the same name.
  • A regression guard for the class: tests/unit/test_op_scope_fields.py lists every op input field that names another namespace, org or inbox (namespaces, to_namespace, extra_namespaces, from_org, inbox, ...) with the function that checks it, and checks the function exists. A new such field fails the test until it is declared there, and a declaration whose field is gone fails too. Names that resolve to a namespace indirectly (code.repos' repo) and namespace_scope (filtered by the fan-out through the gate) are outside the pattern, as the test's docstring says. The gate checks only org and namespace, so each of these fields needs its own handler-side check.

Scope and risk

server/code/app/search_fanout.py, its call in server/code/app/search/handler.py, server/code/app/repo_admin.py, server/code/api/models_repos.py (the field comment, and the regenerated docs/reference/operations/code.md), server/tasks/app/inboxes.py, two comments in server/tracker/app/binding.py, the repository card's tracker picker (frontend/src/views/RepositoryCard.tsx, with bindableRecords in frontend/src/lib/trackerSources.ts: it says a new link needs the tracker's admin; a tracker the caller holds no admin grant on is marked, not hidden, since a token that administers it another way may still link it, and the hint says Loom links it only if the token administers it; when a linked tracker is one the caller holds no admin grant on, the card says that if the links come from the deployment's map, any change stores them, which needs an admin of each), their tests, one row of the tracker overview, the new contract test and one row of the security page's CI-gate table. A one-entry search runs one row_in_scope read. Every set_source call now makes one point read of the repository's qa_binding state row; each tracker it newly links runs one row_in_scope read for an admin of it and two otherwise, a missing tracker and a kept link none. set_source is the only writer of the qa_binding row (other code_index_state writers use their own fixed keys, knowledge sources write knowledge_source:<name> keys, and erasure only deletes), so every stored link that counts as kept passed this check or was stored before it, as the operator steps say.

Compatibility, rollout and rollback

  • Wire: code.search with namespaces: [x] answers 403 AUTH_INSUFFICIENT when the caller cannot read x; before, it searched x. code.repo.set_source newly linking a tracker the caller does not administer answers 403 AUTH_INSUFFICIENT to a reader of it and 422 NOT_A_TRACKER_NAMESPACE to anyone else. inbox.register's 409 message no longer names an owner the caller cannot read.
  • Operator steps: review existing repository links to trackers (code.repo.set_source state) made by maintainers who are not the tracker's admin (the qa_binding key in loom.code_index_state); links stored before stay in force until changed. During a rolling upgrade the review also covers qa_binding rows written until the last N-1 replica stops, since N-1's set_source has no admin check.
  • Rollback: revert.

Tests

pytest tests/unit/test_code_search_fanout.py tests/unit/test_code_presence.py tests/unit/test_request_sli.py tests/unit/test_op_scope_fields.py tests/unit/test_tracker_multi_binding.py tests/unit/test_tracker_source_form.py tests/unit/test_task_inbox.py tests/unit/test_code_repo_access.py: code.symbol and code.grep presence mode with namespaces: ["code-secret"] are refused before anything runs; a viewer of one code namespace searching namespaces: ["code-secret"] is refused with AuthInsufficientError naming it, and searching namespaces: ["code-default"], which it reads, runs the single search there (the refusal fails on main, where the search runs on code-secret); newly linking a tracker the maintainer reads but does not administer is refused with 403, one it cannot read like a missing one, and reordering or dropping an existing link needs no admin of it; a taken inbox names its owner only to the owner's readers; every current second-scope field is declared with a function that exists; an unread link row refuses the write, and a row under the same namespace name in another org does not count as this repository's.

npx vitest run src/views/RepositoryCard.test.tsx (in frontend/): the Trackers picker marks a tracker the caller holds no admin grant on, says a new link needs its admin, still sends the link, and names the linked trackers a change would store without the caller's admin grant.

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 traced the gate's target and the handler's rewrite, and checked the new test fails without the fix.

  • 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: the SDK op tables, docs/reference/configuration.md and the docs/reference/ tables (python scripts/codegen/docs_reference.py), the reach manifest, schemas/schema.sql (make schema-dump) and the Codex plugin copies (python3 scripts/codegen/agent_plugin_sync.py).
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships (hooks/, lib/, bin/, skills/, .mcp.json, the Codex plugin-defaults.json) bumps both plugin manifests' version, and no other open PR uses that version.
  • The frontend builds (npm --prefix frontend run build) and its tests pass, if frontend/ changed.
  • 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; the history goes in this description (tests/unit/test_public_copy.py).
  • Commits are signed off (git commit -s), as CONTRIBUTING.md asks.

🤖 Generated with Claude Code

@zlareb1 zlareb1 changed the title code.search authorizes a one-entry namespaces list before searching it code.search authorizes a one-entry namespaces list, and code.repo.set_source links only trackers the caller reads Nov 6, 2026
@zlareb1 zlareb1 changed the title code.search authorizes a one-entry namespaces list, and code.repo.set_source links only trackers the caller reads code.search authorizes a one-entry namespaces list, a tracker is linked only by its admin, and a taken inbox hides its owner Nov 6, 2026
zlareb1 and others added 15 commits November 7, 2026 06:38
The gate checks the request's namespace; a one-entry namespaces list became the namespace the search ran on without a check. It is now authorized as each entry of a longer list is. A contract test declares, for every input field naming another namespace or org, the check its handler runs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…-field contract names each check's function

A linked tracker is read by whoever reads the repository, so linking one the maintainer cannot read widened its readers; an unreadable tracker now answers as a missing one. The contract test covers inbox and org fields and checks each declared function exists.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ames its owner only to the owner's readers

Linking a standard tracker opens it to every reader of the repository, which is the tracker admin's call, so set_source requires ADMIN on it. inbox.register's conflict names the owning namespace only to a caller who may read it.

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

Keeping, reordering or dropping a link already in force widens nothing. A caller who reads but does not administer the tracker gets 403; anyone else the missing-tracker answer. inbox.register reads the owner's scope without marking the conflict unverified.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ce stores it, and the stored links are read fail-closed

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…s the tracker's admin, and test the fail-closed link read

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The deployment-wide link snapshot is keyed by namespace name alone, so another org's row under the same name could count as this repository's. set_source reads its own row for its org, which raises when unread; refresh_overrides keeps no strict mode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The 403 says a link from the deployment's map counts as new, the field
comment is one sentence, the missing-tracker answer is no longer called
indistinguishable, and the overview says the repository's admins decide
a linked tracker's readers. The inbox owner test asserts each detail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
A restricted tracker keeps its own gate, so the overview says a linked
standard tracker is what every reader of the repository reads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The Trackers picker says a new link needs the tracker's admin, and a
tracker the caller does not administer is marked "needs its admin"
rather than hidden, since an org-wide admin token may still link it.
The scope-fields test names erasure's scope_value as out of pattern,
and the security page calls it a declaration list the test keeps
complete.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Both call row_in_scope with hides_answer=False only to word a refusal
another check decided: the ADMIN check refused the tracker link, and the
inbox is taken whatever the caller reads. An unverified probe there does
not change the answer, so it does not mark the request the server's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the sec/code-search-one-namespace branch from 35cf1c8 to 03287e6 Compare November 7, 2026 06:40
…save stores

The picker's mark follows the caller's grants, not the server's check,
so it says the caller holds no admin grant and that Loom links the
tracker only if the token administers it. When a linked tracker is one
the caller holds no admin grant on, the card says that a change stores
links that come from the deployment's map, which needs an admin of each.
code.symbol and code.grep presence mode refuse a one-entry list naming
an unreadable namespace before anything runs.

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]>
@zlareb1
zlareb1 merged commit 78e32b8 into main Nov 7, 2026
38 checks passed
@zlareb1
zlareb1 deleted the sec/code-search-one-namespace branch November 7, 2026 09:16
@zlareb1 zlareb1 mentioned this pull request Nov 12, 2026
3 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