Repository navigation
namespace.restore refuses a collection name, as namespace.register does - #200
Merged
Merged
Conversation
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]>
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):
namespace.restorerefuses a collection name (col-…, an end user's personal collection included), asnamespace.registerdoes. 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
ocomputespersonal_name("o", "user:alice")(a deterministic hash of org and subject) for an end user who has not written yet, so noloom.namespacesrow exists.namespace.restore(roleviewer,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@meread is served the planted rows. The same path on anycol-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.registerrefuses thecol-prefix for that reason.namespace.restorewrites 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'snamespacefield, so a restore'starget_namespaceof@mereached 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.registerdoes; SSO names stay refused.Scope and risk
Touches
handle_namespace_restoreandhandle_namespace_register(same refusal, now shared). A restore into a collection or a literal@meis 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, asnamespace.registeralready enforces, and a restore writes grants and an admin grant directly.namespace.snapshotstill 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
namespace.restorewith acol-or@metarget now answers a validation error, including for an admin of an existing collection.Tests
tests/unit/test_namespace_restore_existing_target.py::test_a_restore_into_a_collection_name_is_refused, for a personal collection name, a plaincol-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.make format lint typecheckpass.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 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.tests/unit/test_public_copy.py).git commit -s), as CONTRIBUTING.md asks.🤖 Generated with Claude Code