From 5b166c1577f1c8f507aabb041641d1a55a38d510 Mon Sep 17 00:00:00 2001 From: Rex P <106129829+another-rex@users.noreply.github.com> Date: Wed, 5 Feb 2025 14:28:23 +1100 Subject: [PATCH] fix: HTML report tinkering (#1561) Made a series of changes to resolve the issues identified in #1528 Hosted an example here: https://another-rex.github.io/TestPages/Vulnerability%20Scan%20Report.html To make it easier to see the changes, when reviewing, use this link: https://github.com/google/osv-scanner/pull/1561/files/bd8d5211e77612b1a0a68a4b00db1d40535fe400..8223593ef84cda34da84a57aecd12d3258ea1463 which select the diffs **Excluding** the first commit (use shift to select multiple commits). That moves the files around which breaks all of git's diffing. No change other than moving the files and reindenting is done in that first commit. HTML: - Move to actual .js and .css file rather than .html files. - Alias and groupid tooltips now put each ID on a new line. - Can now click on the entire filter box to change it, not just on the text part. CSS: - Remove max-height in the inner tables, this was making it impossible to have tooltips that escape the container (at least I haven't figured out how to have both). - Tooltip box sizing is now dynamic with max-width - Tooltips now display upwards instead of downwards - Highlight source path better - Minor refactor to how the search box is laid out - Remove unused css lines. - Make iframe bg color black instead of white to avoid flash banging people. JS: - Remove all style edits in javascript, state changes are made with classes now. (TIL `classList.toggle()` function) - Basic linter pass (e.g. use const on variables, define all variables...etc) - Run showAllVulns() function at page load. --- internal/output/html.go | 21 +- .../output/html/base_image_template.gohtml | 2 +- internal/output/html/filter_template.gohtml | 32 +- .../output/html/package_table_template.gohtml | 28 +- .../output/html/package_view_template.gohtml | 2 +- internal/output/html/report_template.gohtml | 8 +- internal/output/html/script.html | 535 --------------- internal/output/html/script.js | 488 ++++++++++++++ internal/output/html/style.css | 628 ++++++++++++++++++ internal/output/html/style.html | 612 ----------------- .../html/vuln_table_entry_template.gohtml | 47 ++ .../output/html/vuln_table_template.gohtml | 75 +-- 12 files changed, 1223 insertions(+), 1255 deletions(-) delete mode 100644 internal/output/html/script.html create mode 100644 internal/output/html/script.js create mode 100644 internal/output/html/style.css delete mode 100644 internal/output/html/style.html create mode 100644 internal/output/html/vuln_table_entry_template.gohtml diff --git a/internal/output/html.go b/internal/output/html.go index e848a2cc626..09ffe725517 100644 --- a/internal/output/html.go +++ b/internal/output/html.go @@ -35,6 +35,18 @@ func formatRating(rating severity.Rating) string { return strings.ToLower(string(rating)) } +type VulnTableEntryArgument struct { + Element VulnResult + IsHidden bool +} + +func buildVulnTableEntryArgument(element VulnResult, isHidden bool) VulnTableEntryArgument { + return VulnTableEntryArgument{ + IsHidden: isHidden, + Element: element, + } +} + func PrintHTMLResults(vulnResult *models.VulnerabilityResults, outputWriter io.Writer) error { // htmlResult := BuildHTMLResults(vulnResult) result := BuildResults(vulnResult) @@ -48,10 +60,11 @@ func PrintHTMLResults(vulnResult *models.VulnerabilityResults, outputWriter io.W "add": func(a, b int) int { return a + b }, - "getFilteredVulnReasons": getFilteredVulnReasons, - "getBaseImageName": getBaseImageName, - "formatSlice": formatSlice, - "formatLayerCommand": formatLayerCommand, + "getFilteredVulnReasons": getFilteredVulnReasons, + "getBaseImageName": getBaseImageName, + "formatSlice": formatSlice, + "formatLayerCommand": formatLayerCommand, + "buildVulnTableEntryArgument": buildVulnTableEntryArgument, } tmpl := template.Must(template.New("").Funcs(funcMap).ParseFS(templates, TemplateDir)) diff --git a/internal/output/html/base_image_template.gohtml b/internal/output/html/base_image_template.gohtml index a3e2cf5c98a..60d92fa22bd 100644 --- a/internal/output/html/base_image_template.gohtml +++ b/internal/output/html/base_image_template.gohtml @@ -36,7 +36,7 @@
No fix available
- {{ else }} -Partial fixes available
- Upgrading the package will fix {{ $element.VulnCount.FixableCount.Fixed }} out of {{ - $element.VulnCount.AnalysisCount.Regular }} vulnerabilities -No fix available
+ All {{ $element.VulnCount.AnalysisCount.Regular }} vulnerabilities have no fixed version available. + {{ else }} +Partial fixes available
+ Upgrading the package can fix {{ $element.VulnCount.FixableCount.Fixed }} out of {{ + $element.VulnCount.AnalysisCount.Regular }} vulnerabilities. + {{ end }} {{ else }} -Fix available
+Fix available
+ Upgrading the package can fix all {{ $element.VulnCount.FixableCount.Fixed }} vulnerabilities. {{ end }} +