Skip to content

Commit

Permalink
Change to Package.PURL
Browse files Browse the repository at this point in the history
  • Loading branch information
George Liontos committed Nov 20, 2024
1 parent 24a5022 commit 8d214e8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
16 changes: 1 addition & 15 deletions grype/presenter/sarif/presenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"github.com/anchore/grype/grype/pkg"
"github.com/anchore/grype/grype/presenter/models"
"github.com/anchore/grype/grype/vulnerability"
"github.com/anchore/packageurl-go"
"github.com/anchore/syft/syft/file"
"github.com/anchore/syft/syft/source"
)
Expand Down Expand Up @@ -123,7 +122,7 @@ func (pres *Presenter) sarifRules() (out []*sarif.ReportingDescriptor) {
// For GitHub reportingDescriptor object:
// 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),
"purls": [...]string{deriveBomRef(m.Package)},
"purls": [...]string{m.Package.PURL},
},
})
}
Expand Down Expand Up @@ -476,16 +475,3 @@ func imageShortPathName(s *source.Description) string {
imageName = nonPathChars.ReplaceAllString(imageName, "")
return imageName
}

func deriveBomRef(p pkg.Package) string {
// try and parse the PURL if possible and append syft id to it, to make
// the purl unique in the BOM.
// TODO: In the future we may want to dedupe by PURL and combine components with
// the same PURL while preserving their unique metadata.
if parsedPURL, err := packageurl.FromString(p.PURL); err == nil {
parsedPURL.Qualifiers = append(parsedPURL.Qualifiers, packageurl.Qualifier{Key: "package-id", Value: string(p.ID)})
return parsedPURL.ToString()
}
// fallback is to use strictly the ID if there is no valid pURL
return string(p.ID)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"properties": {
"purls": [
"9baa2db122fea516"
""
],
"security-severity": "4.0"
}
Expand All @@ -46,7 +46,7 @@
},
"properties": {
"purls": [
"7bb53d560434bc7f"
""
],
"security-severity": "1.0"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"properties": {
"purls": [
"9baa2db122fea516"
""
],
"security-severity": "4.0"
}
Expand All @@ -46,7 +46,7 @@
},
"properties": {
"purls": [
"7bb53d560434bc7f"
""
],
"security-severity": "1.0"
}
Expand Down

0 comments on commit 8d214e8

Please sign in to comment.