-
Notifications
You must be signed in to change notification settings - Fork 5.6k
[INFRA-778] fix(security): scope ExportIssuesEndpoint.get to the requesting user's own exports #9707
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
Open
mguptahub
wants to merge
2
commits into
preview
Choose a base branch
from
infra-778/export-history-scope-to-initiator
base: preview
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.
+99
−3
Open
[INFRA-778] fix(security): scope ExportIssuesEndpoint.get to the requesting user's own exports #9707
Changes from all commits
Commits
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
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
90 changes: 90 additions & 0 deletions
90
apps/api/plane/tests/contract/app/test_export_history_scope.py
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,90 @@ | ||
| # Copyright (c) 2023-present Plane Software, Inc. and contributors | ||
| # SPDX-License-Identifier: AGPL-3.0-only | ||
| # See the LICENSE file for details. | ||
|
|
||
| """Regression test for cross-member export-history disclosure. | ||
|
|
||
| Root cause: ExportIssuesEndpoint.get filtered ExporterHistory by | ||
| workspace__slug only, with no initiated_by filter — so any workspace | ||
| ADMIN/MEMBER could list every other member's export history. | ||
| ExporterHistorySerializer includes `url` (a presigned S3 link, 7-day expiry, | ||
| no auth required to use) and `token`. Since an export defaults to the | ||
| initiator's own projects (including fully private ones) when no project list | ||
| is supplied, this let any workspace member read another member's private | ||
| project data by listing exports and using the disclosed url — no crafted | ||
| request needed, no revocation possible once disclosed. | ||
|
|
||
| Fixed by adding initiated_by=request.user to the queryset filter. | ||
| """ | ||
|
|
||
| from uuid import uuid4 | ||
|
|
||
| import pytest | ||
| from rest_framework import status | ||
| from rest_framework.test import APIClient | ||
|
|
||
| from plane.db.models import ExporterHistory, User, WorkspaceMember | ||
|
|
||
| pytestmark = pytest.mark.contract | ||
|
|
||
|
|
||
| def _make_user(prefix): | ||
| unique = uuid4().hex[:8] | ||
| user = User.objects.create(email=f"{prefix}-{unique}@plane.so", username=f"{prefix}_{unique}") | ||
| user.set_password("test-password") | ||
| user.save() | ||
| return user | ||
|
|
||
|
|
||
| def _client_for(user): | ||
| client = APIClient() | ||
| client.force_authenticate(user=user) | ||
| return client | ||
|
|
||
|
|
||
| def _export_url(slug): | ||
| return f"/api/workspaces/{slug}/export-issues/?per_page=10&cursor=10:0:0" | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def other_member(db, workspace): | ||
| """A second, active workspace MEMBER (role 15) — a different user than | ||
| the workspace fixture's own admin/creator.""" | ||
| user = _make_user("other-member") | ||
| WorkspaceMember.objects.create(workspace=workspace, member=user, role=15, is_active=True) | ||
| return user | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def own_export(db, workspace, create_user): | ||
| """An export initiated by create_user (the workspace admin).""" | ||
| return ExporterHistory.objects.create( | ||
| workspace=workspace, | ||
| project=[], | ||
| initiated_by=create_user, | ||
| provider="csv", | ||
| type="issue_exports", | ||
| url="https://example-bucket.s3.amazonaws.com/secret-export.csv?X-Amz-Signature=forged", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.django_db | ||
| class TestExportHistoryScope: | ||
| def test_member_cannot_see_another_members_export(self, workspace, own_export, other_member): | ||
| """other_member did not initiate own_export (create_user's) — must | ||
| not see it, and therefore must never receive its presigned url.""" | ||
| response = _client_for(other_member).get(_export_url(workspace.slug)) | ||
|
|
||
| assert response.status_code == status.HTTP_200_OK, response.data | ||
| result_ids = [str(row["id"]) for row in response.data["results"]] | ||
| assert str(own_export.id) not in result_ids, "a workspace member must not see another member's export history" | ||
|
|
||
| def test_member_can_still_see_their_own_export(self, workspace, create_user, own_export): | ||
| """Positive control: the initiator must still see their own export.""" | ||
| response = _client_for(create_user).get(_export_url(workspace.slug)) | ||
|
|
||
| assert response.status_code == status.HTTP_200_OK, response.data | ||
| result_ids = [str(row["id"]) for row in response.data["results"]] | ||
| assert str(own_export.id) in result_ids | ||
| own_row = next(row for row in response.data["results"] if str(row["id"]) == str(own_export.id)) | ||
| assert own_row["url"] == own_export.url | ||
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.