Skip to content

Commit

Permalink
Include target value in Sarif template ruleID (aquasecurity#991)
Browse files Browse the repository at this point in the history
* Include target value in Sarif template ruleID

* Fix format
  • Loading branch information
rahul2393 authored May 13, 2021
1 parent 083c157 commit eaf2da2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
8 changes: 4 additions & 4 deletions contrib/sarif.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"version": "0.15.0",
"rules": [
{{- $t_first := true }}
{{- range . }}
{{- range $result := . }}
{{- $vulnerabilityType := .Type }}
{{- range .Vulnerabilities -}}
{{- if $t_first -}}
Expand All @@ -20,7 +20,7 @@
,
{{- end }}
{
"id": "{{ .VulnerabilityID }}/{{ .PkgName }}/{{ .InstalledVersion }}",
"id": {{ printf "%s: %s-%s %s" $result.Target .PkgName .InstalledVersion .VulnerabilityID | toJson }},
"name": "{{ toSarifRuleName $vulnerabilityType }}",
"shortDescription": {
"text": {{ printf "%v Package: %v" .VulnerabilityID .PkgName | printf "%q" }}
Expand Down Expand Up @@ -57,7 +57,7 @@
},
"results": [
{{- $t_first := true }}
{{- range . }}
{{- range $result := . }}
{{- $filePath := .Target }}
{{- range $index, $vulnerability := .Vulnerabilities -}}
{{- if $t_first -}}
Expand All @@ -66,7 +66,7 @@
,
{{- end }}
{
"ruleId": "{{ $vulnerability.VulnerabilityID }}/{{ $vulnerability.PkgName }}/{{ $vulnerability.InstalledVersion }}",
"ruleId": {{ printf "%s: %s-%s %s" $result.Target .PkgName .InstalledVersion .VulnerabilityID | toJson }},
"ruleIndex": {{ $index }},
"level": "{{ toSarifErrorLevel $vulnerability.Vulnerability.Severity }}",
"message": {
Expand Down
32 changes: 16 additions & 16 deletions integration/testdata/alpine-310.sarif.golden
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"version": "0.15.0",
"rules": [
{
"id": "CVE-2019-1549/libcrypto1.1/1.1.1c-r0",
"id": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libcrypto1.1-1.1.1c-r0 CVE-2019-1549",
"name": "OS Package Vulnerability (Alpine)",
"shortDescription": {
"text": "CVE-2019-1549 Package: libcrypto1.1"
Expand All @@ -37,7 +37,7 @@
}
},
{
"id": "CVE-2019-1551/libcrypto1.1/1.1.1c-r0",
"id": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libcrypto1.1-1.1.1c-r0 CVE-2019-1551",
"name": "OS Package Vulnerability (Alpine)",
"shortDescription": {
"text": "CVE-2019-1551 Package: libcrypto1.1"
Expand All @@ -63,7 +63,7 @@
}
},
{
"id": "CVE-2019-1563/libcrypto1.1/1.1.1c-r0",
"id": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libcrypto1.1-1.1.1c-r0 CVE-2019-1563",
"name": "OS Package Vulnerability (Alpine)",
"shortDescription": {
"text": "CVE-2019-1563 Package: libcrypto1.1"
Expand All @@ -89,7 +89,7 @@
}
},
{
"id": "CVE-2019-1547/libcrypto1.1/1.1.1c-r0",
"id": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libcrypto1.1-1.1.1c-r0 CVE-2019-1547",
"name": "OS Package Vulnerability (Alpine)",
"shortDescription": {
"text": "CVE-2019-1547 Package: libcrypto1.1"
Expand All @@ -115,7 +115,7 @@
}
},
{
"id": "CVE-2019-1549/libssl1.1/1.1.1c-r0",
"id": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libssl1.1-1.1.1c-r0 CVE-2019-1549",
"name": "OS Package Vulnerability (Alpine)",
"shortDescription": {
"text": "CVE-2019-1549 Package: libssl1.1"
Expand All @@ -141,7 +141,7 @@
}
},
{
"id": "CVE-2019-1551/libssl1.1/1.1.1c-r0",
"id": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libssl1.1-1.1.1c-r0 CVE-2019-1551",
"name": "OS Package Vulnerability (Alpine)",
"shortDescription": {
"text": "CVE-2019-1551 Package: libssl1.1"
Expand All @@ -167,7 +167,7 @@
}
},
{
"id": "CVE-2019-1563/libssl1.1/1.1.1c-r0",
"id": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libssl1.1-1.1.1c-r0 CVE-2019-1563",
"name": "OS Package Vulnerability (Alpine)",
"shortDescription": {
"text": "CVE-2019-1563 Package: libssl1.1"
Expand All @@ -193,7 +193,7 @@
}
},
{
"id": "CVE-2019-1547/libssl1.1/1.1.1c-r0",
"id": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libssl1.1-1.1.1c-r0 CVE-2019-1547",
"name": "OS Package Vulnerability (Alpine)",
"shortDescription": {
"text": "CVE-2019-1547 Package: libssl1.1"
Expand Down Expand Up @@ -222,7 +222,7 @@
},
"results": [
{
"ruleId": "CVE-2019-1549/libcrypto1.1/1.1.1c-r0",
"ruleId": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libcrypto1.1-1.1.1c-r0 CVE-2019-1549",
"ruleIndex": 0,
"level": "warning",
"message": {
Expand All @@ -238,7 +238,7 @@
}]
},
{
"ruleId": "CVE-2019-1551/libcrypto1.1/1.1.1c-r0",
"ruleId": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libcrypto1.1-1.1.1c-r0 CVE-2019-1551",
"ruleIndex": 1,
"level": "warning",
"message": {
Expand All @@ -254,7 +254,7 @@
}]
},
{
"ruleId": "CVE-2019-1563/libcrypto1.1/1.1.1c-r0",
"ruleId": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libcrypto1.1-1.1.1c-r0 CVE-2019-1563",
"ruleIndex": 2,
"level": "warning",
"message": {
Expand All @@ -270,7 +270,7 @@
}]
},
{
"ruleId": "CVE-2019-1547/libcrypto1.1/1.1.1c-r0",
"ruleId": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libcrypto1.1-1.1.1c-r0 CVE-2019-1547",
"ruleIndex": 3,
"level": "note",
"message": {
Expand All @@ -286,7 +286,7 @@
}]
},
{
"ruleId": "CVE-2019-1549/libssl1.1/1.1.1c-r0",
"ruleId": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libssl1.1-1.1.1c-r0 CVE-2019-1549",
"ruleIndex": 4,
"level": "warning",
"message": {
Expand All @@ -302,7 +302,7 @@
}]
},
{
"ruleId": "CVE-2019-1551/libssl1.1/1.1.1c-r0",
"ruleId": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libssl1.1-1.1.1c-r0 CVE-2019-1551",
"ruleIndex": 5,
"level": "warning",
"message": {
Expand All @@ -318,7 +318,7 @@
}]
},
{
"ruleId": "CVE-2019-1563/libssl1.1/1.1.1c-r0",
"ruleId": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libssl1.1-1.1.1c-r0 CVE-2019-1563",
"ruleIndex": 6,
"level": "warning",
"message": {
Expand All @@ -334,7 +334,7 @@
}]
},
{
"ruleId": "CVE-2019-1547/libssl1.1/1.1.1c-r0",
"ruleId": "testdata/fixtures/alpine-310.tar.gz (alpine 3.10.2): libssl1.1-1.1.1c-r0 CVE-2019-1547",
"ruleIndex": 7,
"level": "note",
"message": {
Expand Down
8 changes: 4 additions & 4 deletions pkg/report/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ func TestReportWriter_Template_SARIF(t *testing.T) {
"version": "0.15.0",
"rules": [
{
"id": "CVE-1234-5678/foopackage/1.2.3",
"id": "foo/target/alpine-310.tar.gz (alpine 3.10.2): foopackage-1.2.3 CVE-1234-5678",
"name": "Other Vulnerability (Footype)",
"shortDescription": {
"text": "CVE-1234-5678 Package: foopackage"
Expand Down Expand Up @@ -437,7 +437,7 @@ func TestReportWriter_Template_SARIF(t *testing.T) {
},
"results": [
{
"ruleId": "CVE-1234-5678/foopackage/1.2.3",
"ruleId": "foo/target/alpine-310.tar.gz (alpine 3.10.2): foopackage-1.2.3 CVE-1234-5678",
"ruleIndex": 0,
"level": "error",
"message": {
Expand Down Expand Up @@ -493,7 +493,7 @@ func TestReportWriter_Template_SARIF(t *testing.T) {
"version": "0.15.0",
"rules": [
{
"id": "CVE-1234-5678/foopackage/1.2.3",
"id": "rust-app\\Cargo.lock: foopackage-1.2.3 CVE-1234-5678",
"name": "Other Vulnerability (Footype)",
"shortDescription": {
"text": "CVE-1234-5678 Package: foopackage"
Expand Down Expand Up @@ -522,7 +522,7 @@ func TestReportWriter_Template_SARIF(t *testing.T) {
},
"results": [
{
"ruleId": "CVE-1234-5678/foopackage/1.2.3",
"ruleId": "rust-app\\Cargo.lock: foopackage-1.2.3 CVE-1234-5678",
"ruleIndex": 0,
"level": "error",
"message": {
Expand Down

0 comments on commit eaf2da2

Please sign in to comment.