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
@@ -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 {
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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"));
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
@@ -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`.
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -111,12 +111,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"),
|
||||
]
|
||||
}
|
||||
@@ -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::<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}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user