Skip to content

Commit

Permalink
Handle duplicates in reports via SARIF partial fingerprints
Browse files Browse the repository at this point in the history
  • Loading branch information
rm3l committed Nov 5, 2021
1 parent 8e0398f commit 56040d7
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions sarif/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ type SarifReportRunToolDriverRuleDescription struct {
Text string `json:"text,omitempty"`
}
type SarifReportRunResult struct {
RuleId string `json:"ruleId"`
Level string `json:"level"`
Message SarifReportRunResultMessage `json:"message"`
Locations []SarifReportRunResultLocation `json:"locations,omitempty"`
RuleId string `json:"ruleId"`
Level string `json:"level"`
Message SarifReportRunResultMessage `json:"message"`
Locations []SarifReportRunResultLocation `json:"locations,omitempty"`
PartialFingerprints map[string]string `json:"partialFingerprints,omitempty"`
}
type SarifReportRunResultMessage struct {
Text string `json:"text"`
Expand Down Expand Up @@ -98,6 +99,7 @@ func FromContainerScan(containerScanReport containerscan.ContainerScan) (SarifRe
})
containerImageNameToPathUri := toPathUri(containerScanReport.ImageName)
var rulesMap = map[string]SarifReportRunToolDriverRule{}
var partialFingerPrintsMap = map[string]string{}
//Trivy Vulnerabilities
for _, vulnerability := range containerScanReport.Vulnerabilities {
var level string
Expand Down Expand Up @@ -152,6 +154,11 @@ func FromContainerScan(containerScanReport containerscan.ContainerScan) (SarifRe
},
},
})
sarifRunResult.PartialFingerprints = make(map[string]string)
if _, exists := partialFingerPrintsMap[vulnerability.VulnerabilityId]; !exists {
partialFingerPrintsMap[vulnerability.VulnerabilityId] = vulnerability.VulnerabilityId
sarifRunResult.PartialFingerprints[vulnerability.VulnerabilityId] = vulnerability.VulnerabilityId
}
sarifReportRun.Results = append(sarifReportRun.Results, sarifRunResult)
}

Expand Down Expand Up @@ -209,6 +216,11 @@ func FromContainerScan(containerScanReport containerscan.ContainerScan) (SarifRe
},
},
})
sarifRunResult.PartialFingerprints = make(map[string]string)
if _, exists := partialFingerPrintsMap[bestPracticeViolation.Code]; !exists {
partialFingerPrintsMap[bestPracticeViolation.Code] = bestPracticeViolation.Code
sarifRunResult.PartialFingerprints[bestPracticeViolation.Code] = bestPracticeViolation.Code
}
sarifReportRun.Results = append(sarifReportRun.Results, sarifRunResult)
}
sarifReportRun.Tool.Driver = sarifReportRunDriver
Expand Down

0 comments on commit 56040d7

Please sign in to comment.