feat(cve): group CVEs by package with one VEX decision per group (#949) #959

Merged
sharang merged 1 commits from feat/949-cve-groups into main 2026-11-10 14:31:34 +00:00
Owner

First PR of epic #955. The target's open CVE alerts are grouped by component, and one decision covers the whole group.

What changed

Core (compliance-core/src/cve_groups.rs, new, pure): group_open_alerts(&[CveAlert]) -> Vec<CveGroup>.

  • "Open" means !status_of(alert).resolves(): no not_affected/fixed statement, and not found gone by a complete scan.
  • Groups are keyed by (affected_package, affected_version, purl).
  • fix_version is the highest version above the component's own that any advisory names as fixed. It is compared with the existing version::cmp_dotted.
  • fixable is how many CVEs name such a fix.
  • counts gives CVEs per severity. A CVE in several alerts (a GHSA and the CVE it aliases) counts once, at its highest severity.
  • kev is true if any CVE is in KEV. epss_max is the highest EPSS score.
  • cve_ids and alert_ids list the members.
  • Groups are sorted by max severity, then CVE count, then name.
  • CveSeverity::of rates an alert from the advisory's rating (GitHub MODERATE = medium), else its CVSS score, else info.

Agent (api/handlers/vex.rs, api/routes.rs):

  • GET /api/v1/targets/{id}/cve-groups returns {"data": [CveGroup], "total": n}:
    {"package": "vite", "version": "5.4.21", "purl": "pkg:npm/vite@5.4.21",
     "fix_version": "8.3.3", "fixable": 9,
     "counts": {"critical": 0, "high": 1, "medium": 0, "low": 1, "info": 7},
     "kev": false, "epss_max": 0.012,
     "cve_ids": ["CVE-…"], "alert_ids": ["65f…"]}
    
  • PATCH /api/v1/targets/{id}/cve-groups/vex takes the group key next to the usual statement fields:
    {"package": "vite", "version": "5.4.21", "purl": "pkg:npm/vite@5.4.21",
     "status": "not_affected", "justification": "vulnerable_code_not_in_execute_path",
     "impact_statement": "Build tool only, not shipped."}
    
    • The server recomputes the group from the target's current alerts; it does not trust alert ids sent by the client.
    • It builds one VexAssessment with the same statement() and validate() as PATCH /api/v1/cves/{id}/vex, so by, by_name and at match a single decision.
    • It writes that statement to every open alert of the group with update_many({_id: {$in}, repo_id}).
    • Responses: 422 for the same reasons as a single decision, 404 when the component has no open alert. Success returns {"status": "updated", "updated": n, "vex": {...}}.
  • The per-alert statements are exactly what a single decision writes. The OpenVEX/CycloneDX/CSAF exports and the CVE issue auto-close in pipeline/cve_issues.rs therefore work unchanged.
  • Role gating: no new entries. The PATCH counts as a write through role_gate::is_write, and neither route is in KEY_SCOPES, the same as the single VEX PATCH.
  • list_target_cves now uses the shared loader target_alerts. Its behaviour has not changed: a DB error still returns an empty list.

Dashboard (components/vex_panel.rs, infrastructure/vex.rs, i18n/texts.rs, assets/main.css):

  • The Schwachstellen und VEX section has a Gruppiert / Einzeln toggle and opens on Gruppiert.
  • Each group card shows:
    • the max-severity badge
    • the headline, e.g. vite 5.4.21 → 8.3.3 behebt 9 CVEs (1 hoch, 1 niedrig, 7 info). When some CVEs name no fix it reads behebt 7 von 9 CVEs; when none does, vite 5.4.21: 9 CVEs, kein Fix bekannt (…).
    • a KEV badge and EPSS 70 %
    • Nicht betroffen (alle N), which opens the same statement editor as Bewerten with "Nicht betroffen" preselected
    • CVEs anzeigen, which expands the group's rows. Each row keeps its own Bewerten and ENISA buttons.
  • Einzeln is the existing list, unchanged apart from the severity badge (see below).
  • The editor is now shared between single and group decisions (SaveTo::Alert | SaveTo::Group). After a save, the alerts, ENISA candidates and groups reload.
  • When nothing is open, the grouped view says "alle bewertet oder behoben" instead of "keine Schwachstellen".
  • All texts are in DE and EN in texts.rs.

Docs: docs/guide/vex.md, docs/guide/vex-en.md and the API paragraph in docs/guide/sbom.md.

Behaviour to note

  • Severity badge in the per-CVE list: rows now use the same rating as the group counts. GitHub MODERATE shows as medium (before: info), an alert rated only by CVSS gets its badge (before: none), and an unrated alert shows info.
  • A group decision replaces affected and person-stated under_investigation statements on the group's open alerts. not_affected and fixed alerts are not in the group and keep their statements.
  • Known limitation: the scanner keeps at most 3 fixed_versions per alert (MAX_FIXED in pipeline/cve.rs). fix_version is the highest of the recorded ones, which may not be the highest the advisory lists.

Left for follow-ups

  • Update-Ticket anlegen (one tracker issue per package upgrade) is not in this PR. The only tracker plumbing is per-alert and pipeline-side (cve_issues.rs::create), plus handlers/issues.rs, which is being changed in #946. A small follow-up can add it once those settle.
  • The new dashboard views of #950 and #952 can use GET /cve-groups directly.

How tested

  • Unit tests:
    • core grouping (5): key, open/settled filter, highest fix via cmp_dotted (8.10.0 > 8.3.3, fixes below the current version ignored), counts with alias dedup, KEV/EPSS max, JSON shape
    • agent (2): validation of the group request (flattened body, not_affected without a reason gives NotAffectedWithoutReason, affected without an action is refused, author fields, trimming) and that the group targets only the component's open alerts
    • dashboard (3): headline strings DE/EN including the issue's exact example, button and EPSS labels, the server body shape matching the agent's
  • cargo fmt --all --check
  • cargo clippy -D warnings --all-targets on compliance-core, compliance-agent, and compliance-dashboard with server and with web
  • cargo test -p compliance-core --lib, cargo test -p compliance-agent --lib api::, dashboard vex and i18n tests (server feature)
  • The UI was not opened in a browser. Only compile, clippy and the unit tests above were run.

Closes #949

🤖 Generated with Claude Code

First PR of epic #955. The target's open CVE alerts are grouped by component, and one decision covers the whole group. ## What changed **Core** (`compliance-core/src/cve_groups.rs`, new, pure): `group_open_alerts(&[CveAlert]) -> Vec<CveGroup>`. - "Open" means `!status_of(alert).resolves()`: no `not_affected`/`fixed` statement, and not found gone by a complete scan. - Groups are keyed by `(affected_package, affected_version, purl)`. - `fix_version` is the highest version above the component's own that any advisory names as fixed. It is compared with the existing `version::cmp_dotted`. - `fixable` is how many CVEs name such a fix. - `counts` gives CVEs per severity. A CVE in several alerts (a GHSA and the CVE it aliases) counts once, at its highest severity. - `kev` is true if any CVE is in KEV. `epss_max` is the highest EPSS score. - `cve_ids` and `alert_ids` list the members. - Groups are sorted by max severity, then CVE count, then name. - `CveSeverity::of` rates an alert from the advisory's rating (GitHub `MODERATE` = medium), else its CVSS score, else `info`. **Agent** (`api/handlers/vex.rs`, `api/routes.rs`): - `GET /api/v1/targets/{id}/cve-groups` returns `{"data": [CveGroup], "total": n}`: ```json {"package": "vite", "version": "5.4.21", "purl": "pkg:npm/vite@5.4.21", "fix_version": "8.3.3", "fixable": 9, "counts": {"critical": 0, "high": 1, "medium": 0, "low": 1, "info": 7}, "kev": false, "epss_max": 0.012, "cve_ids": ["CVE-…"], "alert_ids": ["65f…"]} ``` - `PATCH /api/v1/targets/{id}/cve-groups/vex` takes the group key next to the usual statement fields: ```json {"package": "vite", "version": "5.4.21", "purl": "pkg:npm/vite@5.4.21", "status": "not_affected", "justification": "vulnerable_code_not_in_execute_path", "impact_statement": "Build tool only, not shipped."} ``` - The server recomputes the group from the target's current alerts; it does not trust alert ids sent by the client. - It builds **one** `VexAssessment` with the same `statement()` and `validate()` as `PATCH /api/v1/cves/{id}/vex`, so `by`, `by_name` and `at` match a single decision. - It writes that statement to every open alert of the group with `update_many({_id: {$in}, repo_id})`. - Responses: 422 for the same reasons as a single decision, 404 when the component has no open alert. Success returns `{"status": "updated", "updated": n, "vex": {...}}`. - The per-alert statements are exactly what a single decision writes. The OpenVEX/CycloneDX/CSAF exports and the CVE issue auto-close in `pipeline/cve_issues.rs` therefore work unchanged. - Role gating: no new entries. The PATCH counts as a write through `role_gate::is_write`, and neither route is in `KEY_SCOPES`, the same as the single VEX PATCH. - `list_target_cves` now uses the shared loader `target_alerts`. Its behaviour has not changed: a DB error still returns an empty list. **Dashboard** (`components/vex_panel.rs`, `infrastructure/vex.rs`, `i18n/texts.rs`, `assets/main.css`): - The **Schwachstellen und VEX** section has a **Gruppiert / Einzeln** toggle and opens on **Gruppiert**. - Each group card shows: - the max-severity badge - the headline, e.g. `vite 5.4.21 → 8.3.3 behebt 9 CVEs (1 hoch, 1 niedrig, 7 info)`. When some CVEs name no fix it reads `behebt 7 von 9 CVEs`; when none does, `vite 5.4.21: 9 CVEs, kein Fix bekannt (…)`. - a KEV badge and `EPSS 70 %` - **Nicht betroffen (alle N)**, which opens the same statement editor as **Bewerten** with "Nicht betroffen" preselected - **CVEs anzeigen**, which expands the group's rows. Each row keeps its own Bewerten and ENISA buttons. - **Einzeln** is the existing list, unchanged apart from the severity badge (see below). - The editor is now shared between single and group decisions (`SaveTo::Alert | SaveTo::Group`). After a save, the alerts, ENISA candidates and groups reload. - When nothing is open, the grouped view says "alle bewertet oder behoben" instead of "keine Schwachstellen". - All texts are in DE and EN in `texts.rs`. **Docs:** `docs/guide/vex.md`, `docs/guide/vex-en.md` and the API paragraph in `docs/guide/sbom.md`. ## Behaviour to note - **Severity badge in the per-CVE list:** rows now use the same rating as the group counts. GitHub `MODERATE` shows as medium (before: info), an alert rated only by CVSS gets its badge (before: none), and an unrated alert shows info. - **A group decision replaces `affected` and person-stated `under_investigation` statements** on the group's open alerts. `not_affected` and `fixed` alerts are not in the group and keep their statements. - **Known limitation:** the scanner keeps at most 3 `fixed_versions` per alert (`MAX_FIXED` in `pipeline/cve.rs`). `fix_version` is the highest of the recorded ones, which may not be the highest the advisory lists. ## Left for follow-ups - **Update-Ticket anlegen** (one tracker issue per package upgrade) is not in this PR. The only tracker plumbing is per-alert and pipeline-side (`cve_issues.rs::create`), plus `handlers/issues.rs`, which is being changed in #946. A small follow-up can add it once those settle. - The new dashboard views of #950 and #952 can use `GET /cve-groups` directly. ## How tested - Unit tests: - core grouping (5): key, open/settled filter, highest fix via `cmp_dotted` (`8.10.0` > `8.3.3`, fixes below the current version ignored), counts with alias dedup, KEV/EPSS max, JSON shape - agent (2): validation of the group request (flattened body, `not_affected` without a reason gives `NotAffectedWithoutReason`, `affected` without an action is refused, author fields, trimming) and that the group targets only the component's open alerts - dashboard (3): headline strings DE/EN including the issue's exact example, button and EPSS labels, the server body shape matching the agent's - `cargo fmt --all --check` - `cargo clippy -D warnings --all-targets` on compliance-core, compliance-agent, and compliance-dashboard with `server` and with `web` - `cargo test -p compliance-core --lib`, `cargo test -p compliance-agent --lib api::`, dashboard `vex` and `i18n` tests (server feature) - The UI was **not** opened in a browser. Only compile, clippy and the unit tests above were run. Closes #949 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 1 commit 2026-11-10 14:10:29 +00:00
feat(cve): group CVEs by package with one VEX decision per group (#949)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 6m8s
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 20m22s
8f7235017e
The target's open CVE alerts are grouped by component (package, version,
purl) in compliance-core: the highest fixed version the advisories name
above the component's own, how many CVEs that update fixes, the CVEs per
severity (a CVE in several alerts counts once), KEV and the highest EPSS.

Agent:
- GET /api/v1/targets/{id}/cve-groups lists the groups, most severe first.
- PATCH /api/v1/targets/{id}/cve-groups/vex states one VEX status on every
  open alert of a component: one statement per alert with the validation,
  author and time of PATCH /api/v1/cves/{id}/vex, so the exports and the
  CVE issue auto-close treat them as single decisions. Settled alerts keep
  their statements; 404 when the component has no open alert.

Dashboard: the target's VEX section opens grouped ("Gruppiert") with one
card per component ("vite 5.4.21 -> 8.3.3 behebt 9 CVEs (1 hoch, ...)"),
"Nicht betroffen (alle N)" opening the same statement editor as
"Bewerten", and the rows on demand; "Einzeln" keeps the full list. The
severity badge of a row now uses the same rating as the group counts
(GitHub's MODERATE reads as medium, a CVSS-only alert gets its badge).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang force-pushed feat/949-cve-groups from bc5a5eed69 to 8f7235017e 2026-11-10 14:10:29 +00:00 Compare
sharang merged commit f57a1020db into main 2026-11-10 14:31:34 +00:00
Sign in to join this conversation.