Skip to content

bugfix(metrics): closed findings counter always shows 0 when no new findings are imported #14464

Open
vvpoglazov wants to merge 1 commit intoDefectDojo:bugfixfrom
vvpoglazov:bugfix/metrics-closed-findings-end-of-day
Open

bugfix(metrics): closed findings counter always shows 0 when no new findings are imported #14464
vvpoglazov wants to merge 1 commit intoDefectDojo:bugfixfrom
vvpoglazov:bugfix/metrics-closed-findings-end-of-day

Conversation

@vvpoglazov
Copy link
Contributor

The Closed Findings counter on the Product Metrics page shows 0 even when closed findings exist and are correctly displayed when clicking the link.

Metrics page (counter) Findings list (after clicking)
0 Closed Findings 1 finding shown

Root cause: finding_queries() builds end_date from the latest finding discovery date (as midnight 00:00:00) and uses it as the upper bound for mitigated__range. This is semantically incorrect

  • a finding can be closed at any time after discovery, including days or weeks after the last scan. Any finding closed after that midnight cutoff is silently excluded from the counter.

The bug "self-healed" only when a new finding with a later discovery date was imported - making it particularly hard to notice. In environments with stable finding profiles (re-imports without new findings), the counter stayed at 0 permanently.

Related historical issues: #9735, #2187.

Fix: replace end_date with timezone.now() as the upper bound so any finding closed up to the current moment is counted. Applied in both dojo/product/views.py and dojo/metrics/utils.py.

Test results

Added regression tests in unittests/test_product_metrics_closed_count.py:

  • finding closed on the same day as discovery date (after midnight) is counted
  • finding discovered in the past but closed recently is counted
  • all findings closed at any time on the same day are counted

Updated test_closed_findings_filtered_by_mitigated_date in unittests/test_metrics_queries.py to reflect correct behavior: findings closed after the discovery date range but before now() should appear in closed metrics.

Documentation

No documentation changes needed.

Checklist

  • Rebased against latest bugfix
  • Bugfix submitted against bugfix branch
  • Code is ruff compliant
  • Code is Python 3.13 compliant
  • Unit tests added

Unit tests

image

@dryrunsecurity
Copy link

dryrunsecurity bot commented Mar 8, 2026

DryRun Security

🔴 Risk threshold exceeded.

This pull request modifies sensitive code paths (dojo/metrics/utils.py and dojo/product/views.py), and the scanner flagged these edits as sensitive—configure allowed paths and authors in .dryrunsecurity.yaml to manage or suppress these findings.

🔴 Configured Codepaths Edit in dojo/metrics/utils.py (drs_e1cf06e3)
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/product/views.py (drs_4c7d856d)
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.

@vvpoglazov vvpoglazov force-pushed the bugfix/metrics-closed-findings-end-of-day branch 2 times, most recently from a437692 to 179a5ec Compare March 8, 2026 18:13
…ilter

The closed findings counter showed 0 even when closed findings existed.

Root cause: the upper bound for mitigated__range was derived from the latest
finding discovery date (end_date), built as midnight (00:00:00). This made
no semantic sense - a finding can be closed at any time after discovery,
so using the discovery date as the cutoff for mitigated is incorrect.

Fix: replace end_date with timezone.now() as the upper bound so any finding
closed up to the current moment is counted. Applied in both
dojo/product/views.py and dojo/metrics/utils.py.

The bug "self-healed" the next day when a new finding with a later discovery
date was imported - making it particularly hard to notice.

Adds regression tests in unittests/test_product_metrics_closed_count.py.
Updates test_closed_findings_filtered_by_mitigated_date to reflect correct
behavior: findings closed after discovery date range but before now() should
appear in closed metrics.
@vvpoglazov vvpoglazov force-pushed the bugfix/metrics-closed-findings-end-of-day branch from 179a5ec to 1f68169 Compare March 8, 2026 19:09
@valentijnscholten valentijnscholten added this to the 2.56.2 milestone Mar 9, 2026
Copy link
Contributor

@Maffooch Maffooch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this change support a use case of trying to answer the question "how many findings were closed in Q4 2025" ?

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.

3 participants