fix: handle missing status_finding_non_special prefetch in reimporter#14569
fix: handle missing status_finding_non_special prefetch in reimporter#14569seantechco wants to merge 6 commits intoDefectDojo:bugfixfrom
Conversation
When a finding is created during reimport (no match found) and added to the candidate dictionaries for same-batch matching, it lacks the status_finding_non_special prefetch attribute that is only set by build_candidate_scope_queryset. If a subsequent finding in the same batch matches against this newly-created finding, accessing existing_finding.status_finding_non_special raises AttributeError. Add EndpointManager.get_non_special_endpoint_statuses() that returns the prefetched attribute when available, falling back to an equivalent DB query otherwise. Use it at both access sites: default_reimporter.py (process_matched_mitigated_finding) and endpoint_manager.py (update_endpoint_status). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
This pull request modifies sensitive files (dojo/importers/default_reimporter.py and dojo/importers/endpoint_manager.py), triggering the configured-codepaths analyzer which flags these edits as errors; review carefully or update
🔴 Configured Codepaths Edit in
|
| Vulnerability | Configured Codepaths Edit |
|---|---|
| Description | Sensitive edits detected for this file. Sensitive file paths and allowed authors can be configured in .dryrunsecurity.yaml. |
🔴 Configured Codepaths Edit in dojo/importers/endpoint_manager.py (drs_77f1ef31)
| Vulnerability | Configured Codepaths Edit |
|---|---|
| Description | Sensitive edits detected for this file. Sensitive file paths and allowed authors can be configured in .dryrunsecurity.yaml. |
We've notified @mtesauro.
Comment to provide feedback on these findings.
Report false positive: @dryrunsecurity fp [FINDING ID] [FEEDBACK]
Report low-impact: @dryrunsecurity nit [FINDING ID] [FEEDBACK]
Example: @dryrunsecurity fp drs_90eda195 This code is not user-facing
All finding details can be found in the DryRun Security Dashboard.
|
@seantechco Thanks for the report. Interesting case which is not covered by tests yet. With which parser did you see this problem? And if you happen to have a anonimized sample report to reproduce it with that woudl be great. |
Drop the to_attr Prefetch for status_finding_non_special and instead prefetch all endpoint statuses, filtering non-special ones in Python via EndpointManager.get_non_special_endpoint_statuses(). This avoids AttributeError when a finding created during the same reimport batch (via add_new_finding_to_candidates) is matched by a subsequent finding — such findings were never loaded through the prefetch queryset and lacked the to_attr attribute. See: DefectDojo#14569
Summary
AttributeError: 'Finding' object has no attribute 'status_finding_non_special'during reimport-scanEndpointManager.get_non_special_endpoint_statuses()helper that uses the prefetched attribute when available and falls back to an equivalent DB query otherwisedefault_reimporter.pyandendpoint_manager.pyBug
During reimport, when a scan report contains duplicate findings (same hash_code/unique_id), the first occurrence creates a new finding via
process_finding_that_was_not_matched()and adds it to the candidate dictionaries viaadd_new_finding_to_candidates(). When a subsequent finding in the same batch matches against this newly-created finding,process_matched_mitigated_finding()orupdate_endpoint_status()accessesexisting_finding.status_finding_non_special, which raisesAttributeError.Root Cause
The
status_finding_non_specialattribute is aPrefetchwithto_attrset up inbuild_candidate_scope_queryset()(deduplication.py:306-316). This prefetch is only applied to findings loaded from the database through that queryset. Findings created during the same reimport batch (viasave_no_options()inprocess_finding_that_was_not_matched()) and added to candidate dictionaries never pass through that queryset, so they lack the prefetched attribute.Fix
Added
EndpointManager.get_non_special_endpoint_statuses()as a@staticmethodthat:finding.status_finding_non_specialif the prefetch attribute exists (hasattrcheck)finding.status_finding.exclude(Q(false_positive=True) | Q(out_of_scope=True) | Q(risk_accepted=True)).select_related("endpoint")— the exact same filter logic as thePrefetchdefinitionUpdated both call sites to use this helper:
dojo/importers/default_reimporter.pyline 768 (process_matched_mitigated_finding)dojo/importers/endpoint_manager.pyline 162 (update_endpoint_status)Test plan
AttributeErroronstatus_finding_non_special🤖 Generated with Claude Code