From 5367c386b2356b8c79115b4cf1a822288496531c Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Mon, 16 Nov 2026 16:47:58 +0100 Subject: [PATCH] fix(vex): a CVE a scan no longer finds is not stated fixed (#994) A complete scan that no longer finds a CVE used to state VEX `fixed` (Weg A), and the exports read `resolved_at` without a statement as `fixed` (Weg B). A CVE can disappear without a fix, so neither holds. - resolve_gone only sets resolved_at; it states nothing. - CveAlert::statement() ignores the `fixed` scans inferred that way (by_scan, fixed, no reason given); a Yocto recipe's statement gives its reason and still counts. status_of, is_resolved_by_vex, the exports, the CVE groups and the ENISA drafts all read through it. - status_of: no statement means under_investigation, gone or not. - ENISA: the final report is dated only by a person's `fixed`; an exploited CVE that is merely gone reads "no longer found", not fixed. - The CVE list (API and MCP) leaves the inferred statements out, so the dashboard no longer shows them. - scripts/vex-994-cleanup.js counts the stored ones and removes them only with apply=true; dry run by default, counts only. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9 --- compliance-agent/src/api/handlers/vex.rs | 6 +- compliance-agent/src/pipeline/cve_issues.rs | 45 ++++++++++ .../src/pipeline/vex_lifecycle.rs | 70 ++++++--------- compliance-agent/tests/vex_lifecycle.rs | 36 +++++--- compliance-core/src/csaf_docs.rs | 4 +- compliance-core/src/cve_groups.rs | 5 +- compliance-core/src/enisa_docs.rs | 88 +++++++++++++++---- compliance-core/src/models/cve.rs | 58 ++++++++++-- compliance-core/src/models/vex.rs | 14 ++- compliance-core/src/vex_docs.rs | 28 +++--- compliance-core/tests/vex_schemas.rs | 44 +++++++++- compliance-mcp/src/tools/targets.rs | 8 +- docs/guide/sbom.md | 11 +-- docs/guide/vex-en.md | 19 ++-- docs/guide/vex.md | 21 +++-- scripts/vex-994-cleanup.js | 53 +++++++++++ 16 files changed, 380 insertions(+), 130 deletions(-) create mode 100644 scripts/vex-994-cleanup.js diff --git a/compliance-agent/src/api/handlers/vex.rs b/compliance-agent/src/api/handlers/vex.rs index c097f71..0a17715 100644 --- a/compliance-agent/src/api/handlers/vex.rs +++ b/compliance-agent/src/api/handlers/vex.rs @@ -20,7 +20,8 @@ use super::dto::{collect_cursor_async, tenant_db, AgentExt, ApiResponse, ApiResu use super::findings::Actor; /// GET /api/v1/targets/{id}/cves — the target's CVE alerts with their VEX -/// statements, newest first. +/// statements, newest first. A `fixed` a scan inferred from a CVE no longer +/// being found is left out (#994). #[tracing::instrument(skip_all, fields(target_id = %id))] pub async fn list_target_cves( Extension(agent): AgentExt, @@ -29,7 +30,8 @@ pub async fn list_target_cves( ) -> ApiResult> { let db = tenant_db(&agent, &tenant).await?; // An unreadable list reads as empty here, as it always has. - let alerts = target_alerts(&db, &id).await.unwrap_or_default(); + let mut alerts = target_alerts(&db, &id).await.unwrap_or_default(); + alerts.iter_mut().for_each(CveAlert::drop_inferred_fix); Ok(Json(ApiResponse { total: Some(alerts.len() as u64), data: alerts, diff --git a/compliance-agent/src/pipeline/cve_issues.rs b/compliance-agent/src/pipeline/cve_issues.rs index 22d1569..ec13cdc 100644 --- a/compliance-agent/src/pipeline/cve_issues.rs +++ b/compliance-agent/src/pipeline/cve_issues.rs @@ -997,6 +997,51 @@ mod tests { pool.drop_tenant("cve-issues-vex").await.ok(); } + #[tokio::test] + async fn a_cve_gone_from_the_scan_is_never_closed_as_vex_fixed() { + let Some((pool, db)) = test_db("cve-issues-gone").await else { + return; + }; + let calls: Calls = Arc::default(); + let tracker = tracker_at(fake_gitea(calls.clone()).await); + let target = vex_target(&db, &tracker, IssueAutoclose::On); + // The `fixed` scans inferred from a CVE no longer found (#994). + let mut log4j = alert("log4j-core", "2.14.1", "CVE-2021-44228", "CRITICAL"); + log4j.vex = Some(VexAssessment { + by: "pruefwerk-scan".into(), + by_scan: true, + ..vex(VexStatus::Fixed) + }); + + // Reported with it: no statement, so the issue opens. + let counts = sync_cve_issues(&target, std::slice::from_ref(&log4j), true) + .await + .unwrap(); + assert_eq!( + counts, + CveIssueCounts { + created: 1, + ..Default::default() + } + ); + + // Gone: closed for being gone, never with a VEX status. + assert_eq!( + sync_cve_issues(&target, &[], true).await.unwrap(), + closed(1) + ); + { + let calls = calls.lock().unwrap(); + assert!(calls.iter().all(|c| !c.contains("VEX")), "{calls:?}"); + assert!( + calls.iter().any(|c| c.contains("no longer finds")), + "{calls:?}" + ); + } + + pool.drop_tenant("cve-issues-gone").await.ok(); + } + /// Log lines written while the returned guard lives (on this thread; a /// `#[tokio::test]` runs on one). fn capture_logs() -> (Arc>>, tracing::subscriber::DefaultGuard) { diff --git a/compliance-agent/src/pipeline/vex_lifecycle.rs b/compliance-agent/src/pipeline/vex_lifecycle.rs index 48abfa8..67bc45f 100644 --- a/compliance-agent/src/pipeline/vex_lifecycle.rs +++ b/compliance-agent/src/pipeline/vex_lifecycle.rs @@ -2,10 +2,12 @@ //! //! An alert is stored once per CVE and target. Reported again, it is updated //! and counts as open: a `fixed` the scan had stated is withdrawn. When a -//! complete lookup no longer reports it (the component removed or updated -//! past the fix), it is marked resolved, and one nobody assessed, or -//! assessed as affected, gets the VEX status `fixed` from the scan. A -//! person's `not_affected` or `fixed` is never changed by a scan. What a +//! complete lookup no longer reports it, it is marked resolved, and its VEX +//! status stays as it was: that a CVE is gone is no evidence of a fix, so a +//! scan never states `fixed` for it (#994). A `fixed` scans stated that way +//! before is read as no statement ([`CveAlert::statement`]) and withdrawn +//! when the CVE is reported again. A person's statement is never changed by +//! a scan. What a //! scan states from the target's own data (a Yocto recipe's CVE_STATUS or //! `CVE:` patch) is stated again on every scan, and likewise never replaces //! a person's statement. The first @@ -20,7 +22,7 @@ use futures_util::TryStreamExt; use mongodb::bson::doc; -use compliance_core::models::{CveAlert, StatusChange, VexAssessment, VexStatus}; +use compliance_core::models::{CveAlert, VexAssessment}; use crate::database::{Database, DatabasePool}; use crate::error::AgentError; @@ -297,6 +299,11 @@ pub async fn attach_stored_vex( /// Mark resolved the stored alerts of `repo_id` a complete lookup /// (`complete`) no longer reports in `current`. /// +/// That is what the scan observed, not a VEX statement: each alert keeps the +/// statement it has, and one without stays without. A CVE can disappear for +/// other reasons than a fix (other scan data, an incomplete inventory, a +/// changed identification), so only a person states `fixed` (#994). +/// /// # Returns /// /// How many were resolved. @@ -313,52 +320,25 @@ pub async fn resolve_gone( if !complete { return Ok(0); } - let now = mongodb::bson::DateTime::now(); let seen: Vec<&str> = current.iter().map(|a| a.cve_id.as_str()).collect(); - let gone = doc! { - "repo_id": repo_id, - "cve_id": { "$nin": seen }, - "resolved_at": { "$exists": false }, - }; - let fixed = VexAssessment { - status: VexStatus::Fixed, - justification: None, - impact_statement: None, - action_statement: None, - by: StatusChange::SCAN_ACTOR.to_string(), - by_name: None, - at: chrono::Utc::now(), - by_scan: true, - }; - let fixed = mongodb::bson::to_bson(&fixed) - .map_err(|e| AgentError::Other(format!("encode VEX: {e}")))?; - let mut unassessed = gone.clone(); - unassessed.insert( - "$or", - mongodb::bson::bson!([ - { "vex": { "$exists": false } }, - { "vex.status": { "$in": ["under_investigation", "affected"] } }, - ]), - ); - let became_fixed = db - .cve_alerts() - .update_many( - unassessed, - doc! { "$set": { "resolved_at": now, "vex": fixed } }, - ) - .await?; let resolved = db .cve_alerts() - .update_many(gone, doc! { "$set": { "resolved_at": now } }) - .await?; - let total = became_fixed.modified_count + resolved.modified_count; - if total > 0 { + .update_many( + doc! { + "repo_id": repo_id, + "cve_id": { "$nin": seen }, + "resolved_at": { "$exists": false }, + }, + doc! { "$set": { "resolved_at": mongodb::bson::DateTime::now() } }, + ) + .await? + .modified_count; + if resolved > 0 { tracing::info!( repo_id, - resolved = total, - fixed_by_scan = became_fixed.modified_count, + resolved, "CVE alerts no longer found marked resolved" ); } - Ok(total) + Ok(resolved) } diff --git a/compliance-agent/tests/vex_lifecycle.rs b/compliance-agent/tests/vex_lifecycle.rs index 9e040a5..d265e7f 100644 --- a/compliance-agent/tests/vex_lifecycle.rs +++ b/compliance-agent/tests/vex_lifecycle.rs @@ -1,7 +1,7 @@ //! #498: a CVE alert's VEX status follows the scans. Gone after a complete -//! lookup, an unassessed or affected alert is `fixed` by the scan, a -//! person's `not_affected` stays; reported again, the scan's `fixed` is -//! withdrawn. A stored alert gets its component's purl on a later scan. An +//! lookup, an alert is resolved and keeps its statement or lack of one: a +//! scan never states `fixed` for a CVE it no longer finds (#994). Reported +//! again, a `fixed` scans inferred that way before is withdrawn. A stored alert gets its component's purl on a later scan. An //! alert `not_affected` or `fixed` raises no notification until the //! statement is withdrawn. //! Runs against a live Mongo (`TEST_MONGODB_URI`) and skips @@ -100,15 +100,12 @@ async fn vex_status_follows_the_scans_but_never_overrides_a_person() { .await .unwrap(); - // Assert: three resolved; the unassessed and the affected one are fixed - // by the scan, the person's not_affected stays. + // Assert: three resolved, and no statement made: the unassessed one has + // none, the person's not_affected and affected stay (#994). assert_eq!(resolved, 3); let one = stored(&db, "CVE-1").await; assert!(one.resolved_at.is_some()); - assert_eq!( - one.vex.as_ref().map(|v| (v.status, v.by_scan)), - Some((VexStatus::Fixed, true)) - ); + assert!(one.vex.is_none(), "{:?}", one.vex); let two = stored(&db, "CVE-2").await; assert!(two.resolved_at.is_some()); assert_eq!( @@ -117,12 +114,27 @@ async fn vex_status_follows_the_scans_but_never_overrides_a_person() { ); assert_eq!( stored(&db, "CVE-3").await.vex.map(|v| v.status), - Some(VexStatus::Fixed) + Some(VexStatus::Affected) ); assert!(stored(&db, "CVE-4").await.resolved_at.is_none()); - // Reported again: open, and the scan's `fixed` is withdrawn; the - // person's statement is kept. + // Reported again: open, and the `fixed` a scan inferred before #994 is + // withdrawn; the person's statement is kept. + let inferred = VexAssessment { + justification: None, + action_statement: None, + by: "pruefwerk-scan".into(), + by_name: None, + by_scan: true, + ..by_person(VexStatus::Fixed) + }; + db.cve_alerts() + .update_one( + doc! { "cve_id": "CVE-1" }, + doc! { "$set": { "vex": mongodb::bson::to_bson(&inferred).unwrap() } }, + ) + .await + .unwrap(); upsert_reported(&db, &alert("CVE-1")).await.unwrap(); upsert_reported(&db, &alert("CVE-2")).await.unwrap(); let one = stored(&db, "CVE-1").await; diff --git a/compliance-core/src/csaf_docs.rs b/compliance-core/src/csaf_docs.rs index 05e7fd1..e95ebdb 100644 --- a/compliance-core/src/csaf_docs.rs +++ b/compliance-core/src/csaf_docs.rs @@ -200,7 +200,9 @@ fn vulnerability( let product = in_product(id); let status = status_of(alert); push_product(&mut v, "product_status", status_key(status), &product); - let Some(vex) = &alert.vex else { continue }; + let Some(vex) = alert.statement() else { + continue; + }; match status { VexStatus::NotAffected => { if let Some(justification) = vex.justification { diff --git a/compliance-core/src/cve_groups.rs b/compliance-core/src/cve_groups.rs index 5c71628..caff521 100644 --- a/compliance-core/src/cve_groups.rs +++ b/compliance-core/src/cve_groups.rs @@ -130,9 +130,10 @@ impl PackageKey { } /// Whether `alert` still asks for a decision: neither stated `not_affected` -/// or `fixed`, nor found gone by a complete scan. +/// or `fixed`, nor found gone by a complete scan. Gone is not `fixed` +/// (#994); it only takes the alert off the list. pub fn is_open(alert: &CveAlert) -> bool { - !status_of(alert).resolves() + alert.resolved_at.is_none() && !status_of(alert).resolves() } /// The open CVE alerts of one component. diff --git a/compliance-core/src/enisa_docs.rs b/compliance-core/src/enisa_docs.rs index 0ece5f3..ef22c8f 100644 --- a/compliance-core/src/enisa_docs.rs +++ b/compliance-core/src/enisa_docs.rs @@ -142,9 +142,12 @@ pub enum Reportability { NotExploited, /// The manufacturer stated the product is not affected. NotAffected, - /// The product no longer contains the vulnerable component or version, - /// and no scan found it exploited while it did. + /// Stated `fixed` (VEX), and no scan found it exploited before. Fixed, + /// A complete scan no longer finds it and no scan found it exploited + /// before, but nobody stated it `fixed`: that it is gone is no evidence + /// of a fix (#994). + NoLongerFound, } impl Reportability { @@ -156,9 +159,10 @@ impl Reportability { } Self::NotExploited => "not known to be actively exploited", Self::NotAffected => "the product is not affected (VEX not_affected)", - Self::Fixed => { - "the product no longer contains the vulnerable component (VEX fixed), and no \ - scan found it exploited before" + Self::Fixed => "stated fixed (VEX fixed), and no scan found it exploited before", + Self::NoLongerFound => { + "a complete scan no longer finds it and no scan found it exploited before; \ + nobody has stated it fixed, so this says nothing about a fix" } } } @@ -174,10 +178,16 @@ pub fn reportability(alert: &CveAlert) -> Reportability { .exploitation .as_ref() .is_some_and(|e| e.actively_exploited()); + let seen_exploited = alert.exploited_seen_at.is_some(); match (exploited, status_of(alert)) { (false, _) => Reportability::NotExploited, (true, VexStatus::NotAffected) => Reportability::NotAffected, - (true, VexStatus::Fixed) if alert.exploited_seen_at.is_none() => Reportability::Fixed, + (true, VexStatus::Fixed) if !seen_exploited => Reportability::Fixed, + (true, VexStatus::Affected | VexStatus::UnderInvestigation) + if !seen_exploited && alert.resolved_at.is_some() => + { + Reportability::NoLongerFound + } (true, VexStatus::Affected | VexStatus::UnderInvestigation | VexStatus::Fixed) => { Reportability::Reportable } @@ -185,17 +195,13 @@ pub fn reportability(alert: &CveAlert) -> Reportability { } /// When the fix became available, as far as Prüfwerk knows: when a person -/// stated `fixed`, else when a scan found the component gone. +/// stated `fixed`. A scan finding the component gone dates no fix (#994), +/// so without the statement the final report has no deadline yet. fn fixed_at(alert: &CveAlert) -> Option> { - if status_of(alert) != VexStatus::Fixed { - return None; - } alert - .vex - .as_ref() + .statement() .filter(|v| v.status == VexStatus::Fixed && !v.by_scan) .map(|v| v.at) - .or(alert.resolved_at) } /// The alerts of one vulnerability, grouped by CVE ([`CveAlert::cve`]): a @@ -297,8 +303,7 @@ pub struct EnisaInput<'a> { /// the fixed version. fn user_measures(alert: &CveAlert) -> Option { alert - .vex - .as_ref() + .statement() .and_then(|v| v.action_statement.clone()) .or_else(|| { (!alert.fixed_versions.is_empty()).then(|| { @@ -389,7 +394,7 @@ fn value(nr: &str, input: &EnisaInput<'_>) -> Option { "12" => text(components(alerts)), "14" | "17" => joined(alerts, user_measures).and_then(text), "16" => joined(alerts, |a| { - a.vex.as_ref().and_then(|v| v.action_statement.clone()) + a.statement().and_then(|v| v.action_statement.clone()) }) .and_then(text), "v19" => cve.starts_with("CVE-").then(|| serde_json::json!(cve)), @@ -422,8 +427,7 @@ fn value(nr: &str, input: &EnisaInput<'_>) -> Option { }) } "v25" => joined(alerts, |a| { - a.vex - .as_ref() + a.statement() .and_then(|v| v.impact_statement.clone()) .or_else(|| a.llm_impact_summary.clone()) }) @@ -553,20 +557,66 @@ mod tests { assert_eq!(reportability(&a), Reportability::NotAffected); a.vex = None; a.resolved_at = Some(Utc::now()); + // Gone from the scan is no fix (#994), and no reason to report. + assert_eq!(reportability(&a), Reportability::NoLongerFound); + a.vex = Some(statement(VexStatus::Fixed)); assert_eq!(reportability(&a), Reportability::Fixed); // Found exploited while the product contained it: the final report // is still due. a.exploited_seen_at = Some(at("2026-10-06T08:00:00Z")); assert_eq!(reportability(&a), Reportability::Reportable); + a.vex = None; + assert_eq!(reportability(&a), Reportability::Reportable); a.exploitation = None; assert_eq!(reportability(&a), Reportability::NotExploited); } + /// The final report's draft of `a`, aware at the first exploitation. + fn final_report_draft(a: &CveAlert) -> serde_json::Value { + draft(&EnisaInput { + product: "Pump Remote", + manufacturer: "example-pumps", + tooling: "Prüfwerk test", + alerts: &[a], + aware_at: at("2026-10-01T08:00:00Z"), + now: at("2026-10-06T09:00:00Z"), + }) + } + + /// The final report's due date while no fix is dated. + const UNDATED_FINAL_REPORT: &str = "14 days after the date in field v22"; + + #[test] + fn a_vulnerability_a_scan_no_longer_finds_dates_no_final_report() { + let mut a = alert(); + a.exploited_seen_at = Some(at("2026-10-01T08:00:00Z")); + a.resolved_at = Some(at("2026-10-05T10:00:00Z")); + let doc = final_report_draft(&a); + assert_eq!(doc["due"]["final_report"], UNDATED_FINAL_REPORT); + + // Nor does a `fixed` a scan inferred from that before #994. + a.vex = Some(VexAssessment { + impact_statement: None, + by: "pruefwerk-scan".into(), + by_scan: true, + at: at("2026-10-05T10:00:00Z"), + ..statement(VexStatus::Fixed) + }); + assert_eq!(fixed_at(&a), None); + assert_eq!(status_of(&a), VexStatus::UnderInvestigation); + let doc = final_report_draft(&a); + assert_eq!(doc["due"]["final_report"], UNDATED_FINAL_REPORT); + } + #[test] fn a_fixed_vulnerability_dates_its_final_report() { let mut a = alert(); a.exploited_seen_at = Some(at("2026-10-01T08:00:00Z")); - a.resolved_at = Some(at("2026-10-05T10:00:00Z")); + a.resolved_at = Some(at("2026-10-04T10:00:00Z")); + a.vex = Some(VexAssessment { + at: at("2026-10-05T10:00:00Z"), + ..statement(VexStatus::Fixed) + }); let doc = draft(&EnisaInput { product: "Pump Remote", manufacturer: "example-pumps", diff --git a/compliance-core/src/models/cve.rs b/compliance-core/src/models/cve.rs index c68a240..fccc0ec 100644 --- a/compliance-core/src/models/cve.rs +++ b/compliance-core/src/models/cve.rs @@ -203,13 +203,30 @@ impl CveAlert { ids } - /// Whether a VEX statement settles the alert: `not_affected` or `fixed`, - /// stated by a person, by the scan or in an imported VEX document. Such an - /// alert raises no notification and keeps no open tracker issue; once the - /// statement is withdrawn (back to `affected`, `under_investigation` or - /// none) it counts again. + /// The alert's VEX statement, by a person, by a scan from the target's + /// own data or in an imported VEX document. A `fixed` a scan inferred + /// from the CVE no longer being found is none + /// ([`super::vex::VexAssessment::is_inferred_from_absence`], #994). + pub fn statement(&self) -> Option<&super::vex::VexAssessment> { + self.vex + .as_ref() + .filter(|vex| !vex.is_inferred_from_absence()) + } + + /// Drop a `fixed` inferred from absence (see [`Self::statement`]), so a + /// client shown the stored alert does not read it as a statement. + pub fn drop_inferred_fix(&mut self) { + if self.statement().is_none() { + self.vex = None; + } + } + + /// Whether a VEX statement ([`Self::statement`]) settles the alert: + /// `not_affected` or `fixed`. Such an alert raises no notification and + /// keeps no open tracker issue; once the statement is withdrawn (back to + /// `affected`, `under_investigation` or none) it counts again. pub fn is_resolved_by_vex(&self) -> bool { - self.vex.as_ref().is_some_and(|vex| vex.status.resolves()) + self.statement().is_some_and(|vex| vex.status.resolves()) } pub fn new( @@ -285,6 +302,35 @@ mod tests { } } + #[test] + fn a_fixed_inferred_from_absence_is_no_statement() { + use crate::models::vex::{VexAssessment, VexStatus}; + let scan_fixed = |impact_statement: Option<&str>| VexAssessment { + status: VexStatus::Fixed, + justification: None, + impact_statement: impact_statement.map(String::from), + action_statement: None, + by: "pruefwerk-scan".into(), + by_name: None, + at: Utc::now(), + by_scan: true, + }; + // What scans stated for a CVE they no longer found (#994). + let mut a = alert("CVE-2021-44228", &[]); + a.vex = Some(scan_fixed(None)); + assert!(a.statement().is_none()); + assert!(!a.is_resolved_by_vex()); + a.drop_inferred_fix(); + assert!(a.vex.is_none()); + // A Yocto recipe's patch gives its reason: a statement. + let recipe = scan_fixed(Some("Patched in the recipe (CVE: tag).")); + a.vex = Some(recipe.clone()); + assert_eq!(a.statement(), Some(&recipe)); + assert!(a.is_resolved_by_vex()); + a.drop_inferred_fix(); + assert_eq!(a.vex, Some(recipe)); + } + #[test] fn a_cve_is_strictly_recognised() { assert!(is_cve("CVE-2021-44228")); diff --git a/compliance-core/src/models/vex.rs b/compliance-core/src/models/vex.rs index 20908c7..b993dd3 100644 --- a/compliance-core/src/models/vex.rs +++ b/compliance-core/src/models/vex.rs @@ -89,7 +89,9 @@ pub struct VexAssessment { pub by_name: Option, #[serde(with = "super::serde_helpers::bson_datetime")] pub at: DateTime, - /// Set by a scan (a `fixed` because the component is gone), not a person. + /// Set by a scan from the target's own data (a Yocto recipe's + /// `CVE_STATUS` or patch), not a person. Before #994 also a `fixed` for + /// a CVE a scan no longer found ([`Self::is_inferred_from_absence`]). #[serde(default)] pub by_scan: bool, } @@ -104,6 +106,16 @@ pub enum VexError { } impl VexAssessment { + /// Whether this is a `fixed` that a scan stated only because a complete + /// scan no longer found the CVE, as scans did before #994. A CVE can + /// disappear without a fix (other scan data, an incomplete inventory, a + /// changed identification), so nothing reads such a statement as one. A + /// scan's statement from the target's own data always gives its reason + /// (`impact_statement`), so it is never one of them. + pub fn is_inferred_from_absence(&self) -> bool { + self.by_scan && self.status == VexStatus::Fixed && self.impact_statement.is_none() + } + /// Check what OpenVEX requires of a statement: a reason for /// `not_affected`, and (stricter than OpenVEX, as CISA recommends) an /// action for `affected`. diff --git a/compliance-core/src/vex_docs.rs b/compliance-core/src/vex_docs.rs index 42fc192..a67992d 100644 --- a/compliance-core/src/vex_docs.rs +++ b/compliance-core/src/vex_docs.rs @@ -2,8 +2,10 @@ //! known vulnerability of its components, in OpenVEX 0.2.0 and in CycloneDX //! 1.6 (the SBOM with its vulnerabilities and their analysis). //! -//! An alert nobody assessed is `under_investigation`; one a complete scan no -//! longer finds is `fixed`. The CycloneDX analysis uses CycloneDX's terms: +//! An alert nobody assessed is `under_investigation`, also when a complete +//! scan no longer finds it: a CVE can disappear without a fix, so only a +//! statement says `fixed` (#994). The CycloneDX analysis uses CycloneDX's +//! terms: //! //! | OpenVEX | CycloneDX | //! |---|---| @@ -42,14 +44,13 @@ pub struct VexInput<'a> { pub now: DateTime, } -/// The status an alert is stated with: its VEX statement's, `fixed` once a -/// complete scan found it gone, else `under_investigation`. +/// The status an alert is stated with: its VEX statement's +/// ([`CveAlert::statement`]), else `under_investigation`. A CVE a complete +/// scan no longer finds is not thereby `fixed` (#994). pub fn status_of(alert: &CveAlert) -> VexStatus { - match (&alert.vex, alert.resolved_at) { - (Some(vex), _) => vex.status, - (None, Some(_)) => VexStatus::Fixed, - (None, None) => VexStatus::UnderInvestigation, - } + alert + .statement() + .map_or(VexStatus::UnderInvestigation, |vex| vex.status) } /// The SBOM entry an alert is about, if it is in the SBOM. @@ -105,10 +106,7 @@ impl Statement<'_> { /// the same component: an explicit statement (the latest one) over none, /// then an open alert over a resolved one. fn weight(alert: &CveAlert) -> (Option>, bool) { - ( - alert.vex.as_ref().map(|v| v.at), - alert.resolved_at.is_none(), - ) + (alert.statement().map(|v| v.at), alert.resolved_at.is_none()) } /// The statements of `input`, one per CVE and component in the order the @@ -169,7 +167,7 @@ pub fn openvex(input: &VexInput<'_>) -> serde_json::Value { }], "status": status, }); - if let Some(vex) = &alert.vex { + if let Some(vex) = alert.statement() { statement["timestamp"] = serde_json::json!(rfc3339(vex.at)); if let Some(j) = vex.justification { statement["justification"] = serde_json::json!(j); @@ -253,7 +251,7 @@ pub fn cyclonedx_vex(input: &VexInput<'_>) -> serde_json::Value { } let status = status_of(alert); let mut analysis = serde_json::json!({ "state": cdx_state(status) }); - if let Some(vex) = &alert.vex { + if let Some(vex) = alert.statement() { if let Some(j) = vex.justification { analysis["justification"] = serde_json::json!(cdx_justification(j)); } diff --git a/compliance-core/tests/vex_schemas.rs b/compliance-core/tests/vex_schemas.rs index 6c385c9..ade66a8 100644 --- a/compliance-core/tests/vex_schemas.rs +++ b/compliance-core/tests/vex_schemas.rs @@ -135,12 +135,13 @@ fn alerts() -> Vec { s.justification = Some(VexJustification::VulnerableCodeNotInExecutePath); s.impact_statement = Some("template() is never called.".into()); not_affected.vex = Some(s); - let mut gone = alert("CVE-2020-0001", "zlib", "1.2.11"); - gone.resolved_at = Some(Utc::now()); + let mut fixed = alert("CVE-2020-0001", "zlib", "1.2.11"); + fixed.resolved_at = Some(Utc::now()); + fixed.vex = Some(statement(VexStatus::Fixed)); vec![ affected, not_affected, - gone, + fixed, alert("CVE-2024-0002", "PumpSDK", "3.1.0"), ] } @@ -436,8 +437,10 @@ fn a_fixed_component_that_left_the_sbom_keeps_its_stored_purl() { let mut log4j = alert("CVE-2021-44228", "log4j-core", "2.14.1"); log4j.purl = Some(maven.into()); log4j.resolved_at = Some(Utc::now()); + log4j.vex = Some(statement(VexStatus::Fixed)); let mut old = alert("CVE-2020-0001", "zlib", "1.2.11"); old.resolved_at = Some(Utc::now()); + old.vex = Some(statement(VexStatus::Fixed)); let alerts = vec![log4j, old]; let input = vex_input(&alerts, &sbom); @@ -621,3 +624,38 @@ fn the_cyclonedx_sbom_lists_a_vulnerability_under_its_cve_once() { assert_eq!(vulns[1]["source"]["name"], "osv"); assert!(vulns[1].get("references").is_none()); } + +#[test] +fn a_cve_a_scan_no_longer_finds_is_not_stated_fixed() { + // Arrange (#994): one alert gone without a statement (Weg B), one with + // the `fixed` scans inferred from that before (Weg A). + let mut unstated = alert("CVE-2020-0001", "zlib", "1.2.11"); + unstated.resolved_at = Some(Utc::now()); + let mut inferred = alert("CVE-2021-44228", "log4j-core", "2.14.1"); + inferred.resolved_at = Some(Utc::now()); + inferred.vex = Some(VexAssessment { + by: "pruefwerk-scan".into(), + by_name: None, + by_scan: true, + ..statement(VexStatus::Fixed) + }); + let (alerts, sbom) = (vec![unstated, inferred], sbom()); + let input = vex_input(&alerts, &sbom); + + // Act + let openvex = vex_docs::openvex(&input); + let cdx = vex_docs::cyclonedx_vex(&input); + let csaf = csaf_docs::csaf_vex(&input, "https://example.invalid/pumps", "en"); + + // Assert: under investigation in every format, never fixed. + assert_eq!(openvex_errors(&openvex), Vec::::new()); + assert_eq!(cyclonedx_errors(&cdx), Vec::::new()); + assert_eq!(csaf_errors(&csaf), Vec::::new()); + for i in 0..2 { + assert_eq!(openvex["statements"][i]["status"], "under_investigation"); + assert_eq!(cdx["vulnerabilities"][i]["analysis"]["state"], "in_triage"); + let status = &csaf["vulnerabilities"][i]["product_status"]; + assert!(status["fixed"].is_null(), "{status}"); + assert!(status["under_investigation"].is_array(), "{status}"); + } +} diff --git a/compliance-mcp/src/tools/targets.rs b/compliance-mcp/src/tools/targets.rs index 172b92b..d3ab747 100644 --- a/compliance-mcp/src/tools/targets.rs +++ b/compliance-mcp/src/tools/targets.rs @@ -109,9 +109,10 @@ pub struct ListCvesParams { } /// `list_cves`: the CVE alerts of a target's dependencies and firmware -/// libraries, highest CVSS first. +/// libraries, highest CVSS first, without a `fixed` a scan inferred from a +/// CVE no longer being found (#994). pub async fn list_cves(db: &Database, params: ListCvesParams) -> Result { - let alerts = collect( + let mut alerts: Vec = collect( db.cve_alerts() .find(doc! { "repo_id": ¶ms.target_id }) .sort(doc! { "cvss_score": -1 }) @@ -119,6 +120,9 @@ pub async fn list_cves(db: &Database, params: ListCvesParams) -> Result