Skip to content

Fix getInScopeFindings regression introduced by Pydantic refactor#323

Open
NoodlesNZ wants to merge 1 commit into
OWASP:masterfrom
NoodlesNZ:fix-getinscopefindings
Open

Fix getInScopeFindings regression introduced by Pydantic refactor#323
NoodlesNZ wants to merge 1 commit into
OWASP:masterfrom
NoodlesNZ:fix-getinscopefindings

Conversation

@NoodlesNZ
Copy link
Copy Markdown
Contributor

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, where Finding.target held an Element object reference.

The Pydantic refactor (PR #320) changed Finding.target to a str (the element's name). This silently broke getInScopeFindings, the inner loop was now doing:

  getattr("Web Server", "inScope", False)  # always False

The result: getInScopeFindings returned [] 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:

  • Non-element input returns []
  • Out-of-scope element returns []
  • In-scope element with one finding returns it
  • In-scope element with multiple findings returns all of them
  • In-scope element with no findings returns []
  • Findings on one element do not appear on a different element (regression guard for Threats seem to "come through" to inScope = False assets #310)
  • Out-of-scope element is unaffected by findings on a preceding in-scope element

@NoodlesNZ NoodlesNZ requested a review from izar as a code owner April 15, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Threats seem to "come through" to inScope = False assets

1 participant