Repository navigation
fix(api): reject grp_-prefixed personal user IDs at every identity boundary - #335
Merged
loveRhythm1990 merged 1 commit intoOct 19, 2026
Conversation
…undary A personal user ID beginning with grp_ was routed to group storage by DbRouter::scope_store()/MemoryService::user_sql_store(), which infer scope type from string prefix alone instead of the authenticated principal's group_id. Only the owner-scoped master auth path rejected this prefix; API-key creation and master/open-mode X-User-Id resolution did not, letting a personal request get silently dispatched into an unrelated group's store if a same-named active group existed. Reject the grp_ prefix consistently at every boundary that mints or accepts a personal user_id: personal API-key creation, and master-key / open-mode X-User-Id / X-Impersonate-User / query-param resolution. The owner-scoped path already had this check; it's now reused via a shared helper instead of being duplicated. Fixes matrixorigin#334 Co-Authored-By: Claude Sonnet 5 <[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.
Summary
Fixes #334.
DbRouter::scope_store()/MemoryService::user_sql_store()dispatch between personal and group storage purely by checking whether the scope string starts withgrp_, without regard to the authenticated principal's actualgroup_id. Only the owner-scoped master-auth path (validate_owner_scoped_master_request) rejected this prefix for personal user IDs; API-key creation and the master-key/open-modeX-User-Idresolution did not. A personal principal whoseuser_idhappened to start withgrp_(via a mis-issued personal API key, or an open-mode client supplying an arbitraryX-User-Id) could therefore be silently dispatched into an unrelated group's store if a same-named active group existed.This PR takes the narrower of the two fixes the issue proposes: consistently reject the reserved
grp_prefix at every boundary that mints or accepts a personaluser_id, rather than threading an explicit scope-type through the whole call chain. That keeps the existing string-prefix dispatch inrouter.rs/service.rssafe by invariant, without touching those call sites.Changes
memoria-api/src/auth.rs: extract the existinggrp_rejection (previously inlined invalidate_owner_scoped_master_request) into a sharedis_reserved_group_id()helper, and a newresolve_personal_user_id()helper that resolves + validates the master-key/open-modeX-User-Id/X-Impersonate-User/query-param path the same way.memoria-api/src/routes/auth.rs:create_key's personal-key branch (group_idabsent) now rejects auser_idstarting withgrp_before persisting the key.Out of scope (per issue's own acceptance criteria)
Per discussion, this PR intentionally does not cover: already-persisted API keys/cached principals created before this fix,
invalidate_scope()'s own prefix heuristic inrouter.rs, or threading an explicit scope-type through the router/service layers (the issue's alternative, broader fix). Those remain open follow-ups if needed.Test plan
cargo test -p memoria-api --lib auth::— 20/20 pass, including 5 new unit tests covering theX-User-Idheader,X-Impersonate-Userheader, and query-param paths, plus the ordinary (non-grp_) case.cargo check -p memoria-api/cargo clippy -p memoria-api --lib -- -D warnings— clean.create_key's rejection path (no local MySQL/MatrixOne instance available in this environment to extendmemoria-api/tests/*); the unit tests above cover the same validation logic in isolation.🤖 Generated with Claude Code