Fix getInScopeFindings regression introduced by Pydantic refactor#323
Open
NoodlesNZ wants to merge 1 commit into
Open
Fix getInScopeFindings regression introduced by Pydantic refactor#323NoodlesNZ wants to merge 1 commit into
NoodlesNZ wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes: #310
Regression introduced by: #320
What broke and why
PR #312 fixed issue #310 by adding
ReportUtils.getInScopeFindings(), which filters threat findings to only those belonging to in-scope elements. The fix worked correctly against the pre-Pydantic codebase, whereFinding.targetheld anElementobject reference.The Pydantic refactor (PR #320) changed
Finding.targetto a str (the element's name). This silently brokegetInScopeFindings, the inner loop was now doing:The result:
getInScopeFindingsreturned [] for every element, including in-scope ones. All threat findings were hidden from advanced_template.md and reveal.md reports.The out-of-scope case appeared to still work (returning []) but only because of the early-return guard at the top of the function, not because the inner loop was correct.
The fix
One-line change in report_util.py: use finding.element (the Element reference, set by Finding.init) instead of finding.target (the name string).
Note on root cause
The original state-bleed described in #310 (findings from one element appearing on another) was caused by a shared class-level list in the old descriptor system. That root cause was independently fixed by the Pydantic refactor, which uses default_factory=list to give each element instance its own findings list. The fix in this PR restores the template-level filtering that was broken as a side effect.
Tests
Seven new tests added to tests/test_report_util.py, covering: