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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
This commit is contained in:
1 parent
f5848f7bad
commit
63eebef021
16 files changed
+380
-130
No files matched your search
@@ -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<Vec<CveAlert>> {
|
||||
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,
|
||||
|
||||
@@ -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<Mutex<Vec<u8>>>, tracing::subscriber::DefaultGuard) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user