Skip to content

Commit

Permalink
feat: pass thru the cpe source if available
Browse files Browse the repository at this point in the history
For CPE-based matches, display the detail about the CPE used to match.

This includes the "source" indicating if the cpe was syft-generated, or
a lookup from the cpe-dictionary.

Signed-off-by: Zach Hill <[email protected]>
  • Loading branch information
zhill committed Jun 14, 2024
1 parent 587a844 commit 1e1594d
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions grype/search/cpe.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ type CPEPackageParameter struct {
}

type CPEParameters struct {
Namespace string `json:"namespace"`
CPEs []string `json:"cpes"`
Package CPEPackageParameter `json:"package"`
Namespace string `json:"namespace"`
CPEs []string `json:"cpes"`
Package CPEPackageParameter `json:"package"`
CPEDetails []CPEDetail `json:"cpeDetails"`
}

func (i *CPEParameters) Merge(other CPEParameters) error {
Expand All @@ -48,6 +49,23 @@ type CPEResult struct {
CPEs []string `json:"cpes"`
}

type CPEDetail struct {
CPE string `json:"cpe"`
CPESource string `json:"cpeSource"`
}

func cpeToCpeDetail(cpes []cpe.CPE) []CPEDetail {
details := make([]CPEDetail, len(cpes))
cpeStrings := cpesToString(cpes)
for i, c := range cpes {
details[i] = CPEDetail{
CPE: cpeStrings[i],
CPESource: string(c.Source),
}
}
return details
}

func (h CPEResult) Equals(other CPEResult) bool {
if h.VersionConstraint != other.VersionConstraint {
return false
Expand Down Expand Up @@ -161,6 +179,7 @@ func addNewMatch(matchesByFingerprint map[match.Fingerprint]match.Match, vuln vu
CPEs: []string{
searchedByCPE.Attributes.BindToFmtString(),
},
CPEDetails: cpeToCpeDetail([]cpe.CPE{searchedByCPE}),
Package: CPEPackageParameter{
Name: p.Name,
Version: p.Version,
Expand Down

0 comments on commit 1e1594d

Please sign in to comment.