-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[WEB-8400] fix(security): scope DeployBoardViewSet queryset to the URL workspace/project (GHSA-h4w5-vhxc-265g) #9481
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
web-8400/deploy-board-cross-workspace-idor
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.
+140
−0
Open
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
124 changes: 124 additions & 0 deletions
124
apps/api/plane/tests/contract/app/test_deploy_board_cross_workspace_scope_app.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,124 @@ | ||
| # Copyright (c) 2023-present Plane Software, Inc. and contributors | ||
| # SPDX-License-Identifier: AGPL-3.0-only | ||
| # See the LICENSE file for details. | ||
|
|
||
| """Contract tests for DeployBoardViewSet object scoping. | ||
|
|
||
| Regression coverage for GHSA-h4w5-vhxc-265g. ``DeployBoardViewSet`` defines only | ||
| ``list``/``create``; the routed ``retrieve``/``partial_update``/``destroy`` fall | ||
| through to DRF's ``ModelViewSet`` defaults, which resolve the object via | ||
| ``get_object()`` -> ``get_queryset()``. The base ``get_queryset`` returns | ||
| ``DeployBoard.objects.all()`` (every workspace), and ``ProjectMemberPermission`` | ||
| only checks the URL slug/project_id. So any authenticated user could supply their | ||
| own workspace+project in the URL and a victim board's pk to read/modify/hard-delete | ||
| another workspace's published board. | ||
|
|
||
| The fix scopes ``get_queryset`` to the URL workspace + project, so a foreign pk | ||
| 404s. | ||
| """ | ||
|
|
||
| from uuid import uuid4 | ||
|
|
||
| import pytest | ||
| from rest_framework import status | ||
|
|
||
| from plane.db.models import DeployBoard, Project, ProjectMember, User, Workspace, WorkspaceMember | ||
|
|
||
|
|
||
| def _board_url(slug, project_id, pk): | ||
| return f"/api/workspaces/{slug}/projects/{project_id}/project-deploy-boards/{pk}/" | ||
|
|
||
|
|
||
| def _board_for(workspace, project): | ||
| return DeployBoard.objects.create( | ||
| workspace=workspace, project=project, entity_name="project", entity_identifier=project.id | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def project_a(db, workspace, create_user): | ||
| """The attacker's own project; create_user (session_client) is a member.""" | ||
| project = Project.objects.create( | ||
| name="Attacker Project", identifier="ATK", workspace=workspace, created_by=create_user | ||
| ) | ||
| ProjectMember.objects.create(project=project, member=create_user, workspace=workspace, role=20, is_active=True) | ||
| return project | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def own_board(db, workspace, project_a): | ||
| return _board_for(workspace, project_a) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def sibling_board(db, workspace, create_user): | ||
| """A board for a DIFFERENT project in the SAME workspace as project_a. | ||
|
|
||
| Guards the project predicate specifically: a workspace-slug-only scope would | ||
| still expose this board through project_a's URL. | ||
| """ | ||
| other = Project.objects.create( | ||
| name="Sibling Project", identifier="SIB", workspace=workspace, created_by=create_user | ||
| ) | ||
| return _board_for(workspace, other) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def victim_board(db): | ||
| """A published board in a DIFFERENT workspace the caller has no relation to.""" | ||
| unique = uuid4().hex[:8] | ||
| owner = User.objects.create(email=f"victim-{unique}@plane.so", username=f"victim_{unique}") | ||
| owner.set_password("test-password") | ||
| owner.save() | ||
| ws = Workspace.objects.create(name="Victim WS", slug=f"victim-{unique}", owner=owner) | ||
| WorkspaceMember.objects.create(workspace=ws, member=owner, role=20, is_active=True) | ||
| project = Project.objects.create(name="Victim Project", identifier="VIC", workspace=ws, created_by=owner) | ||
| ProjectMember.objects.create(project=project, member=owner, workspace=ws, role=20, is_active=True) | ||
| return _board_for(ws, project) | ||
|
|
||
|
|
||
| @pytest.mark.contract | ||
| @pytest.mark.django_db | ||
| class TestDeployBoardCrossWorkspaceScope: | ||
| """A caller must not reach another workspace's board via their own URL scope.""" | ||
|
|
||
| def test_cannot_retrieve_foreign_board(self, session_client, workspace, project_a, victim_board): | ||
| response = session_client.get(_board_url(workspace.slug, project_a.id, victim_board.id)) | ||
| assert response.status_code == status.HTTP_404_NOT_FOUND, ( | ||
| f"Got {response.status_code}: {getattr(response, 'data', None)!r}" | ||
| ) | ||
|
|
||
| def test_cannot_destroy_foreign_board(self, session_client, workspace, project_a, victim_board): | ||
| response = session_client.delete(_board_url(workspace.slug, project_a.id, victim_board.id)) | ||
| assert response.status_code == status.HTTP_404_NOT_FOUND, ( | ||
| f"Got {response.status_code}: {getattr(response, 'data', None)!r}" | ||
| ) | ||
| assert DeployBoard.objects.filter(pk=victim_board.id).exists(), "Foreign board was deleted" | ||
|
|
||
| def test_cannot_patch_foreign_board(self, session_client, workspace, project_a, victim_board): | ||
| response = session_client.patch( | ||
| _board_url(workspace.slug, project_a.id, victim_board.id), | ||
| {"is_comments_enabled": True}, | ||
| format="json", | ||
| ) | ||
| assert response.status_code == status.HTTP_404_NOT_FOUND, ( | ||
| f"Got {response.status_code}: {getattr(response, 'data', None)!r}" | ||
| ) | ||
| victim_board.refresh_from_db() | ||
| assert victim_board.is_comments_enabled is False | ||
|
|
||
| def test_cannot_retrieve_same_workspace_other_project_board( | ||
| self, session_client, workspace, project_a, sibling_board | ||
| ): | ||
| """A board in the same workspace but a different project must 404 via project_a's URL.""" | ||
| response = session_client.get(_board_url(workspace.slug, project_a.id, sibling_board.id)) | ||
| assert response.status_code == status.HTTP_404_NOT_FOUND, ( | ||
| f"Got {response.status_code}: {getattr(response, 'data', None)!r}" | ||
| ) | ||
|
|
||
| def test_can_retrieve_own_board(self, session_client, workspace, project_a, own_board): | ||
| """Positive control: a project member may retrieve their own board.""" | ||
| response = session_client.get(_board_url(workspace.slug, project_a.id, own_board.id)) | ||
| assert response.status_code == status.HTTP_200_OK, ( | ||
| f"Got {response.status_code}: {getattr(response, 'data', None)!r}" | ||
| ) | ||
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.