Skip to content

Commit 9cc9d47

Browse files
fix: wrong vuln rating source (#81)
1 parent 2f3d685 commit 9cc9d47

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/snyk/enrich_cyclonedx.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,21 @@ func enrichCycloneDX(cfg *Config, bom *cdx.BOM, logger *zerolog.Logger) *cdx.BOM
204204

205205
if issue.Attributes.Severities != nil {
206206
for _, sev := range *issue.Attributes.Severities {
207-
source := cdx.Source{
208-
Name: "Snyk",
209-
URL: snykVulnerabilityDBWebURL,
207+
var source cdx.Source
208+
if sev.Source != nil {
209+
source = cdx.Source{
210+
Name: *sev.Source,
211+
}
212+
} else {
213+
source = cdx.Source{
214+
Name: "Snyk",
215+
}
210216
}
217+
218+
if source.Name == "Snyk" {
219+
source.URL = snykVulnerabilityDBWebURL
220+
}
221+
211222
if sev.Score != nil {
212223
score := float64(*sev.Score)
213224
rating := cdx.VulnerabilityRating{

lib/snyk/enrich_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ func TestEnrichSBOM_CycloneDXWithVulnerabilities(t *testing.T) {
4747
vuln := (*bom.Vulnerabilities)[0]
4848
assert.Equal(t, "pkg:pypi/[email protected]", vuln.BOMRef)
4949
assert.Equal(t, "SNYK-PYTHON-NUMPY-73513", vuln.ID)
50+
51+
assert.NotNil(t, vuln.Ratings)
52+
assert.Len(t, *vuln.Ratings, 4)
53+
assert.Equal(t, (*vuln.Ratings)[0].Source, &cdx.Source{Name: "Snyk", URL: "https://security.snyk.io"})
54+
assert.Equal(t, (*vuln.Ratings)[1].Source, &cdx.Source{Name: "NVD"})
5055
}
5156

5257
func TestEnrichSBOM_CycloneDXExternalRefs(t *testing.T) {

0 commit comments

Comments
 (0)