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

fix: exclude OS packages from CPE target filtering #1130

Merged
merged 1 commit into from
Feb 13, 2023
Merged
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
9 changes: 9 additions & 0 deletions grype/search/only_vulnerable_targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
syftPkg "github.com/anchore/syft/syft/pkg"
)

func isOSPackage(p pkg.Package) bool {
return p.Type == syftPkg.AlpmPkg || p.Type == syftPkg.ApkPkg || p.Type == syftPkg.DebPkg || p.Type == syftPkg.KbPkg || p.Type == syftPkg.PortagePkg || p.Type == syftPkg.RpmPkg
}

func isUnknownTarget(targetSW string) bool {
if syftPkg.LanguageByName(targetSW) != syftPkg.UnknownLanguage {
return false
Expand Down Expand Up @@ -35,6 +39,11 @@ func isUnknownTarget(targetSW string) bool {
func onlyVulnerableTargets(p pkg.Package, allVulns []vulnerability.Vulnerability) []vulnerability.Vulnerability {
var vulns []vulnerability.Vulnerability

// Exclude OS package types from this logic, since they could be embedding any type of ecosystem package
if isOSPackage(p) {
return allVulns
}

// There are quite a few cases within java where other ecosystem components (particularly javascript packages)
// are embedded directly within jar files, so we can't yet make this assumption with java as it will cause dropping
// of valid vulnerabilities that syft has specific logic https://github.com/anchore/syft/blob/main/syft/pkg/cataloger/common/cpe/candidate_by_package_type.go#L48-L75
Expand Down