Skip to content

Commit

Permalink
Make sure 'runs.results' field is never 'null' in SARIF report
Browse files Browse the repository at this point in the history
This sets the 'runs.results' field to an empty array in the resulting SARIF
if container scan returned no vulnerabilities or best practices violations.
Otherwise, the SARIF report is considered as invalid by the 'upload-sarif'
GitHub Action.
  • Loading branch information
rm3l committed Jul 2, 2022
1 parent 165284e commit 9d0ad88
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func NewSarifReportFromContainerScanReport(containerScanReport containerscan.Rep
containerImageNameToPathUri := toPathUri(containerScanReport.ImageName)
var rulesMap = map[string]sarif.RunToolDriverRule{}
var partialFingerPrintsMap = map[string]string{}

nbVulns := len(containerScanReport.Vulnerabilities)
nbPracticesViolations := len(containerScanReport.BestPracticeViolations)
sarifReportRun.Results = make([]sarif.RunResult, 0, nbVulns+nbPracticesViolations)
//Trivy Vulnerabilities
for _, vulnerability := range containerScanReport.Vulnerabilities {
var level string
Expand Down Expand Up @@ -161,6 +165,7 @@ func NewSarifReportFromContainerScanReport(containerScanReport containerscan.Rep
}
sarifReportRun.Results = append(sarifReportRun.Results, sarifRunResult)
}

sarifReportRun.Tool.Driver = sarifReportRunDriver
rules := make([]sarif.RunToolDriverRule, 0, len(rulesMap))
for _, rule := range rulesMap {
Expand Down

0 comments on commit 9d0ad88

Please sign in to comment.