Skip to content

Commit b849808

Browse files
committed
add severity count
1 parent f6df334 commit b849808

19 files changed

+650013
-117
lines changed

internal/output/html.go

+155-96
Large diffs are not rendered by default.

internal/output/html/package_table_template.html

+8-4
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,19 @@
1818
<td>{{ $element.Ecosystem }}</td>
1919
<td>{{ $element.InstalledVersion }}</td>
2020
<td {{ if eq $element.FixedVersion "No fix available" }} class="warning" {{ end }}>{{ $element.FixedVersion }}</td>
21-
<td>{{ len $element.CalledVulns }}</td>
21+
<td>{{ printSeverityCountShort $element.HTMLVulnCount }}</td>
2222
</tr>
2323
<tr>
2424
<td colspan="100%">
2525
<div id="vuln-details-{{ $element.Name }}-{{ $rowIndex }}-{{ $randomIndex }}" class="vuln-details">
26-
<p>Vulnerability:</p>
26+
<p>Source: {{ $element.Source }}
27+
<p>Vulnerabilities:</p>
2728
{{ range $index, $vuln := $element.CalledVulns }}
28-
<p><a href="https://osv.dev/{{ $vuln.Summary.Id }}">{{ $vuln.Summary.Id }}</a>
29-
{{$vuln.Summary.FixedVersion}}(Fixed Version) {{$vuln.Summary.Severity}} </p>
29+
{{ if eq $element.FixedVersion "No fix available" }}
30+
<p><a href="https://osv.dev/{{ $vuln.Summary.Id }}">{{ $vuln.Summary.Id }}</a> ({{$vuln.Summary.SeverityRating}}) has no fix available</p>
31+
{{ else }}
32+
<p><a href="https://osv.dev/{{ $vuln.Summary.Id }}">{{ $vuln.Summary.Id }}</a> ({{$vuln.Summary.SeverityRating}}) has a fixed version at {{$vuln.Summary.FixedVersion}}(Fixed Version)</p>
33+
{{ end }}
3034
{{ end }}
3135
</div>
3236
</td>

internal/output/html/report_template.html

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
<head>
55
<title>Vulnerability Scan Report</title>
6+
<link rel="icon" href="https://google.github.io/osv.dev/assets/icon.png" type="image/x-icon">
67
<style>
78
body {
89
font-family: sans-serif;
@@ -216,7 +217,7 @@
216217
<h1>Vulnerability Scan Report</h1>
217218
</header>
218219
<h2>Scanning Results</h2>
219-
<p>Total {{ .TotalCount }} vulnerabilities found.</p>
220+
<p>Total {{ .HTMLVulnCount.Called }} vulnerabilities found ({{ .HTMLVulnCount.Fixed }} have fix available), {{ printSeverityCount .HTMLVulnCount}}.</p>
220221
<div id="tab-switch">
221222
<button id="package-button" class="tab-switch-button tab-switch-button-selected"
222223
onclick="openTab('package')">Package View</button>
@@ -232,10 +233,10 @@ <h3>Vulnerable Package Summary</h3>
232233
{{ range .EcosystemResults }}
233234
<div class="ecosystem">
234235
<h2>{{ .Ecosystem }}</h2>
235-
<div class="artifact-section">
236-
{{ range .Artifacts }}
236+
<div class="source-section">
237+
{{ range .Sources }}
237238
<h3>Source: {{ .Ecosystem }}: {{ .Source }}</h3>
238-
<p>Found {{ index .PackageCount 0 }} package(s) with issues, {{ index .VulnCount 0 }} known
239+
<p>Found {{ index .PackageCount 0 }} package(s) with issues, {{ .HTMLVulnCount.Called }} known
239240
vulnerabilities found.</p>
240241

241242
{{template "vuln_view_template.html" .}}

internal/output/html/vuln_table_template.html

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
<td>{{ $element.Summary.InstalledVersion }}</td>
1616
<td {{ if eq $element.Summary.FixedVersion "No fix available" }} class="warning" {{ end }}>{{
1717
$element.Summary.FixedVersion }}</td>
18-
<td>{{ $element.Summary.Severity }}</td>
18+
<td>{{ $element.Summary.SeverityRating }} {{ if ne $element.Summary.SeverityRating "UNKNOWN" }}({{
19+
$element.Summary.SeverityScore }}){{ end }}</td>
1920
</tr>
2021
<tr>
2122
<td colspan="100%">
2223
<div id="vuln-details-{{ $element.Summary.Id }}-{{ $rowIndex }}-{{ $randomIndex }}" class="vuln-details">
23-
{{ range $detailKey, $detailValue := $element.Detail }}
24-
{{if $detailValue }}
25-
<p>{{ format $detailKey }}: {{ $detailValue }}</p>
26-
{{end}}
24+
{{ range $detailIndex, $info := printImportantDetail $element.Detail}}
25+
<p><strong>{{ $info }}</strong></p>
26+
{{ end }}
27+
{{ range $detailIndex, $info := printVulnDetail $element.Detail}}
28+
<p>{{ $info }}</p>
2729
{{ end }}
2830
</div>
2931
</td>

internal/output/html/vuln_view_template.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<summary>Show/Hide Uncalled vulnerabilities</summary>
77
<div id="uncalled-details-{{ .Source }}">
88
<h4>Uncalled vulnerabilities</h4>
9-
<p>Found {{ index .PackageCount 1 }} package(s) with issues, {{ index .VulnCount 1 }} known vulnerabilities found.
9+
<p>Found {{ index .PackageCount 1 }} package(s) with issues, {{ .HTMLVulnCount.Uncalled }} known vulnerabilities found.
1010
</p>
1111
{{template "vuln_table_template.html" $uncalledVulns }}
1212
</div>

internal/output/table.go

+3-7
Original file line numberDiff line numberDiff line change
@@ -150,26 +150,22 @@ func tableBuilderInner(vulnResult *models.VulnerabilityResults, calledVulns bool
150150

151151
func MaxSeverity(group models.GroupInfo, pkg models.PackageVulns) string {
152152
var maxSeverity float64 = -1
153-
var maxRating string = ""
154153
for _, vulnID := range group.IDs {
155154
var severities []models.Severity
156155
for _, vuln := range pkg.Vulnerabilities {
157156
if vuln.ID == vulnID {
158157
severities = vuln.Severity
159158
}
160159
}
161-
score, rating, _ := severity.CalculateOverallScore(severities)
162-
if score > maxSeverity {
163-
maxSeverity = score
164-
maxRating = rating
165-
}
160+
score, _, _ := severity.CalculateOverallScore(severities)
161+
maxSeverity = max(maxSeverity, score)
166162
}
167163

168164
if maxSeverity < 0 {
169165
return ""
170166
}
171167

172-
return fmt.Sprintf("%s (%.1f)", maxRating, maxSeverity)
168+
return fmt.Sprintf("%.1f", maxSeverity)
173169
}
174170

175171
func licenseTableBuilder(outputTable table.Writer, vulnResult *models.VulnerabilityResults) table.Writer {

internal/utility/severity/severity.go

+16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package severity
22

33
import (
4+
"strconv"
45
"strings"
56

67
"github.com/google/osv-scanner/pkg/models"
@@ -71,3 +72,18 @@ func CalculateOverallScore(severities []models.Severity) (float64, string, error
7172

7273
return maxScore, maxRating, nil
7374
}
75+
76+
func CalculateRating(score string) (string, error) {
77+
// All CSVs' rating methods are identical.
78+
parsedScore, err := strconv.ParseFloat(score, 64)
79+
if err != nil {
80+
return unknownRating, err
81+
}
82+
83+
rating, err := gocvss30.Rating(parsedScore)
84+
if err != nil || rating == "NONE" {
85+
rating = unknownRating
86+
}
87+
88+
return rating, err
89+
}

0 commit comments

Comments
 (0)