-
Notifications
You must be signed in to change notification settings - Fork 1
fix(dav): reject ambiguous nested authorization encodings #1345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
seonghobae
wants to merge
33
commits into
develop
Choose a base branch
from
fix/dav-single-decode-authorization
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 17 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
3dc8420
test(dav): reject ambiguous nested authorization encodings
seonghobae 029c065
fix(dav): enforce single-decode authorization boundary
seonghobae 532a0b4
test(dav): reproduce dropped normalized route path
seonghobae fae5b62
fix(dav): propagate canonical authorization path
seonghobae b0e530d
Merge branch 'develop' into fix/dav-single-decode-authorization
opencode-agent[bot] 0a897db
test(dav): align route assertions with framework decoding
seonghobae 9e82a88
Merge protected develop into DAV authorization fix
seonghobae f7abb82
Merge protected develop into DAV authorization fix
seonghobae b66af0d
test(security): reject unsafe local-provider address classes
seonghobae 81c8890
fix(security): bound local LLM provider networks
seonghobae 5b0a888
docs(security): record DAV and local-provider network boundaries
seonghobae 60feaad
test(security): cover IPv6 local-provider network boundaries
seonghobae df2bf10
Merge protected develop into security fix lane
seonghobae d6a870d
test(data): reproduce cross-organization document access
seonghobae c05855f
test(data): inspect only document WHERE scope
seonghobae 2b8a18f
fix(data): enforce document organization scope
seonghobae 7cfa1bf
merge(develop): integrate current protected base
seonghobae 17b3452
test(data): cover remaining document organization scopes
seonghobae 0ca9624
test(data): use one api.data import style
seonghobae 3a56fed
Merge branch 'develop' into fix/dav-single-decode-authorization
opencode-agent[bot] 95f23c2
test(security): reject loopback DNS rebinding
seonghobae d73e9e4
fix(security): bind loopback access to local host identity
seonghobae 7052b66
test(security): scope loopback opt-in to local identities
seonghobae 76b5d16
test(dav): reject advertised unsupported capabilities
seonghobae a094523
fix(dav): expose only implemented protocol capabilities
seonghobae 085aecf
Merge branch 'develop' into fix/dav-single-decode-authorization
seonghobae bde6998
Merge branch 'develop' into fix/dav-single-decode-authorization
seonghobae ff6e475
merge(develop): reconcile DAV/SSRF/tenant isolation onto current develop
cursoragent 89d8850
Merge remote-tracking branch 'origin/develop' into HEAD
seonghobae 07954b2
Merge branch 'develop' into fix/dav-single-decode-authorization
opencode-agent[bot] 8c6a51e
Merge branch 'develop' into fix/dav-single-decode-authorization
seonghobae 8146c56
Merge remote-tracking branch 'origin/develop' into codex/pr1345-repair
seonghobae 9a01989
fix(dav): restore canonical LLM owner boundary
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| """Authorization regressions for workspace document actions.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import pytest | ||
| from fastapi import HTTPException | ||
|
|
||
| from api.auth import AuthContext | ||
| from api.data import _get_workspace_document | ||
| from db.models import Document | ||
|
|
||
|
|
||
| class _ScalarResult: | ||
| """Minimal SQLAlchemy result surface used by the authorization helper.""" | ||
|
|
||
| def __init__(self, value: Document | None) -> None: | ||
| self._value = value | ||
|
|
||
| def scalar_one_or_none(self) -> Document | None: | ||
| """Return the single simulated document result.""" | ||
|
|
||
| return self._value | ||
|
|
||
|
|
||
| class _OrganizationAwareSession: | ||
| """Evaluate document scope predicates against one in-memory document.""" | ||
|
|
||
| def __init__(self, document: Document) -> None: | ||
| self.document = document | ||
|
|
||
| async def execute(self, statement): | ||
| """Return the document only when every emitted scope predicate matches.""" | ||
|
|
||
| compiled = statement.compile() | ||
| rendered_scope = str(statement.whereclause) | ||
| values = tuple(compiled.params.values()) | ||
| if self.document.document_id not in values: | ||
| return _ScalarResult(None) | ||
| if self.document.workspace_id not in values: | ||
| return _ScalarResult(None) | ||
|
|
||
| # A missing organization predicate reproduces the vulnerable behavior: | ||
| # a document from another tenant is still returned solely because both | ||
| # principals supplied the same workspace identifier. | ||
| if "workspace_documents.organization_id" not in rendered_scope: | ||
| return _ScalarResult(self.document) | ||
|
|
||
| if self.document.organization_id is None: | ||
| organization_matches = "IS NULL" in rendered_scope.upper() | ||
| else: | ||
| organization_matches = self.document.organization_id in values | ||
| return _ScalarResult(self.document if organization_matches else None) | ||
|
|
||
|
|
||
| def _auth_context(organization_id: str | None) -> AuthContext: | ||
| return AuthContext( | ||
| user_id="member-a", | ||
| role="member", | ||
| organization_id=organization_id, | ||
| group_ids=(), | ||
| workspace_id="workspace-shared-identifier", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_workspace_document_lookup_rejects_cross_organization_idor() -> None: | ||
| """A reused workspace identifier must not cross the tenant boundary.""" | ||
|
|
||
| document = Document( | ||
| document_id="doc-org-b", | ||
| workspace_id="workspace-shared-identifier", | ||
| organization_id="org-b", | ||
| document_name="private.md", | ||
| document_type="text/markdown", | ||
| document_content="tenant B evidence", | ||
| document_status="uploaded", | ||
| ) | ||
| session = _OrganizationAwareSession(document) | ||
|
|
||
| with pytest.raises(HTTPException) as exc_info: | ||
| await _get_workspace_document(session, _auth_context("org-a"), document.document_id) # type: ignore[arg-type] | ||
|
|
||
| assert exc_info.value.status_code == 404 | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_workspace_document_lookup_preserves_same_organization_collaboration() -> None: | ||
| """Workspace members in the owning organization retain shared-document access.""" | ||
|
|
||
| document = Document( | ||
| document_id="doc-org-a", | ||
| workspace_id="workspace-shared-identifier", | ||
| organization_id="org-a", | ||
| document_name="shared.md", | ||
| document_type="text/markdown", | ||
| document_content="shared tenant evidence", | ||
| document_status="uploaded", | ||
| ) | ||
| session = _OrganizationAwareSession(document) | ||
|
|
||
| resolved = await _get_workspace_document( | ||
| session, # type: ignore[arg-type] | ||
| _auth_context("org-a"), | ||
| document.document_id, | ||
| ) | ||
|
|
||
| assert resolved is document | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_personal_workspace_document_lookup_rejects_organization_document() -> None: | ||
| """Personal-scope sessions cannot read organization-owned workspace documents.""" | ||
|
|
||
| document = Document( | ||
| document_id="doc-org-owned", | ||
| workspace_id="workspace-shared-identifier", | ||
| organization_id="org-a", | ||
| document_name="org.md", | ||
| document_type="text/markdown", | ||
| document_content="organization evidence", | ||
| document_status="uploaded", | ||
| ) | ||
| session = _OrganizationAwareSession(document) | ||
|
|
||
| with pytest.raises(HTTPException) as exc_info: | ||
| await _get_workspace_document(session, _auth_context(None), document.document_id) # type: ignore[arg-type] | ||
|
|
||
| assert exc_info.value.status_code == 404 | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.