Skip to content

fix(metrics): paginate Engineer Metrics' Detail Breakdown and order it by severity - #17123

Merged
Maffooch merged 1 commit into
DefectDojo:devfrom
skywalke34:fix/engineer-metrics-paginate-details
Dec 3, 2026
Merged

Maffooch merged 1 commit into
DefectDojo:devfrom
skywalke34:fix/engineer-metrics-paginate-details

Conversation

@skywalke34

Copy link
Copy Markdown
Contributor

Description

Engineer Metrics (/metrics/engineer/<id>) renders its Detail Breakdown with every open finding the engineer reported, on one page. view_engineer builds an in-memory list of all of them, sorts it in Python, and the template renders every row. On a demo instance with 58k findings:

Before After
Detail rows rendered 34,527 25 (page 1 of 1,382)
HTML size 17.6 MB 116 KB
Server time (3 runs, warm) 7.9 – 8.2 s 2.2 – 2.5 s
Page height 3,039,640 px 6,287 px

It also sorted on the severity name, so the order was Critical, High, Info, Low, Medium: Info findings came before Low and Medium.

The fix pages the queryset with the existing get_page_items helper and dojo/paging_snippet.html (25 per page, details prefix, page-size picker), ordered by numerical_severity, newest first, with id as a stable tiebreak. Rows are rendered from the findings, with the same seven columns and values: Days Open uses Finding.age, which equals the old date.today() - f.date for open findings. The remaining ~2.4 s is the page's other charts and counters, which this PR doesn't touch.

Before: High jumps to Info at row 2,401 of 34,527 After: 25 rows plus paging
before after

Test results

  • New unittests/test_view_engineer_details_paging.py (3 tests). All 3 fail on current dev, where details is a plain list, and pass with this change:
    • The first page holds 25 rows, both in the context and in the rendered table.
    • detailspage=2 returns the next, non-overlapping rows.
    • Rows follow severity rank.
  • Existing metrics suites still pass, including test_view_engineer_metrics: 24 tests OK in total, 2 pre-existing skips.
  • Live checks: the last page (detailspage=1382) and an invalid page (detailspage=abc) both return 200.
  • ruff check (0.16.10) passes.

Notes

Documentation

None needed (bug fix).

Checklist

  • Rebased against the latest dev.
  • Submitted against the dev branch.
  • Meaningful PR name.
  • Ruff compliant.
  • Python 3.13 compliant.
  • New feature documentation: n/a, bug fix.
  • Migrations: n/a, no model changes.
  • Unit tests added.
  • Labels and milestone applied.

Generated with Claude Code under the direction of T. Walker (skywalke34) - DefectDojo

…t by severity

view_engineer built the Detail Breakdown as an in-memory list of every open
finding the engineer reported and rendered all of it: on a 58k-finding
instance that is 34,527 rows, a 17.6 MB page and ~8 s per request. It also
sorted by the severity *name*, so Info came before Low and Medium.

Page the queryset with get_page_items (25 per page, `details` prefix, the
shared paging snippet with a page-size picker) and order it by
numerical_severity, newest first, with id as a stable tiebreak. The same
page now renders in ~2.4 s at 116 KB.

Authored by T. Walker - DefectDojo
@skywalke34 skywalke34 added this to the 3.6.0 milestone Dec 1, 2026
@skywalke34 skywalke34 added bugfix performance performance improvement or bug report labels Dec 1, 2026
@dryrunsecurity

dryrunsecurity Bot commented Dec 1, 2026

Copy link
Copy Markdown

DryRun Security

This pull request contains two critical findings where the user 'skywalke34' modified sensitive codepaths in 'dojo/templates/dojo/view_engineer.html' and 'dojo/metrics/views.py' without being on the allowed authors list.

🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/view_engineer.html (drs_3dd8cb5a)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/view_engineer.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'skywalke34' (commit d2a58ac) who is not in the allowed authors list.
🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/metrics/views.py (drs_a94ebad5)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/metrics/views.py' matches configured sensitive codepath pattern 'dojo/metrics/*.py' and was modified by 'skywalke34' (commit d2a58ac) who is not in the allowed authors list.

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.

@Maffooch Maffooch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review: #17123 fix(metrics): paginate Engineer Metrics' Detail Breakdown and order it by severity

Verdict: approve-with-nits
Head SHA reviewed: d2a58ac
Profile: code change (view + template + new unit test)
Base / milestone: dev, 3.6.0 (correct)

Gates

  • ruff 0.16.10: all checks passed. Removing import operator leaves no stale reference, and date is still used elsewhere.
  • CI: 40 of 40 pass.
  • No model change. The query-count performance script does not cover this view.

New test vs base

  • unittests.test_view_engineer_details_paging on the PR head: 3 tests OK.
  • With dojo/metrics/views.py and view_engineer.html reverted to origin/dev: all 3 error ('list' object has no attribute 'paginator', and similar).

Break attempts

  1. Hostile page params. detailspage=abc, 99999 and -1 all return 200. detailspage_size=abc returns 500 (ValueError: invalid literal for int()), detailspage_size=0 returns 500 (ZeroDivisionError), and detailspage_size=-5 raises EmptyPage. On dev this page ignores those params and returns 200. The root cause is the shared helper dojo/utils.py:912 (get_page_items_and_count passes the raw string to Paginator). It reproduces on dev on every paginated page: /metrics/engineer?page_size=abc returns 500, /metrics/engineer?page_size=0 returns 500, and /finding/open?page_size=abc returns 500. Follow-up (pre-existing in the helper, not introduced by this PR's lines).
  2. N+1 / scale. Query count for the whole page with page size 25 vs page size 100: 48 vs 48 (on dev: 47). open_findings already has select_related("test__engagement__product__prod_type", "reporter"), so rows add no queries. Live on a local stack with 120 open findings: 25 rows, Showing entries 1 to 25 of 120, and the pager links work. No break.
  3. Severity order with real saves. Live data created through Finding.objects.create, so save() keeps numerical_severity in sync: Critical rows come first. With fixture rows included, the order looked like Critical, High, Low, High, ... because dojo_testdata.json loads findings with numerical_severity out of sync with severity. That is a fixture artifact, not a product bug. Ordering by numerical_severity is the same convention used in dojo/metrics/views.py:310 and dojo/templatetags/display_tags.py:1005. No break.
  4. Value equivalence. The Days Open column moves from (date.today() - f.date).days to Finding.age. For open findings _age uses get_current_date() - date and clamps to max(0, ...) (dojo/finding/models.py:1170-1185). It differs only for future-dated findings, which now show 0 instead of a negative number. That is better, not a regression. Accepted/Active still reads finding.risk_accepted. No break.
  5. Authorization. The view's request.user.is_superuser or username match gate is unchanged. A different non-superuser requesting /metrics/engineer/<admin id> is refused (I saw 400 in my run, not 2xx). The details queryset is still built from get_authorized_findings("view"). No break.
  6. Interaction with #17124 (the same views.py). No merge conflict. Combined tree: 35 tests OK. No break.

Blocking

None.

Nice-to-haves

  • Follow-up issue (not for this PR): get_page_items_and_count (dojo/utils.py:912-918) should coerce page_size to a positive int with a fallback. Today any ?<prefix>page_size=abc or =0 returns 500 on every paginated page. This PR adds one more page that exposes it.
  • unittests/test_view_engineer_details_paging.py test_rows_follow_severity_rank filters to its own rows because of the fixture mismatch. The comment explains this, which is fine.

Verified hands-on

Tests on the PR head and with the fix reverted. My edge-case test on the PR and on dev. Live engineer page on the combined tree. The page_size 500 reproduced on dev.

Statically only

Finding.age semantics.

Could not reproduce

The 58k-finding timings in the description. I only checked that the query count does not grow with page size.

@Maffooch
Maffooch added this pull request to the merge queue Dec 3, 2026
Merged via the queue into DefectDojo:dev with commit 705b2f3 Dec 3, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix performance performance improvement or bug report ui unittests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants