Skip to content

Commit

Permalink
feat(cve): add reference url for cve
Browse files Browse the repository at this point in the history
Signed-off-by: Laurentiu Niculae <[email protected]>
  • Loading branch information
laurentiuNiculae committed Nov 27, 2023
1 parent 02a8ed7 commit 93ef408
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/extensions/search/cve/model/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type CVE struct {
Description string `json:"Description"`
Severity string `json:"Severity"`
Title string `json:"Title"`
Reference string `json:"Reference"`
PackageList []Package `json:"PackageList"`
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/extensions/search/cve/trivy/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ func (scanner Scanner) scanManifest(ctx context.Context, repo, digest string) (m
ID: vulnerability.VulnerabilityID,
Title: vulnerability.Title,
Description: vulnerability.Description,
Reference: getCVEReference(vulnerability.PrimaryURL, vulnerability.References),
Severity: convertSeverity(vulnerability.Severity),
PackageList: newPkgList,
}
Expand All @@ -439,6 +440,18 @@ func (scanner Scanner) scanManifest(ctx context.Context, repo, digest string) (m
return cveidMap, nil
}

func getCVEReference(primaryURL string, references []string) string {
if primaryURL != "" {
return primaryURL
}

if len(references) > 0 {
return references[0]
}

return ""
}

func (scanner Scanner) scanIndex(ctx context.Context, repo, digest string) (map[string]cvemodel.CVE, error) {
if cachedMap := scanner.cache.Get(digest); cachedMap != nil {
return cachedMap, nil
Expand Down
13 changes: 13 additions & 0 deletions pkg/extensions/search/cve/trivy/scanner_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,16 @@ func TestIsIndexScannableErrors(t *testing.T) {
})
})
}

func TestGetCVEReference(t *testing.T) {
Convey("getCVEReference", t, func() {
ref := getCVEReference("primary", []string{})
So(ref, ShouldResemble, "primary")

ref = getCVEReference("", []string{"secondary"})
So(ref, ShouldResemble, "secondary")

ref = getCVEReference("", []string{""})
So(ref, ShouldResemble, "")
})
}
57 changes: 57 additions & 0 deletions pkg/extensions/search/gql_generated/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/extensions/search/gql_generated/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pkg/extensions/search/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ func getCVEListForImage(
desc := cveDetail.Description
title := cveDetail.Title
severity := cveDetail.Severity
referenceURL := cveDetail.Reference

pkgList := make([]*gql_generated.PackageInfo, 0)

Expand All @@ -244,6 +245,7 @@ func getCVEListForImage(
Title: &title,
Description: &desc,
Severity: &severity,
Reference: &referenceURL,
PackageList: pkgList,
},
)
Expand Down
4 changes: 4 additions & 0 deletions pkg/extensions/search/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ type CVE {
"""
Description: String
"""
Reference for the given CVE
"""
Reference: String
"""
The impact the CVE has, one of "UNKNOWN", "LOW", "MEDIUM", "HIGH", "CRITICAL"
"""
Severity: String
Expand Down

0 comments on commit 93ef408

Please sign in to comment.