From ffcd555324e1301f690c45417961fe22631e1692 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 1/2] 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 6686a13..b504a12 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 b30f68e..459b002 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; @@ -308,6 +310,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. @@ -324,52 +331,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 88302a0..be6395b 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 c97090a..465a27f 100644 --- a/compliance-core/src/cve_groups.rs +++ b/compliance-core/src/cve_groups.rs @@ -141,9 +141,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 c732770..515f480 100644 --- a/compliance-core/src/models/cve.rs +++ b/compliance-core/src/models/cve.rs @@ -209,13 +209,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( @@ -292,6 +309,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 c40c871..d268b77 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, } @@ -142,6 +144,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 a3a2696..63d08fd 100644 --- a/compliance-core/tests/vex_schemas.rs +++ b/compliance-core/tests/vex_schemas.rs @@ -111,12 +111,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"), ] } @@ -412,8 +413,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); @@ -597,3 +600,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 Date: Fri, 27 Nov 2026 20:28:03 +0100 Subject: [PATCH 2/2] fix(vex): an issue whose CVE is gone stays open, told so once (#994) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A complete scan that no longer finds a CVE closed its tracker issue. A CVE can disappear without a fix, so the issue now stays open and gets one comment saying the scan no longer finds it and that a person checks and closes it (in Prüfwerk with the VEX status "Behoben" and a reason). TrackerIssue::gone_noted_at keeps it to one comment while the CVE stays gone; when the CVE is found again it is cleared, so a later disappearance is told again. Docs (managed git, issues) say the same. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9 --- compliance-agent/src/pipeline/cve_issues.rs | 118 ++++++++++++++---- .../src/pipeline/issue_creation.rs | 5 +- compliance-core/src/models/issue.rs | 10 ++ docs/guide/issues.md | 2 +- docs/guide/managed-git-en.md | 7 +- docs/guide/managed-git.md | 8 +- 6 files changed, 115 insertions(+), 35 deletions(-) diff --git a/compliance-agent/src/pipeline/cve_issues.rs b/compliance-agent/src/pipeline/cve_issues.rs index ec13cdc..1fcf067 100644 --- a/compliance-agent/src/pipeline/cve_issues.rs +++ b/compliance-agent/src/pipeline/cve_issues.rs @@ -3,9 +3,10 @@ //! For a target from a managed git source (#439), every critical or high CVE //! in its components becomes one issue per package and CVE, labelled like the //! finding issues plus `cve`, with the fixed version where the advisory names -//! one. When a later complete scan no longer finds the CVE (the dependency was -//! updated or removed), the issue is closed with a comment; when it comes back, -//! it is reopened. +//! one. When a later complete scan no longer finds the CVE, the issue stays +//! open and is told so once (#994): a CVE can disappear without a fix (other +//! scan data, a changed identification), so a person checks and closes it. +//! When the CVE comes back, the next disappearance is told again. //! //! An issue a person closed in Gitea (#953) stays closed while the scan still //! finds its CVE: closing it was that person's call, and no VEX statement is @@ -96,6 +97,8 @@ pub(crate) struct CveIssueCounts { pub created: u32, pub reopened: u32, pub closed: u32, + /// Open issues told that the scan no longer finds their CVE. + pub noted_gone: u32, } /// The key a CVE issue is stored under (`TrackerIssue::finding_id`): one per @@ -165,7 +168,8 @@ fn issue_worthy(alert: &CveAlert, epss_percentile: Option) -> bool { /// its stored VEX statement /// ([`crate::pipeline::vex_lifecycle::attach_stored_vex`]) /// * `complete` - whether every component was matched; only then is a CVE -/// that is missing from `alerts` known to be gone, and its issue closed +/// that is missing from `alerts` known to be gone, and its open issue told +/// so (once; it stays open) /// /// # Errors /// @@ -203,6 +207,11 @@ pub(crate) async fn sync_cve_issues( match existing.get(key) { // A person closed it in Gitea while the CVE is unchanged. Some(issue) if issue.closed_in_tracker.is_some() => {} + // Found again after it was gone: a later disappearance is told + // again. + Some(issue) if issue.gone_noted_at.is_some() && !issue.status.is_closed() => { + note_gone(target.db, issue, false).await?; + } Some(issue) if issue.status.is_closed() => { let comment = "**Prüfwerk:** Bei der Prüfung erneut gefunden, daher wieder geöffnet.\n\nFound again by the scan, so reopened."; if set_state(target, issue, comment, "open").await { @@ -242,10 +251,22 @@ pub(crate) async fn sync_cve_issues( } continue; } - let comment = "**Prüfwerk:** Die Prüfung findet diese Schwachstelle nicht mehr: Die Abhängigkeit wurde aktualisiert oder entfernt.\n\nThe scan no longer finds this vulnerability: the dependency was updated or removed."; - if set_state(target, issue, comment, "closed").await { - record(target.db, issue, IssueStatus::Closed).await?; - counts.closed += 1; + if issue.gone_noted_at.is_some() { + continue; + } + let number = issue.external_id.as_str(); + match target + .tracker + .add_comment(target.owner, target.repo, number, GONE_COMMENT) + .await + { + Ok(()) => { + note_gone(target.db, issue, true).await?; + counts.noted_gone += 1; + } + Err(e) => { + tracing::warn!(issue = number, error = %e, "could not comment on the CVE issue"); + } } } } @@ -505,6 +526,27 @@ async fn set_state( } } +/// The comment an open issue gets once when a complete scan no longer finds +/// its CVE. It stays open: that the CVE is gone is no proof of a fix (#994). +const GONE_COMMENT: &str = "**Prüfwerk:** Die Prüfung findet diese Schwachstelle nicht mehr. Das allein belegt keine Behebung: Bitte prüfen Sie, ob sie behoben ist, und schließen Sie das Issue dann selbst. In Prüfwerk können Sie dazu den VEX-Status \"Behoben\" mit Begründung setzen.\n\nThe scan no longer finds this vulnerability. That alone does not prove a fix: please check whether it is fixed and close the issue yourself. In Prüfwerk you can set the VEX status \"fixed\" with a reason."; + +/// Store that `issue` was told its CVE is gone (`gone`), or that the CVE was +/// found again. +async fn note_gone(db: &Database, issue: &TrackerIssue, gone: bool) -> Result<(), AgentError> { + let Some(id) = issue.id else { + return Ok(()); + }; + let update = if gone { + doc! { "$set": { "gone_noted_at": mongodb::bson::DateTime::now() } } + } else { + doc! { "$unset": { "gone_noted_at": "" } } + }; + db.tracker_issues() + .update_one(doc! { "_id": id }, update) + .await?; + Ok(()) +} + /// Store an issue's new state. async fn record( db: &Database, @@ -719,7 +761,7 @@ mod tests { } #[tokio::test] - async fn severe_cves_open_issues_that_close_when_the_dependency_is_fixed() { + async fn severe_cves_open_issues_a_person_closes_once_the_cve_is_gone() { let uri = std::env::var("TEST_MONGODB_URI") .unwrap_or_else(|_| "mongodb://root:example@localhost:27017/?authSource=admin".into()); let prefix = format!( @@ -783,30 +825,50 @@ mod tests { CveIssueCounts::default() ); - // The dependency is updated: the complete scan finds it no more. + // The complete scan finds it no more: the issue is told so once and + // stays open, since a CVE that is gone is no proof of a fix (#994). + let noted = CveIssueCounts { + noted_gone: 1, + ..Default::default() + }; assert_eq!( - sync_cve_issues(&target, &[minor], true).await.unwrap(), - CveIssueCounts { - closed: 1, - ..Default::default() - } + sync_cve_issues(&target, std::slice::from_ref(&minor), true) + .await + .unwrap(), + noted ); + { + let calls = calls.lock().unwrap(); + let last = calls.last().unwrap(); + assert!( + last.starts_with("comment 100: ") && last.contains("no longer finds"), + "{last}" + ); + assert!(calls.iter().all(|c| !c.starts_with("state ")), "{calls:?}"); + } + let sent = calls.lock().unwrap().len(); assert_eq!( - calls.lock().unwrap().last().unwrap(), - "state 100: \"closed\"" + sync_cve_issues(&target, std::slice::from_ref(&minor), true) + .await + .unwrap(), + CveIssueCounts::default(), + "told once" ); + assert_eq!(calls.lock().unwrap().len(), sent); - // It comes back: reopened, not opened twice. + // It comes back: the issue is still open, so nothing is sent; gone + // again, it is told again. assert_eq!( sync_cve_issues(&target, std::slice::from_ref(&okhttp), true) .await .unwrap(), - CveIssueCounts { - reopened: 1, - ..Default::default() - } + CveIssueCounts::default() ); - assert_eq!(calls.lock().unwrap().last().unwrap(), "state 100: \"open\""); + assert_eq!(calls.lock().unwrap().len(), sent); + assert_eq!(sync_cve_issues(&target, &[], true).await.unwrap(), noted); + sync_cve_issues(&target, std::slice::from_ref(&okhttp), true) + .await + .unwrap(); // A person closes it in Gitea (#953): the scan that still finds the // CVE leaves it closed and sends nothing. @@ -1025,14 +1087,18 @@ mod tests { } ); - // Gone: closed for being gone, never with a VEX status. + // Gone: never closed, neither for being gone nor with a VEX status; + // the issue is told once that the scan no longer finds the CVE. assert_eq!( sync_cve_issues(&target, &[], true).await.unwrap(), - closed(1) + CveIssueCounts { + noted_gone: 1, + ..Default::default() + } ); { let calls = calls.lock().unwrap(); - assert!(calls.iter().all(|c| !c.contains("VEX")), "{calls:?}"); + assert!(calls.iter().all(|c| !c.starts_with("state ")), "{calls:?}"); assert!( calls.iter().any(|c| c.contains("no longer finds")), "{calls:?}" diff --git a/compliance-agent/src/pipeline/issue_creation.rs b/compliance-agent/src/pipeline/issue_creation.rs index a6adec8..d49fc97 100644 --- a/compliance-agent/src/pipeline/issue_creation.rs +++ b/compliance-agent/src/pipeline/issue_creation.rs @@ -243,10 +243,11 @@ impl CveIssueSync<'_> { let counts = crate::pipeline::cve_issues::sync_cve_issues(&target, alerts, complete).await?; tracing::info!( - "[{repo_id}] CVE issues: {} opened, {} reopened, {} closed", + "[{repo_id}] CVE issues: {} opened, {} reopened, {} closed, {} told the CVE is gone", counts.created, counts.reopened, - counts.closed + counts.closed, + counts.noted_gone ); Ok(()) } diff --git a/compliance-core/src/models/issue.rs b/compliance-core/src/models/issue.rs index 46b446c..fb05cb9 100644 --- a/compliance-core/src/models/issue.rs +++ b/compliance-core/src/models/issue.rs @@ -98,6 +98,15 @@ pub struct TrackerIssue { /// closed: a person's decision the scan does not undo on its own. #[serde(default, skip_serializing_if = "Option::is_none")] pub closed_in_tracker: Option, + /// When a complete scan first no longer found the issue's CVE (#994), + /// while it stays gone: the issue was told so once and stays open, since + /// a CVE that is gone is no proof of a fix. + #[serde( + default, + skip_serializing_if = "Option::is_none", + with = "super::serde_helpers::opt_bson_datetime" + )] + pub gone_noted_at: Option>, #[serde(with = "super::serde_helpers::bson_datetime")] pub created_at: DateTime, #[serde(with = "super::serde_helpers::bson_datetime")] @@ -122,6 +131,7 @@ impl TrackerIssue { title, status: IssueStatus::Open, closed_in_tracker: None, + gone_noted_at: None, created_at: now, updated_at: now, } diff --git a/docs/guide/issues.md b/docs/guide/issues.md index bfce3d4..309ba4a 100644 --- a/docs/guide/issues.md +++ b/docs/guide/issues.md @@ -19,7 +19,7 @@ A scan opens issues only for the findings it finds new, so a finding whose issue ### CVE issues (managed repositories) -For a repository from a managed git source, known vulnerabilities in its dependencies become issues too: one per package and CVE, labelled `cve`. A critical or high CVE opens one, and so does any CVE in CISA's Known Exploited Vulnerabilities catalog (rated at least high). A CVE whose EPSS percentile reaches `CVE_ISSUE_EPSS_PERCENTILE` (default `0.95`) is rated one step higher, so a medium one opens an issue as high. The issue names the KEV entry, the EPSS score with its attribution, and CISA's SSVC exploitation where known. When a complete scan no longer finds the CVE, the issue is closed; when it comes back, it is reopened. A CVE with the VEX status `not_affected` or `fixed` gets no new issue. Its issue that is already open is closed only with `ISSUE_AUTOCLOSE=on`: with a comment naming the status and the justification, at most 20 per target and scan (the rest follow in the next scans). `ISSUE_AUTOCLOSE=dry_run` only logs, per target, how many issues it would close per VEX status, and changes nothing; the default is `off`. When the statement is withdrawn, a closed issue is reopened. +For a repository from a managed git source, known vulnerabilities in its dependencies become issues too: one per package and CVE, labelled `cve`. A critical or high CVE opens one, and so does any CVE in CISA's Known Exploited Vulnerabilities catalog (rated at least high). A CVE whose EPSS percentile reaches `CVE_ISSUE_EPSS_PERCENTILE` (default `0.95`) is rated one step higher, so a medium one opens an issue as high. The issue names the KEV entry, the EPSS score with its attribution, and CISA's SSVC exploitation where known. When a complete scan no longer finds the CVE, the issue stays open and is told so once: a CVE can disappear without a fix, so a person checks and closes it. A closed issue whose CVE comes back is reopened. A CVE with the VEX status `not_affected` or `fixed` gets no new issue. Its issue that is already open is closed only with `ISSUE_AUTOCLOSE=on`: with a comment naming the status and the justification, at most 20 per target and scan (the rest follow in the next scans). `ISSUE_AUTOCLOSE=dry_run` only logs, per target, how many issues it would close per VEX status, and changes nothing; the default is `off`. When the statement is withdrawn, a closed issue is reopened. ### Closing an issue in Gitea diff --git a/docs/guide/managed-git-en.md b/docs/guide/managed-git-en.md index fdc0393..91d1446 100644 --- a/docs/guide/managed-git-en.md +++ b/docs/guide/managed-git-en.md @@ -22,9 +22,10 @@ of an organisation in that instance automatically: - **Known vulnerabilities as issues.** A critical or high CVE in a dependency becomes one issue per package and CVE (`[CVE] okhttp@3.12.0: CVE-2021-0341`), labelled like the findings plus `cve`, with the fixed version where the - advisory names one. When a complete scan no longer finds it (the dependency - was updated or removed), the issue is closed with a comment; if it comes - back, it is reopened. + advisory names one. When a complete scan no longer finds it, the issue stays + open and gets one comment saying so: a CVE can disappear without a fix, so + you check and close it yourself (in Prüfwerk, set the VEX status "fixed" + with a reason). If it comes back and goes again, it is told again. - **The issue follows the finding.** When the finding is closed in Prüfwerk — the scan no longer finds it, or someone marks it resolved, a false alarm or ignored — Prüfwerk comments on the issue why and closes it. An accepted risk diff --git a/docs/guide/managed-git.md b/docs/guide/managed-git.md index c110721..507d33c 100644 --- a/docs/guide/managed-git.md +++ b/docs/guide/managed-git.md @@ -24,9 +24,11 @@ Repository-Organisation dieser Instanz automatisch prüfen: Abhängigkeit wird ein Issue je Paket und CVE (`[CVE] okhttp@3.12.0: CVE-2021-0341`), mit denselben Labels wie die Befunde plus `cve` und der behebenden Version, wenn die Meldung eine nennt. Findet - eine vollständige Prüfung sie nicht mehr (Abhängigkeit aktualisiert oder - entfernt), wird das Issue mit Kommentar geschlossen; taucht sie wieder auf, - wird es wieder geöffnet. + eine vollständige Prüfung sie nicht mehr, bleibt das Issue offen und erhält + einmal einen Kommentar dazu: Eine CVE kann auch ohne Behebung verschwinden, + deshalb prüfen und schließen Sie es selbst (im Prüfwerk mit dem VEX-Status + „Behoben“ und Begründung). Taucht sie wieder auf und verschwindet erneut, + kommt der Hinweis noch einmal. - **Das Issue folgt dem Befund.** Wird der Befund im Prüfwerk geschlossen – die Prüfung findet ihn nicht mehr, oder jemand setzt ihn auf behoben, Fehlalarm oder ignoriert –, kommentiert Prüfwerk im Issue den Grund und -- 2.54.1