Skip to content

Commit

Permalink
feat(report): set location.message (aquasecurity#3002)
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Andrews <candrews@integralblue.com>
  • Loading branch information
candrews committed Oct 8, 2022
1 parent babd7e7 commit ae018b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/report/sarif.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type sarifData struct {
url string
resultIndex int
artifactLocation string
locationMessage string
message string
cvssScore string
startLine int
Expand Down Expand Up @@ -104,7 +105,7 @@ func (sw *SarifWriter) addSarifResult(data *sarifData) {
WithRuleIndex(data.resultIndex).
WithMessage(sarif.NewTextMessage(data.message)).
WithLevel(toSarifErrorLevel(data.severity)).
WithLocations([]*sarif.Location{sarif.NewLocation().WithPhysicalLocation(location)})
WithLocations([]*sarif.Location{sarif.NewLocation().WithMessage(data.locationMessage).WithPhysicalLocation(location)})
sw.run.AddResult(result)
}

Expand Down Expand Up @@ -148,6 +149,7 @@ func (sw SarifWriter) Write(report types.Report) error {
url: vuln.PrimaryURL,
resourceClass: string(res.Class),
artifactLocation: path,
locationMessage: fmt.Sprintf("%v: package %v@%v", path, vuln.PkgName, vuln.InstalledVersion),
resultIndex: getRuleIndex(vuln.VulnerabilityID, ruleIndexes),
fullDescription: html.EscapeString(fullDescription),
helpText: fmt.Sprintf("Vulnerability %v\nSeverity: %v\nPackage: %v\nFixed Version: %v\nLink: [%v](%v)\n%v",
Expand All @@ -167,6 +169,7 @@ func (sw SarifWriter) Write(report types.Report) error {
url: misconf.PrimaryURL,
resourceClass: string(res.Class),
artifactLocation: target,
locationMessage: target,
startLine: misconf.CauseMetadata.StartLine,
endLine: misconf.CauseMetadata.EndLine,
resultIndex: getRuleIndex(misconf.ID, ruleIndexes),
Expand All @@ -188,6 +191,7 @@ func (sw SarifWriter) Write(report types.Report) error {
url: builtinRulesUrl,
resourceClass: string(res.Class),
artifactLocation: target,
locationMessage: target,
startLine: secret.StartLine,
endLine: secret.EndLine,
resultIndex: getRuleIndex(secret.RuleID, ruleIndexes),
Expand Down
4 changes: 4 additions & 0 deletions pkg/report/sarif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func TestReportWriter_Sarif(t *testing.T) {
Message: sarif.Message{Text: toPtr("Package: foo\nInstalled Version: 1.2.3\nVulnerability CVE-2020-0001\nSeverity: HIGH\nFixed Version: 3.4.5\nLink: [CVE-2020-0001](https://avd.aquasec.com/nvd/cve-2020-0001)")},
Locations: []*sarif.Location{
{
Message: "library/test: package foo@1.2.3",
PhysicalLocation: &sarif.PhysicalLocation{
ArtifactLocation: &sarif.ArtifactLocation{
URI: toPtr("library/test"),
Expand Down Expand Up @@ -149,6 +150,7 @@ func TestReportWriter_Sarif(t *testing.T) {
Message: sarif.Message{Text: toPtr("Artifact: library/test\nType: \nVulnerability KSV001\nSeverity: HIGH\nMessage: Message\nLink: [KSV001](https://avd.aquasec.com/appshield/ksv001)")},
Locations: []*sarif.Location{
{
Message: "library/test",
PhysicalLocation: &sarif.PhysicalLocation{
ArtifactLocation: &sarif.ArtifactLocation{
URI: toPtr("library/test"),
Expand All @@ -171,6 +173,7 @@ func TestReportWriter_Sarif(t *testing.T) {
Message: sarif.Message{Text: toPtr("Artifact: library/test\nType: \nVulnerability KSV002\nSeverity: CRITICAL\nMessage: Message\nLink: [KSV002](https://avd.aquasec.com/appshield/ksv002)")},
Locations: []*sarif.Location{
{
Message: "library/test",
PhysicalLocation: &sarif.PhysicalLocation{
ArtifactLocation: &sarif.ArtifactLocation{
URI: toPtr("library/test"),
Expand Down Expand Up @@ -263,6 +266,7 @@ func TestReportWriter_Sarif(t *testing.T) {
Message: sarif.Message{Text: toPtr("Artifact: library/test\nType: \nSecret AWS Secret Access Key\nSeverity: CRITICAL\nMatch: 'AWS_secret_KEY'=\"****************************************\"")},
Locations: []*sarif.Location{
{
Message: "library/test",
PhysicalLocation: &sarif.PhysicalLocation{
ArtifactLocation: &sarif.ArtifactLocation{
URI: toPtr("library/test"),
Expand Down

0 comments on commit ae018b7

Please sign in to comment.