Skip to content

Apply object-level permission check to finding duplicate API actions#14866

Open
Maffooch wants to merge 3 commits into
bugfixfrom
fix/finding-action-authz
Open

Apply object-level permission check to finding duplicate API actions#14866
Maffooch wants to merge 3 commits into
bugfixfrom
fix/finding-action-authz

Conversation

@Maffooch
Copy link
Copy Markdown
Contributor

Summary

  • FindingViewSet.reset_finding_duplicate_status (POST /api/v2/findings/{id}/duplicate/reset/) and FindingViewSet.set_finding_as_original (POST /api/v2/findings/{id}/original/{new_fid}/) never called self.get_object(). Because the related-object permission class UserHasFindingRelatedObjectPermission only enforces the per-finding check in has_object_permission (its has_permission always returns True), DRF skipped the check entirely on these two actions. Sibling actions like close, verify, and remove_tags already call self.get_object() at the top.
  • Added self.get_object() at the top of both action bodies so the existing object-level permission flow runs. No other behavior changes.
  • Added regression tests in unittests/test_rest_framework.py (FindingActionAuthzTest) covering admin happy paths and a non-member user on both endpoints, including a state-preservation check on the unauthorized attempt.

Test plan

  • python manage.py test unittests.test_rest_framework.FindingActionAuthzTest
  • python manage.py test unittests.test_rest_framework.FindingsTest.test_duplicate (existing happy path still passes)
  • python manage.py check
  • ruff check . --fix

`FindingViewSet.reset_finding_duplicate_status` and
`FindingViewSet.set_finding_as_original` were never calling
`self.get_object()`, so DRF never invoked
`UserHasFindingRelatedObjectPermission.has_object_permission`. The
`has_permission` method on that class always returns `True`, so the
per-finding check was effectively skipped. Sibling actions like `close`,
`verify`, and `remove_tags` already call `self.get_object()` at the top.

Adds `self.get_object()` at the top of both action bodies and regression
tests in `unittests/test_rest_framework.py` (`FindingActionAuthzTest`).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Maffooch and others added 2 commits May 13, 2026 14:58
The existing assertion documented the prior bypass behavior (Reader
reaching the internal helper and getting 400). With the object-level
permission check now running on these actions, a Reader is denied
upfront with 403.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The sibling `RequestResponsePairsAuthzTest` already uses
`@versioned_fixtures` so the suite picks up `dojo_testdata_locations.json`
when V3_FEATURE_LOCATIONS is enabled. Matching that decorator avoids
the Endpoint-deprecation fixture-load error in the V3 CI variant.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants