-
Notifications
You must be signed in to change notification settings - Fork 2.8k
refactor(lang): use MatchVersion instead of IsVulnerable for Comparer interface
#9735
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
base: main
Are you sure you want to change the base?
refactor(lang): use MatchVersion instead of IsVulnerable for Comparer interface
#9735
Conversation
- use MatchVersion instead of IsVulnerable function - move GenericComparer to separate package - move common IsVulnerable function into driver.go
📊 API Changes DetectedSemver impact: |
|
|
||
| // IsVulnerable checks if the package version is vulnerable to the advisory. | ||
| func (n Comparer) IsVulnerable(ver string, advisory dbTypes.Advisory) bool { | ||
| return compare.IsVulnerable(ver, advisory, n.MatchVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here’s a more detailed description of the issue in #9427.
It’s related to an npm package.
Suppose we have a package with version 4.17.20+root.io.1 and an advisory:
• PatchedVersions: "4.17.20+root.io.5", "4.17.21"
• VulnerableVersions: "=4.17.20", ">4.17.20, <4.17.21"
When we check VulnerableVersions, the package is considered vulnerable.
But when we check PatchedVersions, 4.17.20+root.io.1 == 4.17.20+root.io.5 (because build metadata isn’t compared), so we don’t show this vulnerability.
Test for this case:
https://github.com/chait-slim/trivy/blob/790eaa7a430f9b95370d9a13695174b13c09b6d3/pkg/detector/library/rootio/rootio_test.go#L123-L154
Description
Refactored the
Comparerinterface in the library detection system to use a cleanerMatchVersionfunction instead ofIsVulnerable. This change simplifies version comparison logic by separating constraint matching from vulnerabilityassessment.
Changes
Comparerinterface fromIsVulnerable(currentVersion, advisory)toMatchVersion(currentVersion, constraint)GenericComparerfrompkg/detector/library/compare/topkg/detector/library/compare/generic/IsVulnerablefunction intodriver.go, centralizing vulnerability assessment logicRelated PRs
IsVulnerablethat checks onlyVulnerableVersionsand doesn’t checkPatchedVersions.However, the current compares are tied to the main IsVulnerable and don’t allow reusing them.
Checklist