Skip to content
This repository was archived by the owner on May 24, 2025. It is now read-only.

Commit bd899d9

Browse files
authored
fix(#15): Fix invalid SARIF content if container-scan returns no vulnerabilities
This sets the 'runs.results' field to an empty array in the resulting SARIF if container scan returned no vulnerabilities or best practices violations, instead of setting such field to 'null'. Otherwise, the SARIF report is considered as invalid by the 'upload-sarif' GitHub Action.
2 parents 8c083cd + 9d0ad88 commit bd899d9

File tree

2 files changed

+564
-203
lines changed

2 files changed

+564
-203
lines changed

pkg/converter/converter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ func NewSarifReportFromContainerScanReport(containerScanReport containerscan.Rep
3838
containerImageNameToPathUri := toPathUri(containerScanReport.ImageName)
3939
var rulesMap = map[string]sarif.RunToolDriverRule{}
4040
var partialFingerPrintsMap = map[string]string{}
41+
42+
nbVulns := len(containerScanReport.Vulnerabilities)
43+
nbPracticesViolations := len(containerScanReport.BestPracticeViolations)
44+
sarifReportRun.Results = make([]sarif.RunResult, 0, nbVulns+nbPracticesViolations)
4145
//Trivy Vulnerabilities
4246
for _, vulnerability := range containerScanReport.Vulnerabilities {
4347
var level string
@@ -161,6 +165,7 @@ func NewSarifReportFromContainerScanReport(containerScanReport containerscan.Rep
161165
}
162166
sarifReportRun.Results = append(sarifReportRun.Results, sarifRunResult)
163167
}
168+
164169
sarifReportRun.Tool.Driver = sarifReportRunDriver
165170
rules := make([]sarif.RunToolDriverRule, 0, len(rulesMap))
166171
for _, rule := range rulesMap {

0 commit comments

Comments
 (0)