Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pass thru the cpe source if available #1946

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading