Repository navigation
fix(metrics): paginate Engineer Metrics' Detail Breakdown and order it by severity - #17123
Conversation
…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
|
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
|
| 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
left a comment
There was a problem hiding this comment.
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 operatorleaves no stale reference, anddateis 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_pagingon the PR head: 3 tests OK.- With
dojo/metrics/views.pyandview_engineer.htmlreverted toorigin/dev: all 3 error ('list' object has no attribute 'paginator', and similar).
Break attempts
- Hostile page params.
detailspage=abc,99999and-1all return 200.detailspage_size=abcreturns 500 (ValueError: invalid literal for int()),detailspage_size=0returns 500 (ZeroDivisionError), anddetailspage_size=-5raisesEmptyPage. Ondevthis page ignores those params and returns 200. The root cause is the shared helperdojo/utils.py:912(get_page_items_and_countpasses the raw string toPaginator). It reproduces ondevon every paginated page:/metrics/engineer?page_size=abcreturns 500,/metrics/engineer?page_size=0returns 500, and/finding/open?page_size=abcreturns 500. Follow-up (pre-existing in the helper, not introduced by this PR's lines). - N+1 / scale. Query count for the whole page with page size 25 vs page size 100: 48 vs 48 (on
dev: 47).open_findingsalready hasselect_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. - Severity order with real saves. Live data created through
Finding.objects.create, sosave()keepsnumerical_severityin sync: Critical rows come first. With fixture rows included, the order looked likeCritical, High, Low, High, ...becausedojo_testdata.jsonloads findings withnumerical_severityout of sync withseverity. That is a fixture artifact, not a product bug. Ordering bynumerical_severityis the same convention used indojo/metrics/views.py:310anddojo/templatetags/display_tags.py:1005. No break. - Value equivalence. The Days Open column moves from
(date.today() - f.date).daystoFinding.age. For open findings_ageusesget_current_date() - dateand clamps tomax(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 readsfinding.risk_accepted. No break. - Authorization. The view's
request.user.is_superuser or username matchgate 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 fromget_authorized_findings("view"). No break. - 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 coercepage_sizeto a positive int with a fallback. Today any?<prefix>page_size=abcor=0returns 500 on every paginated page. This PR adds one more page that exposes it. unittests/test_view_engineer_details_paging.pytest_rows_follow_severity_rankfilters 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.
Description
Engineer Metrics (
/metrics/engineer/<id>) renders its Detail Breakdown with every open finding the engineer reported, on one page.view_engineerbuilds 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: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_itemshelper anddojo/paging_snippet.html(25 per page,detailsprefix, page-size picker), ordered bynumerical_severity, newest first, withidas a stable tiebreak. Rows are rendered from the findings, with the same seven columns and values: Days Open usesFinding.age, which equals the olddate.today() - f.datefor open findings. The remaining ~2.4 s is the page's other charts and counters, which this PR doesn't touch.Test results
unittests/test_view_engineer_details_paging.py(3 tests). All 3 fail on currentdev, wheredetailsis a plain list, and pass with this change:detailspage=2returns the next, non-overlapping rows.test_view_engineer_metrics: 24 tests OK in total, 2 pre-existing skips.detailspage=1382) and an invalid page (detailspage=abc) both return 200.ruff check(0.16.10) passes.Notes
view_engineer.html(the heading and column labels). The two changes touch different lines and don't conflict.Documentation
None needed (bug fix).
Checklist
dev.devbranch.Generated with Claude Code under the direction of T. Walker (skywalke34) - DefectDojo