fix(vex): a CVE a scan no longer finds is not stated fixed (#994)
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Agent integration (pull_request) Successful in 4m31s
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 21m22s

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:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-11-16 16:47:58 +01:00
1 parent 141176df20
commit 5367c386b2
16 files changed
+380 -130

No files matched your search

+4 -2
View File
@@ -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) {
+25 -45
View File
@@ -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)
}
+24 -12
View File
@@ -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;
+3 -1
View File
@@ -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 {
+3 -2
View File
@@ -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.
+69 -19
View File
@@ -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<DateTime<Utc>> {
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<String> {
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<serde_json::Value> {
"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<serde_json::Value> {
})
}
"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",
+52 -6
View File
@@ -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"));
+13 -1
View File
@@ -89,7 +89,9 @@ pub struct VexAssessment {
pub by_name: Option<String>,
#[serde(with = "super::serde_helpers::bson_datetime")]
pub at: DateTime<Utc>,
/// 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`.
+13 -15
View File
@@ -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<Utc>,
}
/// 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<DateTime<Utc>>, 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));
}
+41 -3
View File
@@ -135,12 +135,13 @@ fn alerts() -> Vec<CveAlert> {
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::<String>::new());
assert_eq!(cyclonedx_errors(&cdx), Vec::<String>::new());
assert_eq!(csaf_errors(&csaf), Vec::<String>::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}");
}
}
+6 -2
View File
@@ -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<CallToolResult, McpError> {
let alerts = collect(
let mut alerts: Vec<compliance_core::models::CveAlert> = collect(
db.cve_alerts()
.find(doc! { "repo_id": &params.target_id })
.sort(doc! { "cvss_score": -1 })
@@ -119,6 +120,9 @@ pub async fn list_cves(db: &Database, params: ListCvesParams) -> Result<CallTool
.map_err(db_error)?,
)
.await?;
alerts
.iter_mut()
.for_each(compliance_core::models::CveAlert::drop_inferred_fix);
json_result(&alerts)
}
+6 -5
View File
@@ -450,11 +450,12 @@ Justifications for `not_affected` (OpenVEX): `component_not_present`,
`inline_mitigations_already_exist`. A statement without what its status
requires is refused.
A scan keeps the status current: when a complete CVE check no longer finds an
alert (the component was removed or updated past the fix), it is marked
resolved, and one nobody assessed, or assessed as affected, becomes `fixed`.
A `not_affected` or `fixed` someone stated is never changed by a scan. If the
vulnerability comes back, the scan's `fixed` is withdrawn. A Yocto recipe's
When a complete CVE check no longer finds an alert, it is marked resolved and
keeps its status: a scan never states `fixed` for it, since a vulnerability
can disappear without a fix. An alert nobody assessed stays
`under_investigation` in the exports until someone states its status. A
`fixed` scans stated that way before is not read as a statement. A statement
someone made is never changed by a scan. A Yocto recipe's
`CVE_STATUS` and `CVE:` patches are stated by the scan too (see
[Embedded Linux / Yocto](/guide/yocto#recipe-inventory)), likewise never over a
person's statement.
+11 -8
View File
@@ -55,10 +55,12 @@ Read-only roles see the statements but cannot assess.
## What a scan changes
When a complete scan no longer finds a vulnerability (the component was
removed or updated), it is marked fixed and "Stated by" shows **Scan**. A
"Not affected" or "Fixed" stated by a person is never changed by a scan. If
the vulnerability comes back, the scan withdraws its "Fixed".
When a complete scan no longer finds a vulnerability, it is no longer open,
and its assessment stays as it is. A scan never states "Fixed" for it: a
vulnerability can disappear without a fix, for example through other scan
data, an incomplete inventory or a changed identification. Only a person
states "Fixed". A "Fixed" a scan stated that way before is not read as a
statement. A statement made by a person is never changed by a scan.
A vulnerability that is "Not affected" or "Fixed" (stated by a person, by the
scan or in an imported VEX document) raises no notification and gets no issue
@@ -142,10 +144,11 @@ CVE) or it affects several components. The draft
yourself, through the CSIRT of your main establishment.
Through the API you can give the time the deadlines run from (`aware_at`);
without it, the first scan that found the exploitation counts. For a fixed
vulnerability the draft carries the date of the fix (field v22) and the final
report's deadline. A vulnerability assessed "Not affected", or fixed before
any scan found it exploited, gets no draft. Actively
without it, the first scan that found the exploitation counts. For a vulnerability
assessed "Fixed" the draft carries the date of that statement (field v22) and
the final report's deadline. One a scan only no longer finds leaves both open
until someone states "Fixed". A vulnerability assessed "Not affected", or
fixed or no longer found before any scan found it exploited, gets no draft. Actively
exploited vulnerabilities are also in the evidence pack as
`enisa-drafts.json`. When ENISA changes the glossary we update the fields;
the version in a draft shows which one it follows.
+12 -9
View File
@@ -58,11 +58,13 @@ Rollen mit Lesezugriff sehen die Aussagen, können aber nicht bewerten.
## Was die Prüfung ändert
Findet eine vollständige Prüfung eine Schwachstelle nicht mehr (Komponente
entfernt oder aktualisiert), wird sie als behoben markiert; „Aussage von“
zeigt dann **Prüfung**. Eine Aussage „Nicht betroffen“ oder „Behoben“, die
eine Person gemacht hat, ändert die Prüfung nie. Taucht die Schwachstelle
wieder auf, nimmt die Prüfung ihr „Behoben“ zurück.
Findet eine vollständige Prüfung eine Schwachstelle nicht mehr, gilt sie
nicht mehr als offen; ihre Bewertung bleibt, wie sie ist. Die Prüfung setzt
dafür nie „Behoben“: Eine Schwachstelle kann auch ohne Behebung
verschwinden, etwa durch andere Scandaten, eine unvollständige Erfassung oder
eine geänderte Zuordnung. „Behoben“ sagt nur eine Person. Ein „Behoben“, das
die Prüfung früher so gesetzt hat, gilt nicht als Aussage. Eine Aussage, die
eine Person gemacht hat, ändert die Prüfung nie.
Eine Schwachstelle mit „Nicht betroffen“ oder „Behoben“ (von einer Person,
der Prüfung oder aus einem importierten VEX-Dokument) löst keine
@@ -151,10 +153,11 @@ die CVE dazu) oder sie mehrere Komponenten betrifft. Der Entwurf
Den Zeitpunkt, ab dem die Fristen laufen, können Sie über die API angeben
(`aware_at`); ohne ihn gilt die erste Prüfung, die die Ausnutzung fand. Ist
eine behobene Schwachstelle bekannt, trägt der Entwurf das Datum der Behebung
(Feld v22) und die Frist des Abschlussberichts. Ist sie als „Nicht
betroffen“ bewertet, oder wurde sie behoben, bevor eine Prüfung ihre
Ausnutzung fand, gibt es keinen Entwurf. Aktiv ausgenutzte Schwachstellen stehen als
eine Schwachstelle als „Behoben“ bewertet, trägt der Entwurf das Datum dieser
Aussage (Feld v22) und die Frist des Abschlussberichts. Findet die Prüfung sie
nur nicht mehr, bleibt beides offen, bis jemand „Behoben“ sagt. Ist sie als
„Nicht betroffen“ bewertet, oder wurde sie behoben oder nicht mehr gefunden,
bevor eine Prüfung ihre Ausnutzung fand, gibt es keinen Entwurf. Aktiv ausgenutzte Schwachstellen stehen als
`enisa-drafts.json` auch im Nachweispaket. Ändert ENISA das Glossar,
passen wir die Felder an; die Version im Entwurf zeigt, nach welchem er
erstellt wurde.
+53
View File
@@ -0,0 +1,53 @@
// #994: count, and only on request remove, the VEX `fixed` statements that
// scans inferred from a CVE no longer being found (before the fix, Weg A).
//
// Since the fix, every reader ignores them (`CveAlert::statement`), so the
// stored statements no longer reach an export, the dashboard or a tracker.
// This script removes them from the data too; whether and when it runs is the
// owner's decision on #994. The alerts keep `resolved_at`: that the scan no
// longer finds the CVE stays recorded, as an observation.
//
// A statement counts when a scan made it (`by_scan`), it says `fixed`, and it
// gives no reason (`impact_statement`). A scan's statement from the target's
// own data (a Yocto recipe's patch) always gives one, so it is never matched.
//
// It prints counts only, never a database, target or CVE. Dry run unless
// `apply` is true:
//
// mongosh "$MONGODB_URI" --quiet \
// --eval 'var prefix = "<DB prefix>", apply = false' \
// scripts/vex-994-cleanup.js
if (typeof prefix !== "string" || prefix === "") {
throw new Error("set prefix, the agent's database prefix");
}
const write = typeof apply !== "undefined" && apply === true;
const inferred = {
"vex.by_scan": true,
"vex.status": "fixed",
"vex.impact_statement": null,
};
let databases = 0;
let matched = 0;
let removed = 0;
for (const { name } of db.adminCommand({ listDatabases: 1, nameOnly: true }).databases) {
if (!name.startsWith(prefix + "_")) {
continue;
}
const alerts = db.getSiblingDB(name).getCollection("cve_alerts");
const count = alerts.countDocuments(inferred);
if (count === 0) {
continue;
}
databases += 1;
matched += count;
if (write) {
removed += alerts.updateMany(inferred, { $unset: { vex: "" } }).modifiedCount;
}
}
print(
JSON.stringify({ mode: write ? "apply" : "dry-run", databases, statements: matched, removed }),
);