Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include target value in Sarif template ruleID #991

Merged
merged 2 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "{{ .VulnerabilityID }}/{{ escapeString (toPathUri $result.Target) }}/{{ .PkgName }}/{{ .InstalledVersion }}",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend using toJson from sprig.

Suggested change
"id": "{{ .VulnerabilityID }}/{{ escapeString (toPathUri $result.Target) }}/{{ .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": "{{ $vulnerability.VulnerabilityID }}/{{ escapeString (toPathUri $result.Target) }}/{{ $vulnerability.PkgName }}/{{ $vulnerability.InstalledVersion }}",
"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": "CVE-2019-1549/testdata/fixtures/alpine-310.tar.gz/libcrypto1.1/1.1.1c-r0",
"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": "CVE-2019-1551/testdata/fixtures/alpine-310.tar.gz/libcrypto1.1/1.1.1c-r0",
"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": "CVE-2019-1563/testdata/fixtures/alpine-310.tar.gz/libcrypto1.1/1.1.1c-r0",
"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": "CVE-2019-1547/testdata/fixtures/alpine-310.tar.gz/libcrypto1.1/1.1.1c-r0",
"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": "CVE-2019-1549/testdata/fixtures/alpine-310.tar.gz/libssl1.1/1.1.1c-r0",
"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": "CVE-2019-1551/testdata/fixtures/alpine-310.tar.gz/libssl1.1/1.1.1c-r0",
"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": "CVE-2019-1563/testdata/fixtures/alpine-310.tar.gz/libssl1.1/1.1.1c-r0",
"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": "CVE-2019-1547/testdata/fixtures/alpine-310.tar.gz/libssl1.1/1.1.1c-r0",
"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": "CVE-2019-1549/testdata/fixtures/alpine-310.tar.gz/libcrypto1.1/1.1.1c-r0",
"ruleIndex": 0,
"level": "warning",
"message": {
Expand All @@ -238,7 +238,7 @@
}]
},
{
"ruleId": "CVE-2019-1551/libcrypto1.1/1.1.1c-r0",
"ruleId": "CVE-2019-1551/testdata/fixtures/alpine-310.tar.gz/libcrypto1.1/1.1.1c-r0",
"ruleIndex": 1,
"level": "warning",
"message": {
Expand All @@ -254,7 +254,7 @@
}]
},
{
"ruleId": "CVE-2019-1563/libcrypto1.1/1.1.1c-r0",
"ruleId": "CVE-2019-1563/testdata/fixtures/alpine-310.tar.gz/libcrypto1.1/1.1.1c-r0",
"ruleIndex": 2,
"level": "warning",
"message": {
Expand All @@ -270,7 +270,7 @@
}]
},
{
"ruleId": "CVE-2019-1547/libcrypto1.1/1.1.1c-r0",
"ruleId": "CVE-2019-1547/testdata/fixtures/alpine-310.tar.gz/libcrypto1.1/1.1.1c-r0",
"ruleIndex": 3,
"level": "note",
"message": {
Expand All @@ -286,7 +286,7 @@
}]
},
{
"ruleId": "CVE-2019-1549/libssl1.1/1.1.1c-r0",
"ruleId": "CVE-2019-1549/testdata/fixtures/alpine-310.tar.gz/libssl1.1/1.1.1c-r0",
"ruleIndex": 4,
"level": "warning",
"message": {
Expand All @@ -302,7 +302,7 @@
}]
},
{
"ruleId": "CVE-2019-1551/libssl1.1/1.1.1c-r0",
"ruleId": "CVE-2019-1551/testdata/fixtures/alpine-310.tar.gz/libssl1.1/1.1.1c-r0",
"ruleIndex": 5,
"level": "warning",
"message": {
Expand All @@ -318,7 +318,7 @@
}]
},
{
"ruleId": "CVE-2019-1563/libssl1.1/1.1.1c-r0",
"ruleId": "CVE-2019-1563/testdata/fixtures/alpine-310.tar.gz/libssl1.1/1.1.1c-r0",
"ruleIndex": 6,
"level": "warning",
"message": {
Expand All @@ -334,7 +334,7 @@
}]
},
{
"ruleId": "CVE-2019-1547/libssl1.1/1.1.1c-r0",
"ruleId": "CVE-2019-1547/testdata/fixtures/alpine-310.tar.gz/libssl1.1/1.1.1c-r0",
"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": "CVE-1234-5678/foo/target/alpine-310.tar.gz/foopackage/1.2.3",
"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": "CVE-1234-5678/foo/target/alpine-310.tar.gz/foopackage/1.2.3",
"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": "CVE-1234-5678/rust-app/Cargo.lock/foopackage/1.2.3",
"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": "CVE-1234-5678/rust-app/Cargo.lock/foopackage/1.2.3",
"ruleIndex": 0,
"level": "error",
"message": {
Expand Down