Skip to content

fix(metrics): render Metric Counts tables and critical-asset gauges - #17119

Merged
Maffooch merged 1 commit into
DefectDojo:devfrom
skywalke34:fix/metrics-tabs-and-gauges
Dec 3, 2026
Merged

Maffooch merged 1 commit into
DefectDojo:devfrom
skywalke34:fix/metrics-tabs-and-gauges

Conversation

@skywalke34

@skywalke34 skywalke34 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

Two rendering bugs in dojo/templates/dojo/metrics.html that both date from the Tailwind UI rebuild (#14865).

1. Metric Counts tables are squeezed out of view (Organization Metrics, /metrics/organization and /metrics/organization/<id>).
The template still carried Bootstrap 2's .tabs-left sidebar CSS, including .tabs-left > .nav-tabs { float: left }. .nav-tabs is now a full-width horizontal flex strip, so the "sidebar" became a ~1,165px float. The active pane has .table-responsive (overflow-x: auto), which makes it a block formatting context that is laid out beside the float rather than under it, so the table only gets the leftover width. At a 1440px viewport that is 0px and the tab content disappears entirely; at other widths it renders as a narrow column on the right. The fix removes the dead .tabs-left/right/below rules (keeping the [x-cloak] rule that lived among them) and the now-inert tabs-left class.

Before (1440px) After
before after

2. No gauges render on Critical Asset Metrics (/critical_asset_metrics).
Each gauge container's id was the organization's name plus its pk. The JustGage shim in dojo/static/dojo/js/metrics.js resolves it with document.querySelector('#' + id), which throws SyntaxError whenever the name is not a valid CSS identifier — e.g. it contains &, % or #, or starts with a digit ('#R&D + 100% #110' is not a valid selector). Names with only spaces happen to survive via the getElementById fallback. The uncaught error also aborts the jQuery .each loop, so every gauge on the page stays empty, not just the one with the awkward name. The fix gives each container the id gauge-<pk>.

Before After
before after

Test results

  • New unittests/test_metrics_template.py (2 tests): asserts gauge container ids are safe CSS identifiers (using an organization named R&D + 100% #1) and that the Organization Metrics page no longer carries the floated legacy tab classes. Both tests fail on current dev and pass with this change.
  • Existing metrics suites still pass: unittests.test_metrics_queries, unittests.test_view_engineer_metrics, unittests.test_product_metrics_closed_count — 23 tests, OK (2 pre-existing skips).
  • Verified in a browser at 1440×900: all 8 Metric Counts tabs render at full width (1184px) and switch correctly; both critical-asset gauges draw and the console is clean.
  • ruff check / ruff format --check (0.16.10, ruff.toml) pass on the new test file.

Documentation

None needed (bug fix, no behavior or setting change).

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 bugfix + ui and milestone 3.6.0 applied.

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

Drop the leftover Bootstrap 2 .tabs-left/.tabs-right/.tabs-below rules from
metrics.html. Since the Tailwind rebuild, .nav-tabs is a full-width horizontal
strip; floating it left pushed the active tab's .table-responsive pane (which
establishes its own block formatting context) into the leftover width beside
it -- 0px at a 1440px viewport -- so the Metric Counts tables disappeared on
the Organization Metrics pages.

Give each Critical Asset Metrics gauge an id of gauge-<id> instead of the
organization name. The gauge shim in metrics.js looks the container up with
document.querySelector('#' + id), which throws a SyntaxError for names
containing spaces or characters such as & + % #. The throw also aborts the
jQuery .each loop, so no gauge on the page rendered.

Authored by T. Walker - DefectDojo
@dryrunsecurity

dryrunsecurity Bot commented Dec 1, 2026

Copy link
Copy Markdown

DryRun Security

This pull request contains a critical finding where a sensitive template file was modified by an author not on the allowed list. Although the issue is flagged as failing, it is not currently set to block the merge.

🔴 Configured Sensitive Codepath Modified by Non-Allowed Author in dojo/templates/dojo/metrics.html (drs_08cd5c59)
Vulnerability Configured Sensitive Codepath Modified by Non-Allowed Author
Description File 'dojo/templates/dojo/metrics.html' matches configured sensitive codepath pattern 'dojo/templates/**/*.html' and was modified by 'skywalke34' (commit 793691f) 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.

@skywalke34 skywalke34 added this to the 3.6.0 milestone Dec 1, 2026

@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: #17119 fix(metrics): render Metric Counts tables and critical-asset gauges

Verdict: approve-with-nits (merge after the red required check is re-run green)
Head SHA reviewed: 793691f
Profile: code change (template + new unit test)
Base / milestone: dev, 3.6.0 (the earliest open milestone with a future due date, checked via the milestones API)

Gates

  • ruff 0.16.10 ruff check . on the PR head: all checks passed.
  • No model change, so no migration and no makemigrations gate. No helm/ change.
  • CI: Unit Tests Complete is red only because test-k8s / Kubernetes Deployment (1.34.12, debian) failed with digest-mismatch: error while pulling the chart, followed by release: not found. The 1.35.10 k8s job passed on the same run. The PR changes one template and adds one test, and the skill lists k8s jobs as known flakes. Re-run it. That check is required on dev, so the PR cannot merge until it is green.

New test vs base

  • unittests.test_metrics_template on the PR head: 2 tests OK.
  • With dojo/templates/dojo/metrics.html reverted to origin/dev: both fail. The gauge test fails with 'gauge-4' not found in ['R&amp;D + 100% #14', 'books1', 'ebooks2'] and the tab test with legacy floated-tab class 'tabs-left' still on the page.

Break attempts

  1. Hostile organization names. Created critical orgs named "><script>alert(1)</script> and 123 & co and rendered /critical_product_metrics. Expected escaped output, unique DOM ids, and safe gauge ids. Got 200, no unescaped script, no duplicate ids on the page, gauge ids gauge-4, gauge-5, gauge-1, gauge-2. No break.
  2. Live gauge rendering on base vs PR. In a browser on a local stack with orgs R&D + 100% #1 and 9 Lives: on dev all three gauges are empty and the console shows Uncaught SyntaxError: ... '#9 Lives3' is not a valid selector (this reproduces the bug). On the PR all three gauges draw and the console is clean. No break.
  3. Metric Counts layout and tab switching. At 1440px on dev the tab strip is float: left, 1165px wide, and the active pane is 0px wide (reproduces the bug). On the PR I clicked through all 8 tabs: each pane is 1184px wide and its table renders (450 to 781px). No break.
  4. Narrow viewport. On the PR at 375px (mobile emulation), the document width equals the viewport width, so there is no horizontal page scroll from the tab strip. No break.
  5. Other consumers of the removed CSS or the old id format. Grepped dojo/ for tabs-left, tabs-right, tabs-below and gaugeloop. The only consumer is metrics.html, and .gaugeloop is read only by the inline loop at metrics.html:771, which takes the id from the attribute. The gauge title still comes from name=, so labels are unchanged. The [x-cloak] rule that sat among the deleted rules is kept. No break.
  6. Interaction with the sibling PRs. Merged #17119, #17120, #17122, #17123, #17124 and #17125 onto dev with no conflicts. On the combined tree, all six new tests plus test_metrics_queries, test_view_engineer_metrics and test_product_metrics_closed_count pass: 35 tests, OK, 2 skipped. No break.

Blocking

None in the code. The required check needs a green re-run (see Gates).

Nice-to-haves

  • unittests/test_metrics_template.py:45 checks that the class string is absent. It cannot catch a future CSS rule that floats .nav-tabs again. That is acceptable for a template unit test.

Verified hands-on

Unit tests on the PR head and with the fix reverted. Browser checks on a local stack (dev vs the combined PR tree) of gauge rendering, console errors, the width of every Metric Counts tab at 1440px, and page width at 375px.

Statically only

Whether the gauge JS uses the id anywhere else (dojo/static/dojo/js/metrics.js _ensureCanvas / JustGage).

Could not reproduce

Nothing outstanding. I did not re-run the k8s job myself.

@Maffooch
Maffooch added this pull request to the merge queue Dec 3, 2026
Merged via the queue into DefectDojo:dev with commit ecf9527 Dec 3, 2026
88 of 92 checks passed
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.

4 participants