Skip to content

fix: endpoints not removable from finding via Edit Finding form#14460

Open
valentijnscholten wants to merge 3 commits intoDefectDojo:bugfixfrom
valentijnscholten:fix/endpoint-removal-edit-finding
Open

fix: endpoints not removable from finding via Edit Finding form#14460
valentijnscholten wants to merge 3 commits intoDefectDojo:bugfixfrom
valentijnscholten:fix/endpoint-removal-edit-finding

Conversation

@valentijnscholten
Copy link
Member

@valentijnscholten valentijnscholten commented Mar 7, 2026

Summary

  • Fix FindingForm not pre-selecting existing endpoints in the Edit Finding form: endpoints is listed in Meta.exclude, so Django does not auto-populate it from the model instance — added an explicit self.fields["endpoints"].initial = self.instance.endpoints.all() for the non-V3 path (same pattern already used for the V3/Locations path)
  • Fix add_locations() merging the submitted endpoint selection with the pre-existing set (| finding.endpoints.all()), which made it impossible to remove an endpoint by deselecting it — the submitted queryset now replaces the existing set rather than being unioned with it
  • Both bugs were introduced in the locations refactor (PR locations: everything else #14198)
  • Add unit tests covering add, keep, remove, and switch endpoint scenarios for both add_locations() directly and the EditFinding view
image

Fixes #14454

Two bugs introduced in the locations refactor (PR DefectDojo#14198):

1. FindingForm did not set `endpoints.initial` for the non-V3 path,
   because `endpoints` is in Meta.exclude and Django won't auto-populate
   excluded fields from the model instance. Added explicit initial
   assignment so existing endpoints are pre-selected in the edit form.

2. add_locations() merged the submitted endpoint selection with the
   pre-existing set (| finding.endpoints.all()), making it impossible
   to remove an endpoint by deselecting it. Removed the union with the
   existing set so the submitted selection replaces the current one.

Adds unit tests covering add, keep, remove, and switch scenarios for
both add_locations() directly and the EditFinding view.
@valentijnscholten valentijnscholten added this to the 2.56.1 milestone Mar 7, 2026
@valentijnscholten valentijnscholten linked an issue Mar 7, 2026 that may be closed by this pull request
3 tasks
The previous fix applied replace semantics unconditionally, breaking the
add_finding_from_template flow which copies template endpoints onto the
finding before calling add_locations().

Replace is now opt-in via a keyword argument (replace=False by default).
Only EditFinding passes replace=True; all other callers (add from template,
promote to finding, add finding) keep the original union behaviour so that
pre-populated endpoints are not wiped by an empty form submission.

Unit tests updated to pass replace=True when testing the remove/replace
scenarios that are specific to the EditFinding path.
@valentijnscholten valentijnscholten marked this pull request as ready for review March 8, 2026 10:30
@Maffooch Maffooch modified the milestones: 2.56.1, 2.56.2 Mar 9, 2026
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.

Can't Remove Vulnerable Endpoints / Systems

2 participants