Skip to content

feat: deny-by-default retrieval authorization scoping - #96

Open
DavidAkere204 wants to merge 2 commits into
Deen-Bridge:devfrom
DavidAkere204:dev
Open

feat: deny-by-default retrieval authorization scoping#96
DavidAkere204 wants to merge 2 commits into
Deen-Bridge:devfrom
DavidAkere204:dev

Conversation

@DavidAkere204

Copy link
Copy Markdown
  • Add retrieval/scope.py: RetrievalScope dataclass (principal_user_id, role, publish_visibility), derive_scope(), assert_scope_match(), visible_to() post-check, cache_scope_key() partition helper.

  • Update memory/store.py: get_profile/get_chat_summary accept scope= kwarg; cross-user and anonymous access is blocked and logged.

  • Update semantic_cache.py: CacheEntry carries scope_key slot; SemanticCache.get()/put() enforce partition match so per-user entries never cross principals.

  • Update main.py: _resolve_principal() reads X-User-Id header; /chat and /chat/stream derive RetrievalScope, assert_scope_match raises 403 on body user_id ≠ principal; all memory lookups use _effective_user_id from scope; /memory/{user_id} GET+DELETE and /user/{user_id}/chats enforce scope guard with 403; /chat/stream outer exception handler re-raises HTTPException correctly.

  • Add tests/test_retrieval_scope.py: 63 adversarial tests covering scope construction, derive_scope, assert_scope_match, visible_to post-check, cache partition isolation, memory store enforcement, denied-retrieval logging (no PII leak), HTTP 403 integration tests, and bypass-attempt matrix.

Closes #91

- Add retrieval/scope.py: RetrievalScope dataclass (principal_user_id,
  role, publish_visibility), derive_scope(), assert_scope_match(),
  visible_to() post-check, cache_scope_key() partition helper.

- Update memory/store.py: get_profile/get_chat_summary accept scope=
  kwarg; cross-user and anonymous access is blocked and logged.

- Update semantic_cache.py: CacheEntry carries scope_key slot;
  SemanticCache.get()/put() enforce partition match so per-user entries
  never cross principals.

- Update main.py: _resolve_principal() reads X-User-Id header;
  /chat and /chat/stream derive RetrievalScope, assert_scope_match
  raises 403 on body user_id ≠ principal; all memory lookups use
  _effective_user_id from scope; /memory/{user_id} GET+DELETE and
  /user/{user_id}/chats enforce scope guard with 403; /chat/stream
  outer exception handler re-raises HTTPException correctly.

- Add tests/test_retrieval_scope.py: 63 adversarial tests covering
  scope construction, derive_scope, assert_scope_match, visible_to
  post-check, cache partition isolation, memory store enforcement,
  denied-retrieval logging (no PII leak), HTTP 403 integration tests,
  and bypass-attempt matrix.

Closes Deen-Bridge#91
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown

Important

Review available on request

  • 🔍 Trigger review

Reviews should be triggered manually for repositories with fewer than 10 stars. Select Trigger review above or comment @coderabbitai review to review the latest changes. For a full review, comment @coderabbitai full review.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: fd9f15d1-038c-4af9-aaec-b9fa43699cfb


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@zeemscript

Copy link
Copy Markdown
Contributor

Strict review blocker: this branch conflicts with the base branch, and is failing. Please resolve both blockers.

@zeemscript

Copy link
Copy Markdown
Contributor

Strict review blocker: this branch conflicts with the base branch, and Lint and Test is failing. Please resolve both blockers.

@zeemscript

Copy link
Copy Markdown
Contributor

Strict review blocker: required checks are failing. Please fix the failures before requesting merge.

@zeemscript

Copy link
Copy Markdown
Contributor

@DavidAkere204 this PR has merge conflicts with the main branch. Please resolve the conflicts (merge main in or rebase) and push the fix so it can be merged. Thanks!

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.

2 participants