Skip to content

Fixed CPE matching failing for software names that sanitize to FTS5 reserved keywords (AND, OR, NOT) - #41226

Merged
getvictor merged 3 commits into
mainfrom
victor/41225-cpe-matching-reserved-keywords
Mar 10, 2026
Merged

Fixed CPE matching failing for software names that sanitize to FTS5 reserved keywords (AND, OR, NOT)#41226
getvictor merged 3 commits into
mainfrom
victor/41225-cpe-matching-reserved-keywords

Conversation

@getvictor

@getvictor getvictor commented Mar 8, 2026

Copy link
Copy Markdown
Member

Related issue: Resolves #41225

Most diffs are from regenerating software.sql, where we added this:

('_OR_ (FTS5 keyword test)', '1.0.0', 'apps', 'com.test.or', 'Test Vendor', '', '', '', '', NULL, NULL),

Checklist for submitter

If some of the following don't apply, delete the relevant line.

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

Testing

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

Summary by CodeRabbit

  • Bug Fixes

    • Fixed CPE matching failures when software names contain reserved keywords (AND, OR, NOT), ensuring accurate matching in all scenarios.
  • Tests

    • Added test coverage for CPE matching with reserved keyword names to prevent regressions.

@getvictor

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Mar 8, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

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

Fixes an FTS5 query parsing failure in NVD CPE matching when a software name sanitizes to reserved FTS5 operators (AND/OR/NOT), preventing the vulnerability cron from skipping those software entries.

Changes:

  • Update sanitizeMatch to quote each token so FTS5 treats reserved keywords as literals.
  • Add a regression test covering software names that sanitize to reserved keywords.
  • Add a changelog entry for the bug fix.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.

File Description
server/vulnerabilities/nvd/sanitize.go Quotes sanitized tokens to prevent FTS5 reserved keywords from being interpreted as operators in MATCH queries.
server/vulnerabilities/nvd/cpe_test.go Adds coverage to ensure CPE matching does not error on names that sanitize to AND/OR/NOT.
changes/41225-cpe-matching-reserved-keywords Records the user-visible bug fix in the changelog.

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

Comment thread server/vulnerabilities/nvd/cpe_test.go Outdated
@coderabbitai

coderabbitai Bot commented Mar 8, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

This PR fixes a bug in CPE matching where software names containing or sanitizing to FTS5 reserved keywords (AND, OR, NOT) caused query syntax errors. The fix modifies the sanitizeMatch function to tokenize the sanitized string and wrap each token in double quotes, treating them as literal strings in FTS5 queries instead of operators. A test is added to verify that CPEFromSoftware handles such keyword cases without errors.

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% 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 The title accurately and concisely describes the main change: fixing CPE matching for software names that sanitize to FTS5 reserved keywords.
Description check ✅ Passed The PR description includes the related issue number and confirms changes file added and tests updated, addressing the main template sections.
Linked Issues check ✅ Passed The PR implements the proposed fix from issue #41225 by quoting tokens in sanitizeMatch to prevent FTS5 keyword interpretation, with test coverage added.
Out of Scope Changes check ✅ Passed All changes are in-scope: bug fix to sanitizeMatch function, test case for FTS5 keywords, and software.sql regeneration with test data.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch victor/41225-cpe-matching-reserved-keywords

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.

🧹 Nitpick comments (1)
server/vulnerabilities/nvd/cpe_test.go (1)

59-76: Cover the successful-match path too.

This only verifies that the query stops erroring. It still passes if CPEFromSoftware returns an empty CPE, so the regression that prompted this PR is not fully protected. Please add at least one fixture/assertion that a keyword-like name resolves to the expected CPE, not just NoError.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@server/vulnerabilities/nvd/cpe_test.go` around lines 59 - 76, The test
currently only asserts CPEFromSoftware(t.Context(), slog.New(...), db,
&fleet.Software{Name: name...}, ...) does not error for FTS5-keyword-like names;
also assert the successful-match path by adding at least one fixture where a
specific keyword-like software name (e.g., "_OR_" or "OR - Debug") maps to the
expected non-empty CPE string returned by CPEFromSoftware; update the test to
call CPEFromSoftware for that fixture, require.NoError on err, then
require.NotEmpty (or require.Equal) on the returned CPE value to ensure a
correct resolution (reference function CPEFromSoftware, the test variable
ftsKeywordNames and the fleet.Software{Name, Version, Source} input, and
reCache/db used in the call).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@server/vulnerabilities/nvd/cpe_test.go`:
- Around line 59-76: The test currently only asserts
CPEFromSoftware(t.Context(), slog.New(...), db, &fleet.Software{Name: name...},
...) does not error for FTS5-keyword-like names; also assert the
successful-match path by adding at least one fixture where a specific
keyword-like software name (e.g., "_OR_" or "OR - Debug") maps to the expected
non-empty CPE string returned by CPEFromSoftware; update the test to call
CPEFromSoftware for that fixture, require.NoError on err, then require.NotEmpty
(or require.Equal) on the returned CPE value to ensure a correct resolution
(reference function CPEFromSoftware, the test variable ftsKeywordNames and the
fleet.Software{Name, Version, Source} input, and reCache/db used in the call).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a493abc9-72f0-40a7-9662-aa1ec285f9f3

📥 Commits

Reviewing files that changed from the base of the PR and between 9737a6b and a0ab43f.

📒 Files selected for processing (4)
  • changes/41225-cpe-matching-reserved-keywords
  • cmd/osquery-perf/software-library/software.sql
  • server/vulnerabilities/nvd/cpe_test.go
  • server/vulnerabilities/nvd/sanitize.go

@getvictor
getvictor marked this pull request as ready for review March 8, 2026 17:03
@getvictor
getvictor requested a review from a team as a code owner March 8, 2026 17:03
@codecov

codecov Bot commented Mar 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.35%. Comparing base (9df1186) to head (3731127).
⚠️ Report is 94 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #41226      +/-   ##
==========================================
- Coverage   66.35%   66.35%   -0.01%     
==========================================
  Files        2475     2475              
  Lines      198385   198388       +3     
  Branches     8856     8856              
==========================================
+ Hits       131639   131640       +1     
+ Misses      54859    54857       -2     
- Partials    11887    11891       +4     
Flag Coverage Δ
backend 68.14% <100.00%> (-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.

@dantecatalfamo dantecatalfamo 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.

Interesting

@getvictor
getvictor merged commit c2c4993 into main Mar 10, 2026
48 checks passed
@getvictor
getvictor deleted the victor/41225-cpe-matching-reserved-keywords branch March 10, 2026 19:03
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.

FTS5 keyword syntax error in CPE matching for software names containing AND/OR/NOT

3 participants