-
Notifications
You must be signed in to change notification settings - Fork 571
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
Filter out packages that are owned by OS packages (ownership overlap) #1373
Comments
This is related to anchore/syft#931 |
Found an example case where I'm not sure the RPM package should have won over the python package: Language packages that are available from the OS package manager. For example, in the branch where I have this feature partly built, we can see: It's likely there because someone ran |
Actually these are exactly the cases where we want the os packages to win out by default because rhel backport fixes that PyPI won't know about. |
Now something which would be even more accurate here would be to somehow deselect PyPI vulns specifically when a RHEL one overrules it, but that gets much more complicated because right now grype only knows how to fetch vulnerabilities that a package may be affected by and that approach would require fetching ones that a package is not affected by. It'd also require looking at the relatedVulnerability data to convert identifiers so that you could compare between say GHSA and CVE. It might be doable though, but probably needs alot more thought |
Also I don't think we could do that approach today since grypedb might not even have records when something is marked as not affected or withdrawn, and those would be important to capture somewhere if attempting the more advanced approach |
Thanks for the additional context @westonsteimel. Based on that additional info, I'll keep trying to get #1387 merged. I may have found an interesting edge case with the quality gate, which I'll discuss on the PR. |
@westonsteimel and I discussed this issue this morning, and I think there are basically 2 approaches, which I'll explain with an example issue: Example situation
In this case, Let's see what grype thinks:
We can see that all the vulnerabilities are reported against the JAR, not the RPM. So there are two possibilities: either the RPM has a distro-specific fix that we know about, or the distro doesn't report the package as vulnerable. This brings us to the two approaches: First approach: remove before matchingIn this approach, we remove the JAR However, there are 3 possible situations:
Second possible approachIn the second approach, we try to figure out which of the 3 possible situations we're in, and act accordingly:
I'm going to take some time to see how hard implementing the second approach is. |
I've done some research on the second approach, and it requires changing grype a bit. In order to be able to correctly dedupe in this way, we need a place in the code where we have the following information:
Right now, the only place where all this information is in scope is at grype/cmd/grype/cli/legacy/root.go Line 367 in fff4341
vulnerabilityMatcher.FindMatches call, so I think the vulnerability matcher struct (grype.VulnerabilityMatcher ) should be updated to have a pointer to the SBOM. The code should check for nil on the vulnerability matcher struct, since library users might not know to set the new field.
I'll take this specific approach and see how far it gets me:
|
Met with @wagoodman to discuss this, and we had some thoughts. First, there are 3 logical states grype can believe about a given package/CVE combination:
Right now, grype's searching doesn't distinguish between cases 2 and 3. Case 1 gets printed, and cases 2 and 3 get dropped. However, logic distinguishing cases 2 and 3 would be very helpful. Let's call case 3 an "anti-match." We could have a situation, for example, where someone has run This is the same logic as the second approach in #1373 (comment), but it provides a new entity that can be used in grype. So the functions in the search package will return a slice of known matches and a slice of known anti-matches, and the present of anti-matches can be used to perform business logic, especially for lowering the false positive rate. Additionally, we could display packages from grype that are known to be patched or not affected, which might save time to security teams. |
I think rather than block this issue on #1426, we might do the following:
For example, if we're scanning an RHEL8 image, and we have an RPM that owns a Python package, go ahead and remove the Python package before matching, since the RHEL8 feed will have better information on whether the package is vulnerable than GHSA will. But if we're scanning an Alpine image and there's an APK that owns a Python package, leave the python package under consideration for matching, because Alpine only reports fixes, and so the matching GHSA or NVD data directly is necessary to detect vulnerabilities that Alpine hasn't released a patch for yet. Then, when #1426 is implemented, we can remove the allow-list in favor of the logic described in the previous comment. Next steps are:
|
What would you like to be added:
Today we conditionally filter out packages that are owned by other packages before attempting to find matches
grype/grype/pkg/package.go
Lines 104 to 144 in bc93a96
Ideally we would remove packages that overlap in ownership with other packages when the parent package is an OS package.
Why is this needed:
This should remove a class of false positives since OS distributions typically manage back ports of fixes and are the source of truth for the logical package, thus should override any vulnerability match claims for the contained packages (e.g. if an RPM contains a python package and we find a vuln for the python package and not the RPM, we should drop this).
Dev notes:
The text was updated successfully, but these errors were encountered: