Consider OS distro during vulnerability matching#5783
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
dac7bff to
cdb8634
Compare
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferences |
cdb8634 to
134b2dc
Compare
|
Testing with cdxgen, scalibr, Syft, and Trivy.
|
f9f03bd to
900a70e
Compare
900a70e to
3c140fe
Compare
There was a problem hiding this comment.
Pull request overview
This PR improves OSV-based vulnerability matching for OS packages by incorporating the OS distribution (“distro”) into PURL-based matching, and optimizes OSV mirroring/persistence behavior to reduce database overhead.
Changes:
- Add distro-aware PURL matching (including codename ↔ version matching for Debian/Ubuntu, and major.minor handling for Alpine).
- Enrich OSV-affected package PURLs with inferred
distroqualifiers derived from OSV ecosystem metadata where missing. - Refactor version-range comparison to use
versatileschemes and adjust OSV mirroring to reduce transaction/ORM overhead; add extensive test coverage.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/org/dependencytrack/model/ConfigPropertyConstants.java | Changes defaults for vulnerability-source toggles (needs reverting before merge). |
| src/main/java/org/dependencytrack/model/OsDistribution.java | New distro parsing/matching model for Alpine/Debian/Ubuntu. |
| src/main/java/org/dependencytrack/tasks/OsvDownloadTask.java | Infers/adds distro qualifiers, refactors mirroring transaction/indexing behavior. |
| src/main/java/org/dependencytrack/tasks/scanners/AbstractVulnerableSoftwareAnalysisTask.java | Adds distro qualifier gate for PURL matching; refactors version-range checks. |
| src/main/java/org/dependencytrack/persistence/VulnerableSoftwareQueryManager.java | Extends PURL lookup to include qualifiers in identity matching. |
| src/main/java/org/dependencytrack/persistence/QueryManager.java | Adds overload to query vulnerable software by PURL including qualifiers. |
| src/main/java/org/dependencytrack/util/PurlUtil.java | Adds qualifier serialization + distro qualifier extraction helpers. |
| src/main/java/org/dependencytrack/model/VulnerableSoftware.java | Removes cached Vers building; introduces hasVersionRange() helper. |
| src/main/java/org/dependencytrack/parser/nvd/ModelConverter.java | Removes PURL→VulnerableSoftware conversion helper (tests now use dedicated util). |
| src/test/java/org/dependencytrack/model/OsDistributionTest.java | New unit tests for distro parsing and matching behavior. |
| src/test/java/org/dependencytrack/tasks/scanners/InternalAnalysisTaskDistroMatchingTest.java | New integration tests for distro-aware internal analysis matching. |
| src/test/java/org/dependencytrack/tasks/scanners/InternalAnalysisTaskPurlMatchingTest.java | Updates PURL matching tests to use new test utility. |
| src/test/java/org/dependencytrack/tasks/scanners/VulnerableSoftwareTestUtil.java | New test utility for constructing VulnerableSoftware from PURLs. |
| src/test/java/org/dependencytrack/tasks/OsvDownloadTaskTest.java | Adjusts test setup for vulnerable software PURLs. |
| dev/docker-compose.postgres.yml | Adds pg_stat_statements + PgHero for local performance analysis. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/org/dependencytrack/tasks/scanners/AbstractVulnerableSoftwareAnalysisTask.java
Outdated
Show resolved
Hide resolved
f0e9756 to
ecb46c3
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/org/dependencytrack/tasks/scanners/AbstractVulnerableSoftwareAnalysisTask.java
Outdated
Show resolved
Hide resolved
src/test/java/org/dependencytrack/tasks/scanners/InternalAnalysisTaskDistroMatchingTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/dependencytrack/model/OsDistributionTest.java
Outdated
Show resolved
Hide resolved
ecb46c3 to
e501c5d
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
e501c5d to
89264aa
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/main/java/org/dependencytrack/tasks/scanners/AbstractVulnerableSoftwareAnalysisTask.java
Show resolved
Hide resolved
src/test/java/org/dependencytrack/tasks/scanners/VulnerableSoftwareTestUtil.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/model/VulnerableSoftware.java
Outdated
Show resolved
Hide resolved
src/main/java/org/dependencytrack/tasks/scanners/AbstractVulnerableSoftwareAnalysisTask.java
Show resolved
Hide resolved
* Where possible, enriches an affected package's PURL with `distro` qualifier inferred from the package's `ecosystem`. e.g. `ecosystem=Debian:7` becomes `distro=debian-11`, `ecosystem=Ubuntu:20.04:LTS` becomes `distro=ubuntu-20.04` etc. * During vulnerability analysis, if both component and matching criteria have a PURL `distro` qualifier, ensures they match. Matching can handle codename <-> version comparisons, e.g. for Ubuntu `focal` would match `20.04` and vice versa. * Generally improves performance of OSV mirroring by using fewer transactions and disabling ORM features that caused expensive unnecessary queries. Currently Alpine, Debian, and Ubuntu distribution matching is implemented. These seem to work for SBOMs generated with Trivy and Syft. The codename <-> version mapping is currently hardcoded for Debian and Ubuntu. There is a fallback mechanism that will handle exact matches, such that when Debian publishes a hypothetical "foo" release, we can still match components with vulnerabilities if both `distro` qualifiers are exactly "foo". Debian and Ubuntu provide CSV which we could regularly fetch at runtime, but this involves more work to coordinate. Fixes #1374 Fixes #5776 Fixes #4445 Fixes #4725 Signed-off-by: nscuro <[email protected]>
89264aa to
15df5bf
Compare
Description
Considers OS distro during vulnerability matching.
distroqualifier inferred from the package'secosystem. e.g.ecosystem=Debian:11becomesdistro=debian-11,ecosystem=Ubuntu:20.04:LTSbecomesdistro=ubuntu-20.04etc.distroqualifier, ensures they match. Matching can handle codename <-> version comparisons, e.g. for Ubuntufocalwould match20.04and vice versa.Currently Alpine, Debian, and Ubuntu distribution matching is implemented. These seem to work for SBOMs generated with Trivy and Syft.
The codename <-> version mapping is currently hardcoded for Debian and Ubuntu. There is a fallback mechanism that will handle exact matches, such that when Debian publishes a hypothetical "foo" release, we can still match components with vulnerabilities if both
distroqualifiers are exactly "foo".Debian and Ubuntu provide CSV which we could regularly fetch at runtime, but this involves more work to coordinate.
Addressed Issue
Fixes #1374
Fixes #5776
Fixes #4445
Fixes #4725
Additional Details
A container image for this PR is available at
dependencytrack/bundled:feature-distro-matching.OSV is enabled by default and configured to mirror the
Alpine,Debian, andUbuntuecosystems.Checklist
This PR implements an enhancement, and I have provided tests to verify that it works as intendedThis PR introduces changes to the database model, and I have added corresponding update logicThis PR introduces new or alters existing behavior, and I have updated the documentation accordingly