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: correct APK CPE version comparison logic #1165

Merged
merged 3 commits into from
Mar 8, 2023

Conversation

westonsteimel
Copy link
Contributor

Previously, the -r{buildindex} suffix of APK package versions were treated as pre-release versions per the fuzzy matcher logic; however, these should be treated as equivalent to the release version for the purposes of collecting CPE-based matches for APK packages.

We may want to make a similar change in syft to generate cleaner CPE versions for APK packages, but making the change in grype corrects behaviour for previously-generated SBOMs as well.

@westonsteimel
Copy link
Contributor Author

westonsteimel commented Mar 8, 2023

An example illustrating this is

grype registry:cgr.dev/chainguard/ruby:latest-20230308
 ✔ Vulnerability DB        [no update available]
 ✔ Parsed image
 ✔ Cataloged packages      [114 packages]
 ✔ Scanning image...       [12 vulnerabilities]
   ├── 1 critical, 6 high, 4 medium, 1 low, 0 negligible
   └── 0 fixed
NAME      INSTALLED  FIXED-IN  TYPE  VULNERABILITY   SEVERITY
find      0.1.1                gem   CVE-2015-10065  Critical
find      0.1.1                gem   CVE-2020-24550  Medium
readline  0.0.3                gem   CVE-2014-2524   Low
ruby-3.2  3.2.0-r6             apk   CVE-2023-22795  High

CVE-2023-22795 is fixed for ruby 3.2.0 and therefore shouldn't show up, but since the -r6 is causing it to be treated as a pre-release, it currently gets pulled in

Thanks to @luhring for the example!

@westonsteimel westonsteimel force-pushed the fix-apk-matcher-cpe-version-comparison branch from de25eb9 to 5af75a9 Compare March 8, 2023 11:29
Previously, the -r{buildindex} suffix of APK package versions were
treated as pre-release versions per the fuzzy matcher logic; however,
these should be treated as equivalent to the release version for the
purposes of collecting CPE-based matches for APK packages.

We may want to make a similar change in syft to generate cleaner CPE
versions for APK packages, but making the change in grype corrects
behaviour for previously-generated SBOMs as well.

Signed-off-by: Weston Steimel <[email protected]>
@westonsteimel westonsteimel force-pushed the fix-apk-matcher-cpe-version-comparison branch 2 times, most recently from fbd914f to 94e8087 Compare March 8, 2023 12:04
@westonsteimel westonsteimel force-pushed the fix-apk-matcher-cpe-version-comparison branch from 94e8087 to 8e7bdec Compare March 8, 2023 12:37
@@ -45,7 +46,8 @@ func (m *Matcher) Match(store vulnerability.Provider, d *distro.Distro, p pkg.Pa

func (m *Matcher) cpeMatchesWithoutSecDBFixes(store vulnerability.Provider, d *distro.Distro, p pkg.Package) ([]match.Match, error) {
// find CPE-indexed vulnerability matches specific to the given package name and version
cpeMatches, err := search.ByPackageCPE(store, p, m.Type())
cpePackage := cpeComparablePackage(p)
cpeMatches, err := search.ByPackageCPE(store, cpePackage, m.Type())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be surfacing matches with the original package, the match details should have the necessary (mutated) details. This way we surface the vuln, the original package [from the SBOM as we understand it], and the match details showing what values were used in the search.

Signed-off-by: Weston Steimel <[email protected]>
@westonsteimel westonsteimel force-pushed the fix-apk-matcher-cpe-version-comparison branch from e85d572 to 98eca0f Compare March 8, 2023 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants