Skip to content

Improved cpe deterministic matching - #42325

Merged
ksykulev merged 3 commits into
mainfrom
41644-cpe-matching
Mar 24, 2026
Merged

Improved cpe deterministic matching#42325
ksykulev merged 3 commits into
mainfrom
41644-cpe-matching

Conversation

@ksykulev

@ksykulev ksykulev commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Related issue: Resolves #41644

There are two cases that exist in the cpe database where this generic logic could not be applied.

django from python_packages:
gofiber:django
djangoproject:django

npm from npm_packages:
microsoft:npm
npmjs:npm

These will require individual cve overrides that is outside the scope of this task.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.

  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements), JS inline code is prevented especially for url redirects, and untrusted data interpolated into shell scripts/commands is validated against shell metacharacters.

Testing

  • Added/updated automated tests
  • QA'd all new/changed functionality manually

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced CPE (Common Platform Enumeration) matching to reduce non-deterministic vendor selection when multiple vendors exist for the same software product. The algorithm now incorporates software ecosystem information to ensure more accurate and consistent vulnerability resolution across package types.

@ksykulev
ksykulev requested a review from a team as a code owner March 24, 2026 17:57
Copilot AI review requested due to automatic review settings March 24, 2026 17:57

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review.

Tip: disable this comment in your organization's Code Review settings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Improves deterministic CPE candidate ranking for software entries that often lack vendor data (e.g., package-manager sources) by incorporating the software source’s implied ecosystem (target_sw) into match scoring to reduce nondeterministic vendor selection.

Changes:

  • Add target_sw to indexed CPE query results and introduce ecosystem-based scoring when selecting the “best” CPE candidate.
  • Extend CPE matching tests and test CPE dictionary fixtures to cover python/npm package scenarios.
  • Add a user-visible changes entry describing the improved deterministic matching.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
server/vulnerabilities/nvd/cpe.go Adds target_sw to selection query and implements target_sw/ecosystem scoring in best-match selection.
server/vulnerabilities/nvd/indexed_cpe_item.go Extends IndexedCPEItem with TargetSW to support the new scoring signal.
server/vulnerabilities/nvd/cpe_test.go Adds test coverage for target_sw/ecosystem scoring and deterministic fallback behavior.
server/vulnerabilities/nvd/testing_utils.go Adds additional CPE test fixtures (requests/duplicity/express) to exercise new ranking logic.
changes/41644-improve-cpe-matching Documents the user-visible behavior change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread server/vulnerabilities/nvd/cpe.go
Comment thread server/vulnerabilities/nvd/cpe_test.go Outdated
Comment thread changes/41644-improve-cpe-matching Outdated
@codecov

codecov Bot commented Mar 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.42857% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.51%. Comparing base (c10df65) to head (7d082f2).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
server/vulnerabilities/nvd/cpe.go 91.42% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main   #42325   +/-   ##
=======================================
  Coverage   66.51%   66.51%           
=======================================
  Files        2526     2526           
  Lines      202654   202689   +35     
  Branches     9021     9021           
=======================================
+ Hits       134787   134816   +29     
- Misses      55695    55700    +5     
- Partials    12172    12173    +1     
Flag Coverage Δ
backend 68.31% <91.42%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ksykulev

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai

coderabbitai Bot commented Mar 24, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

The change introduces the target_sw field to the CPE candidate selection process. It adds a new TargetSW field to the IndexedCPEItem struct, updates the CPE database query to retrieve this column, and implements a scoring mechanism that evaluates how well a CPE candidate's vendor matches the software's ecosystem. The CPE selection logic in CPEFromSoftware is modified to rank candidates first by their target_sw match score, then by vendor matching rules. The implementation includes heuristic matching for ecosystem mapping and suffix-based rules. Test coverage is extended with four new scenarios validating behavior across different software sources.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly summarizes the main change: improving CPE matching to be deterministic by leveraging software source information.
Description check ✅ Passed Description includes related issue, documents known limitations requiring CVE overrides, and confirms completion of key checklist items including changes file, input validation, tests, and manual QA.
Linked Issues check ✅ Passed All coding requirements from #41644 are met: target_sw field added to IndexedCPEItem, cpeTargetSWMatchesSoftware scoring function implemented, CPE selection logic updated to rank by target_sw score, and comprehensive test cases added for multiple ecosystems.
Out of Scope Changes check ✅ Passed All changes are scoped to the CPE matching improvement: test data updates, scoring logic, data model changes, and test coverage. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 41644-cpe-matching

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@server/vulnerabilities/nvd/cpe.go`:
- Around line 229-257: The distro/ecosystem matches (the expectedTargetSW == "*"
branch checking software.Source for "deb_packages" and "rpm_packages" and
matching item.Vendor like "debian", "redhat", "fedora") should score higher than
the product "_project" fallback; change the return values in that branch from 1
to a higher score (e.g., 2) so these vendor-less distro/ecosystem signals beat
the vendorLower == productLower+"_project" case (which remains 1), ensuring
distro matches are preferred over the <product>_project fallback and preventing
tie-breaks by alphabetical vendor ordering.
- Around line 123-126: The SELECT list in cpeSelectColumns is missing the
sw_edition column, causing IndexedCPEItem.FmtStr() to read an empty i.SWEdition
and thus serialize CPEs without edition qualifiers; update the cpeSelectColumns
constant to include c.sw_edition (e.g., add c.sw_edition to the SELECT
projection) so the query returns SWEdition and the code that builds/returns
IndexedCPEItem (and its FmtStr()) can populate i.SWEdition correctly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 65a25fff-3be3-4507-9ca2-e2a60a9dc9a9

📥 Commits

Reviewing files that changed from the base of the PR and between 0128279 and b75b0fe.

📒 Files selected for processing (5)
  • changes/41644-improve-cpe-matching
  • server/vulnerabilities/nvd/cpe.go
  • server/vulnerabilities/nvd/cpe_test.go
  • server/vulnerabilities/nvd/indexed_cpe_item.go
  • server/vulnerabilities/nvd/testing_utils.go

Comment thread server/vulnerabilities/nvd/cpe.go
Comment thread server/vulnerabilities/nvd/cpe.go

@getvictor getvictor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good. I think this is a good improvement that should result in fewer false positives/negatives.

@getvictor getvictor self-assigned this Mar 24, 2026
@ksykulev
ksykulev merged commit a599889 into main Mar 24, 2026
48 checks passed
@ksykulev
ksykulev deleted the 41644-cpe-matching branch March 24, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CPE matching sometimes incorrect for software without vendor data

3 participants