Skip to content

namespace.restore refuses a collection name, as namespace.register does - #200

Merged
zlareb1 merged 5 commits into
mainfrom
fix/restore-refuses-collections
Nov 3, 2026
Merged

zlareb1 merged 5 commits into
mainfrom
fix/restore-refuses-collections

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

namespace.restore refuses a collection name (col-…, an end user's personal collection included), as namespace.register does. Before, any viewer in an org could restore a payload into a collection that had no directory row yet and become its admin. A collection's snapshot now restores into a plain namespace only.

Why

Failing case: a viewer of org o computes personal_name("o", "user:alice") (a deterministic hash of org and subject) for an end user who has not written yet, so no loom.namespaces row exists. namespace.restore (role viewer, skip_namespace_authz) finds no target row, skips the admin check, writes a namespace row owned by the caller, an admin grant for the caller and the payload's memory rows into that personal collection. Alice's next @me read is served the planted rows. The same path on any col- name with a tree row but no directory row gives the caller an admin grant that the collection check honours.

Pattern: collections are reached only through their grants, and namespace.register refuses the col- prefix for that reason. namespace.restore writes the same rows and lacked the refusal.

Fix: the refusal moves into one helper, refuse_collection_name, which both handlers call before anything is read or written. It also refuses a literal @me: the transport maps that alias only in a request's namespace field, so a restore's target_namespace of @me reached the handler unmapped and would have created a directory row by that name.

The rest of the restore authorization stays as it was: an existing target (active or soft-deleted) needs an admin on it, with the restricted check, before the idempotency probe answers; a fresh non-collection target makes the caller its admin, as namespace.register does; SSO names stay refused.

Scope and risk

Touches handle_namespace_restore and handle_namespace_register (same refusal, now shared). A restore into a collection or a literal @me is refused with a validation error. This also refuses what used to work: an admin of an existing collection restoring a snapshot back into it. That is deliberate: a collection's rows and grants are changed only by the collection operations, as namespace.register already enforces, and a restore writes grants and an admin grant directly. namespace.snapshot still reads a collection, and its payload restores into a plain namespace. The restore rows in the sharing, tokens-and-grants, backup and history docs say so. No stored data changes.

Compatibility, rollout and rollback

  • Wire: no op or field added or removed. Break: namespace.restore with a col- or @me target now answers a validation error, including for an admin of an existing collection.
  • Operator steps: none. During a rolling upgrade an N-1 replica still accepts such a restore until it is replaced.
  • Rollback: reverting leaves nothing behind.

Tests

  • tests/unit/test_namespace_restore_existing_target.py::test_a_restore_into_a_collection_name_is_refused, for a personal collection name, a plain col- name and a literal @me, with no directory row: failed before the fix (no error raised, rows written), passes after, and asserts no insert at all.
  • The restore, snapshot and register unit tests pass; make format lint typecheck pass.

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. The failing case was checked against the handler and the op declaration, and the test was seen to fail before 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.
  • 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 and others added 5 commits November 3, 2026 10:07
A viewer could restore a payload into a collection that had no directory
row yet, an end user's personal collection included (its name is a hash
of org and subject), and so write its namespace row, an admin grant for
the caller and the payload's memories into it. Both handlers now call
refuse_collection_name before anything is read or written.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The transport maps `@me` only in a request's `namespace` field, so a
restore's `target_namespace` of `@me` reached the handler as a literal
name. The shared refusal now covers it; the sharing comment and the
restore rows in the guides say a collection name is refused; the
now-redundant local imports of is_collection go.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
The target_namespace description, which the operations reference and a
calling agent read, names the refusal; the backup page says a
collection's snapshot restores into a plain namespace; a test pins
register's refusal through the shared helper.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit fd709e2 into main Nov 3, 2026
39 of 40 checks passed
@zlareb1
zlareb1 deleted the fix/restore-refuses-collections branch November 3, 2026 19:22
@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