feat(cve): the daily monitor re-checks NVD/CPE-only components incrementally #558

Merged
sharang merged 2 commits from feat/nvd-cpe-monitor into main 2026-10-09 18:19:20 +00:00
Owner

What

The CVE monitor (scheduler.rs) asked only OSV. Components without an OSV-matchable purl (Yocto recipes via SbomEntry.cpe, header-detected embedded libraries, the CODESYS runtime) were re-matched in NVD only when a scan ran. New: an NVD pass after the OSV pass (pipeline/nvd_monitor.rs).

Design

  • One lastMod listing for all tenants, matched locally (instead of virtualMatchString per CPE). NVD modifies ~3-4k CVEs/day (checked 2026-10-08: 3769), so that's ~8 pages of 500 per day for every tenant together. Per-CPE queries would cost one request per product and tenant on every (hourly) run, hundreds for one Yocto layer tree. Local matching uses the scan's rules: virtualMatchString prefix semantics (nvd_cpe::matches_virtual), the marker, the version range (nvd_cpe::parse_cve, split out of parse).
  • Windows: lastModStartDate/lastModEndDate, at most 120 days (NVD answers 404 "Date range cannot exceed 120 days" otherwise, verified), ending 15 min before now. The first run reads the last 7 days.
  • Cursor in the admin DB (<prefix>__admin.nvd_monitor, _id: lastmod): done_until plus the open window's end, startIndex and totalResults. The run stops on the budget (10 min), an NVD error or a DB error without advancing past the page. The next run continues there, across days. If totalResults shrinks while paging (CVEs modified again leave the window), the next page starts that many places earlier, so nothing gets skipped. A page over the 16 MiB body cap is asked for again with half the page size. With no tenants (registry failure) nothing runs. With no watched components anywhere, the cursor moves on without requests.
  • Pacing/key: nvd_cpe::request_interval (0.6 s with NVD_API_KEY, 6 s without). It reuses the nvd_cpe client: the retry loop is factored into nvd_cpe::fetch (same retries, same guard).
  • Results: cve::record_nvd (same CveAlert: purl, CVSS, summary, source nvd, repo_id; VulnRef added once), stored with $setOnInsert on (cve_id, repo_id) via the new vex_lifecycle::store_monitored (now also used by the OSV pass, same behaviour). Unlike upsert_reported it leaves alone the scan's own VEX statements (recipe CVE_STATUS) and resolved_at. Then attach_stored_vex and notify_new_cves. CVE issues are created only for newly inserted alerts, through the shared CveIssueSync (factored out of the orchestrator), with complete=false, so nothing gets closed for being missing.
  • Log: one INFO line per tenant: components, cpes, requests, new_alerts, notified, suppressed_by_vex, budget_spent, error, resume_at. Plus a WARN if a run stopped on an error.

Config

NVD_MONITOR=on|off, default on. Without a key it is paced to 5 req/30 s and bounded at 10 min per run, so it is slow but harmless. A typical hourly run is 1 request.

Tests

  • nvd_monitor::tests: the cursor tests (first window, 120-day split with no gap, resume in a later run, rewind when the listing shrinks, empty page, skip never past an open window), the switch, CPE selection, recipe CPE parsing, page matching. Also a Mongo + fake NVD (axum) test, the_monitor_raises_new_nvd_alerts_resumes_and_respects_vex. It covers budget exhaustion and resume, the same window continued, alerts with purl/CVSS, no duplicates, VEX not_affected suppressing the notification, the next window starting at the previous end, and an NVD 404 leaving the cursor unchanged.
  • nvd_cpe::tests::a_match_string_matches_cpes_as_nvd_lists_them, and an extended cve::tests::an_nvd_alert_keeps_the_purl_of_its_component.

Docs: guide/sbom.md (Known vulnerabilities), guide/yocto.md, reference/tools.md, .env.example.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p

## What The CVE monitor (scheduler.rs) asked only OSV. Components without an OSV-matchable purl (Yocto recipes via `SbomEntry.cpe`, header-detected embedded libraries, the CODESYS runtime) were re-matched in NVD only when a scan ran. New: an NVD pass after the OSV pass (`pipeline/nvd_monitor.rs`). ## Design - **One lastMod listing for all tenants, matched locally** (instead of `virtualMatchString` per CPE). NVD modifies ~3-4k CVEs/day (checked 2026-10-08: 3769), so that's ~8 pages of 500 per day for every tenant together. Per-CPE queries would cost one request per product and tenant on every (hourly) run, hundreds for one Yocto layer tree. Local matching uses the scan's rules: `virtualMatchString` prefix semantics (`nvd_cpe::matches_virtual`), the marker, the version range (`nvd_cpe::parse_cve`, split out of `parse`). - **Windows**: `lastModStartDate`/`lastModEndDate`, at most 120 days (NVD answers 404 "Date range cannot exceed 120 days" otherwise, verified), ending 15 min before now. The first run reads the last 7 days. - **Cursor** in the admin DB (`<prefix>__admin.nvd_monitor`, `_id: lastmod`): `done_until` plus the open window's end, `startIndex` and `totalResults`. The run stops on the budget (10 min), an NVD error or a DB error without advancing past the page. The next run continues there, across days. If `totalResults` shrinks while paging (CVEs modified again leave the window), the next page starts that many places earlier, so nothing gets skipped. A page over the 16 MiB body cap is asked for again with half the page size. With no tenants (registry failure) nothing runs. With no watched components anywhere, the cursor moves on without requests. - **Pacing/key**: `nvd_cpe::request_interval` (0.6 s with `NVD_API_KEY`, 6 s without). It reuses the nvd_cpe client: the retry loop is factored into `nvd_cpe::fetch` (same retries, same guard). - **Results**: `cve::record_nvd` (same CveAlert: purl, CVSS, summary, source nvd, repo_id; VulnRef added once), stored with `$setOnInsert` on (cve_id, repo_id) via the new `vex_lifecycle::store_monitored` (now also used by the OSV pass, same behaviour). Unlike `upsert_reported` it leaves alone the scan's own VEX statements (recipe CVE_STATUS) and resolved_at. Then `attach_stored_vex` and `notify_new_cves`. CVE issues are created only for newly inserted alerts, through the shared `CveIssueSync` (factored out of the orchestrator), with `complete=false`, so nothing gets closed for being missing. - **Log**: one INFO line per tenant: components, cpes, requests, new_alerts, notified, suppressed_by_vex, budget_spent, error, resume_at. Plus a WARN if a run stopped on an error. ## Config `NVD_MONITOR=on|off`, **default on**. Without a key it is paced to 5 req/30 s and bounded at 10 min per run, so it is slow but harmless. A typical hourly run is 1 request. ## Tests - `nvd_monitor::tests`: the cursor tests (first window, 120-day split with no gap, resume in a later run, rewind when the listing shrinks, empty page, skip never past an open window), the switch, CPE selection, recipe CPE parsing, page matching. Also a Mongo + fake NVD (axum) test, `the_monitor_raises_new_nvd_alerts_resumes_and_respects_vex`. It covers budget exhaustion and resume, the same window continued, alerts with purl/CVSS, no duplicates, VEX `not_affected` suppressing the notification, the next window starting at the previous end, and an NVD 404 leaving the cursor unchanged. - `nvd_cpe::tests::a_match_string_matches_cpes_as_nvd_lists_them`, and an extended `cve::tests::an_nvd_alert_keeps_the_purl_of_its_component`. Docs: guide/sbom.md (Known vulnerabilities), guide/yocto.md, reference/tools.md, .env.example. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-09 17:44:48 +00:00
feat(cve): the daily monitor re-checks NVD/CPE-only components incrementally
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 10m4s
3e17163a6e
The CVE monitor asked only OSV, so Yocto recipes, header-detected embedded
libraries and the CODESYS runtime were re-matched in NVD only by a scan.
A new NVD pass (pipeline/nvd_monitor.rs) reads NVD's lastMod listing
(lastModStartDate/lastModEndDate, windows of at most 120 days, 500 CVEs per
page, one listing for all tenants) and matches the changed CVEs locally with
the scan's rules (virtualMatchString semantics, marker, version range).

- Cursor in the admin DB (done_until + open window/startIndex/total): a run
  stopped by its 10-minute budget, an NVD or a database error continues
  there; a listing that shrinks while paged is re-read from earlier.
- Paced with nvd_cpe::request_interval (0.6 s with NVD_API_KEY, 6 s
  without), reusing the nvd_cpe client (fetch with retries, factored out).
- Matches become the scan's CveAlert (purl, cvss, repo_id), stored with
  $setOnInsert on (cve_id, repo_id) (vex_lifecycle::store_monitored, now
  shared with the OSV pass), VEX attached, notify_new_cves, and CVE issues
  for new alerts via the shared CveIssueSync (incomplete: closes nothing).
- One INFO line per tenant with counts; NVD_MONITOR=off turns it off
  (default on).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang added 1 commit 2026-10-09 18:00:13 +00:00
fix(cve): the NVD monitor adds its CVEs to SBOM entries without overwriting a scan's
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 11m9s
0e3fccf674
The pass reads the entries at its start and may run for 10 minutes; each
new CVE reference is now pushed unless listed, instead of setting the whole
list from the copy read earlier. Tests: an oversized page is asked for again
with half as many CVEs; the one-request budget test gets room for a slow
first connection.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
sharang merged commit 57b5aaeb97 into main 2026-10-09 18:19:20 +00:00
Sign in to join this conversation.