Skip to content

Commit

Permalink
fix: add PURLs in SARIF report (#2254)
Browse files Browse the repository at this point in the history
Signed-off-by: George Liontos <[email protected]>
  • Loading branch information
GeorgeLS authored Dec 4, 2024
1 parent 40a948d commit 851a5e0
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
"bomFormat": "CycloneDX",
"specVersion": "1.6",
"serialNumber": "urn:uuid:7295371c-8562-415c-be23-210d114e68bc",
"serialNumber": "urn:uuid:7fd309b5-5ffd-4d2f-9b24-b040c0bb5af7",
"version": 1,
"metadata": {
"timestamp": "2024-06-14T16:07:19-04:00",
"timestamp": "2024-12-04T15:30:43+02:00",
"tools": {
"components": [
{
Expand Down Expand Up @@ -52,7 +52,7 @@
]
},
{
"bom-ref": "7bb53d560434bc7f",
"bom-ref": "pkg:deb/[email protected]?package-id=7bb53d560434bc7f",
"type": "library",
"name": "package-2",
"version": "2.2.2",
Expand All @@ -69,6 +69,7 @@
}
],
"cpe": "cpe:2.3:a:anchore:engine:2.2.2:*:*:python:*:*:*:*",
"purl": "pkg:deb/[email protected]",
"properties": [
{
"name": "syft:package:type",
Expand All @@ -83,7 +84,7 @@
],
"vulnerabilities": [
{
"bom-ref": "urn:uuid:4287f379-8a42-49f0-8abc-b618cfbec513",
"bom-ref": "urn:uuid:a4b38bae-8a6e-4dd2-bdea-53e9cf590c12",
"id": "CVE-1999-0001",
"source": {},
"references": [
Expand All @@ -109,7 +110,7 @@
]
},
{
"bom-ref": "urn:uuid:afc64b43-24cb-4f55-a948-dfd9c6920061",
"bom-ref": "urn:uuid:829dc942-6d41-4d7d-ad5d-41c9b6b12b62",
"id": "CVE-1999-0002",
"source": {},
"references": [
Expand All @@ -130,7 +131,7 @@
"advisories": [],
"affects": [
{
"ref": "7bb53d560434bc7f"
"ref": "pkg:deb/[email protected]?package-id=7bb53d560434bc7f"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
"bomFormat": "CycloneDX",
"specVersion": "1.6",
"serialNumber": "urn:uuid:d5ea5aa8-ad1d-42c9-aecd-2268354ba41e",
"serialNumber": "urn:uuid:596cd775-e2a5-4932-a807-d1abfe4d804c",
"version": 1,
"metadata": {
"timestamp": "2024-06-14T16:07:15-04:00",
"timestamp": "2024-12-04T15:30:43+02:00",
"tools": {
"components": [
{
Expand Down Expand Up @@ -52,7 +52,7 @@
]
},
{
"bom-ref": "7bb53d560434bc7f",
"bom-ref": "pkg:deb/[email protected]?package-id=7bb53d560434bc7f",
"type": "library",
"name": "package-2",
"version": "2.2.2",
Expand All @@ -69,6 +69,7 @@
}
],
"cpe": "cpe:2.3:a:anchore:engine:2.2.2:*:*:python:*:*:*:*",
"purl": "pkg:deb/[email protected]",
"properties": [
{
"name": "syft:package:type",
Expand All @@ -83,7 +84,7 @@
],
"vulnerabilities": [
{
"bom-ref": "urn:uuid:a0e2f18d-c2d0-4099-ba11-20fdb4745a19",
"bom-ref": "urn:uuid:2fe19024-858a-4864-9a9b-b52f105e992c",
"id": "CVE-1999-0001",
"source": {},
"references": [
Expand All @@ -109,7 +110,7 @@
]
},
{
"bom-ref": "urn:uuid:3c0d9460-1919-43aa-ae5a-d60f269bac64",
"bom-ref": "urn:uuid:1082956b-2ee6-48e4-9d92-183d492a3be8",
"id": "CVE-1999-0002",
"source": {},
"references": [
Expand All @@ -130,7 +131,7 @@
"advisories": [],
"affects": [
{
"ref": "7bb53d560434bc7f"
"ref": "pkg:deb/[email protected]?package-id=7bb53d560434bc7f"
}
]
}
Expand Down
1 change: 1 addition & 0 deletions grype/presenter/internal/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func generatePackages(t *testing.T) []syftPkg.Package {
Name: "package-2",
Version: "2.2.2",
Type: syftPkg.DebPkg,
PURL: "pkg:deb/[email protected]",
Locations: file.NewLocationSet(file.NewVirtualLocation("/foo/bar/somefile-2.txt", "somefile-2.txt")),
CPEs: []cpe.CPE{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"cpes": [
"cpe:2.3:a:anchore:engine:2.2.2:*:*:python:*:*:*:*"
],
"purl": "",
"purl": "pkg:deb/[email protected]",
"upstreams": []
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"cpes": [
"cpe:2.3:a:anchore:engine:2.2.2:*:*:python:*:*:*:*"
],
"purl": "",
"purl": "pkg:deb/[email protected]",
"upstreams": []
}
}
Expand Down
10 changes: 8 additions & 2 deletions grype/presenter/sarif/presenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (pres *Presenter) sarifRules() (out []*sarif.ReportingDescriptor) {
}
}

out = append(out, &sarif.ReportingDescriptor{
descriptor := sarif.ReportingDescriptor{
ID: ruleID,
Name: sp(ruleName(m)),
HelpURI: sp("https://github.com/anchore/grype"),
Expand All @@ -122,7 +122,13 @@ func (pres *Presenter) sarifRules() (out []*sarif.ReportingDescriptor) {
// https://docs.github.com/en/code-security/code-scanning/integrating-with-code-scanning/sarif-support-for-code-scanning#reportingdescriptor-object
"security-severity": pres.securitySeverityValue(m),
},
})
}

if len(m.Package.PURL) != 0 {
descriptor.Properties["purls"] = []string{m.Package.PURL}
}

out = append(out, &descriptor)
}
}
return out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"markdown": "**Vulnerability CVE-1999-0002**\n| Severity | Package | Version | Fix Version | Type | Location | Data Namespace | Link |\n| --- | --- | --- | --- | --- | --- | --- | --- |\n| critical | package-2 | 2.2.2 | | deb | /some/path/somefile-2.txt | source-2 | CVE-1999-0002 |\n"
},
"properties": {
"purls": [
"pkg:deb/[email protected]"
],
"security-severity": "1.0"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
"markdown": "**Vulnerability CVE-1999-0002**\n| Severity | Package | Version | Fix Version | Type | Location | Data Namespace | Link |\n| --- | --- | --- | --- | --- | --- | --- | --- |\n| critical | package-2 | 2.2.2 | | deb | somefile-2.txt | source-2 | CVE-1999-0002 |\n"
},
"properties": {
"purls": [
"pkg:deb/[email protected]"
],
"security-severity": "1.0"
}
}
Expand Down

0 comments on commit 851a5e0

Please sign in to comment.