Files
pruefwerk/compliance-core/src/enisa_docs.rs
T
sharangandClaude Opus 5.5 87b1e281ed
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 3s
CI / Deploy Docs (push) Successful in 1m19s
CI / Deploy MCP (push) Successful in 2m42s
CI / Deploy Dashboard (push) Successful in 6m14s
CI / Deploy Agent (push) Successful in 8m42s
fix(vex): a CVE a scan no longer finds is not stated fixed (#994) (#1015)
A scan never states VEX `fixed`. When a scan stops finding a CVE, its tracker issue stays open and gets one comment; a person closes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
2026-11-27 22:23:03 +00:00

800 lines
33 KiB
Rust

//! Draft notifications of an actively exploited vulnerability under the
//! Cyber Resilience Act (Regulation (EU) 2024/2847), Article 14(1) and (2)
//! (#498): the early warning (24 hours), the vulnerability notification (72
//! hours) and the final report (14 days after a corrective measure is
//! available), for the manufacturer to check, complete and enter by hand in
//! ENISA's single reporting platform (SRP, Article 16). Prüfwerk submits
//! nothing.
//!
//! The fields are the SRP's, as ENISA's CRA SRP Glossary ([`GLOSSARY`])
//! defines them: their numbers and names, and per stage whether each is
//! required, optional or copied from the previous stage. Each carries the
//! point of Article 14 it serves. Prüfwerk fills what it knows (the product
//! and component, the advisory, its exploitation, the VEX statement); a
//! required field it cannot fill is listed under `to_complete`. The Member
//! States are always the manufacturer's to enter.
use chrono::{DateTime, Duration, Utc};
use crate::models::{CveAlert, VexStatus};
use crate::vex_docs::{rfc3339, status_of};
/// The stamp every draft carries.
pub const DRAFT_STAMP: &str = "Draft, not submitted";
/// The glossary the fields follow. When ENISA publishes a new version,
/// compare its table with [`FIELDS`] and update both.
pub const GLOSSARY: Glossary = Glossary {
name: "ENISA CRA SRP Glossary",
version: "1.4",
last_update: "2026-10-01",
url: "https://www.enisa.europa.eu/cra-srp-glossary",
};
/// Which glossary version the drafts follow.
#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize)]
pub struct Glossary {
pub name: &'static str,
pub version: &'static str,
pub last_update: &'static str,
pub url: &'static str,
}
/// Where the notifications go (Article 14(7), Article 16(1)).
const SUBMIT_VIA: &str = "ENISA's CRA single reporting platform \
(https://portal.cra-srp.enisa.europa.eu), through the electronic notification end-point \
of the CSIRT designated as coordinator of the Member State where the manufacturer has its \
main establishment in the Union (Article 14(7)); simultaneously accessible to ENISA";
/// A field's requirement at one stage, as the glossary states it.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
enum Need {
Required,
/// Required if such information is available.
IfAvailable,
Optional,
/// By default copied from the previous stage, or updated.
Copied,
/// Not part of this stage.
No,
}
impl Need {
fn text(self) -> &'static str {
match self {
Self::Required => "Required",
Self::IfAvailable => "Required if such information available",
Self::Optional => "Optional",
Self::Copied => "By default copied from previous step, or updated",
Self::No => "N/A",
}
}
}
/// One SRP field for actively exploited vulnerabilities.
struct Field {
/// The glossary's number (`5`, `v26a`).
nr: &'static str,
/// The glossary's name.
name: &'static str,
/// The requirement at the early warning, the 72-hour notification and
/// the final report.
stages: [Need; 3],
/// The point of Regulation (EU) 2024/2847 it serves.
cra_art14_ref: &'static str,
}
use Need::{Copied, IfAvailable, No, Optional, Required};
/// The fields of the glossary that apply to an actively exploited
/// vulnerability (the common and the AEV fields; not the incident fields,
/// nor the CSIRT's own note), in its order.
const FIELDS: &[Field] = &[
Field { nr: "1", name: "Notification type (Vulnerability/Incident)", stages: [Required, Copied, Copied], cra_art14_ref: "Art. 14(1)" },
Field { nr: "2", name: "Title", stages: [Required, Copied, Copied], cra_art14_ref: "Art. 14(2)" },
Field { nr: "3", name: "Summary", stages: [Required, Copied, Copied], cra_art14_ref: "Art. 14(2)" },
Field { nr: "4", name: "Manufacturer name", stages: [Required, Copied, Copied], cra_art14_ref: "Art. 14(1)" },
Field { nr: "5", name: "Member States where product available (Concerned CSIRT)", stages: [Required, Copied, Copied], cra_art14_ref: "Art. 14(2)(a)" },
Field { nr: "6", name: "Product Name", stages: [Required, Copied, Copied], cra_art14_ref: "Art. 14(2)(b): general information about the product" },
Field { nr: "7", name: "Product Version", stages: [Required, Copied, Copied], cra_art14_ref: "Art. 14(2)(b): general information about the product" },
Field { nr: "8", name: "Product Type (Default/Important Product with Digital Elements/Critical Product with Digital Elements)", stages: [Optional, Copied, Copied], cra_art14_ref: "Art. 14(2)(b): general information about the product" },
Field { nr: "9", name: "Product class", stages: [Optional, Copied, Copied], cra_art14_ref: "Art. 14(2)(b): general information about the product" },
Field { nr: "10", name: "Product category", stages: [Optional, Copied, Copied], cra_art14_ref: "Art. 14(2)(b): general information about the product" },
Field { nr: "11", name: "End of support indicator", stages: [Optional, Copied, Copied], cra_art14_ref: "Art. 14(2)(b): general information about the product" },
Field { nr: "12", name: "Component name", stages: [Optional, Copied, Copied], cra_art14_ref: "Art. 14(2)(b): general information about the product" },
Field { nr: "13", name: "Mitigating measure expected shortly", stages: [Optional, Copied, Copied], cra_art14_ref: "Art. 14(2)(b): corrective or mitigating measures" },
Field { nr: "14", name: "User Action able to reduce impact", stages: [Optional, Copied, Copied], cra_art14_ref: "Art. 14(2)(b): measures users can take" },
Field { nr: "15", name: "Considered sensitivity of information", stages: [Optional, Optional, Copied], cra_art14_ref: "Art. 14(2)(b): how sensitive the information is" },
Field { nr: "16", name: "Corrective or mitigating measures taken", stages: [Optional, Optional, Required], cra_art14_ref: "Art. 14(2)(b): corrective or mitigating measures taken" },
Field { nr: "17", name: "Corrective or mitigating measures that users can take", stages: [Optional, Optional, Required], cra_art14_ref: "Art. 14(2)(b): measures users can take" },
Field { nr: "18", name: "Attack vector", stages: [No, Optional, Optional], cra_art14_ref: "Art. 14(2)(b): general nature of the exploit" },
Field { nr: "v19", name: "CVE ID", stages: [Optional, Copied, Copied], cra_art14_ref: "Art. 14(2)" },
Field { nr: "v20", name: "EUVD ID", stages: [Optional, Copied, Copied], cra_art14_ref: "Art. 14(2)" },
Field { nr: "v21", name: "General information", stages: [Optional, Required, Copied], cra_art14_ref: "Art. 14(2)(b): general nature of the exploit and of the vulnerability" },
Field { nr: "v22", name: "Date when corrective or mitigating measure has been available", stages: [Optional, Optional, Required], cra_art14_ref: "Art. 14(2)(c): 14 days after a corrective or mitigating measure is available" },
Field { nr: "v23", name: "Details about the security update/corrective measure available", stages: [Optional, Optional, Required], cra_art14_ref: "Art. 14(2)(c)(iii)" },
Field { nr: "v24", name: "Full description of the Severity of the vulnerability", stages: [Optional, Optional, Required], cra_art14_ref: "Art. 14(2)(c)(i)" },
Field { nr: "v25", name: "Full description of the Impact of the vulnerability", stages: [Optional, Optional, Required], cra_art14_ref: "Art. 14(2)(c)(i)" },
Field { nr: "v26", name: "Date and time when you become aware of the Actively Exploited Vulnerability", stages: [Required, Copied, Copied], cra_art14_ref: "Art. 14(2)(a): 24 hours of the manufacturer becoming aware" },
Field { nr: "v26a", name: "Date and time when the Actively Exploited Vulnerability occurred (UTC time)", stages: [Optional, Required, Copied], cra_art14_ref: "Art. 14(2)(b)" },
Field { nr: "v27", name: "Malicious actor that has exploited/is exploiting the vulnerability", stages: [Optional, Optional, IfAvailable], cra_art14_ref: "Art. 14(2)(c)(ii)" },
Field { nr: "v28", name: "Particular Exceptional Circumstances (PEC)", stages: [No, Optional, No], cra_art14_ref: "Art. 16(2), third subparagraph" },
Field { nr: "v29", name: "PEC Delay Reason", stages: [No, Optional, No], cra_art14_ref: "Art. 16(2), third subparagraph" },
Field { nr: "v30", name: "Please provide further information", stages: [Optional, Optional, Copied], cra_art14_ref: "Art. 16(2)" },
Field { nr: "40", name: "AR Note", stages: [Optional, Optional, Optional], cra_art14_ref: "Art. 14(7)" },
];
/// The stages, with their deadline as Article 14(2) sets it.
const STAGES: [(&str, &str); 3] = [
("early_warning", "Art. 14(2)(a): within 24 hours of becoming aware"),
("vulnerability_notification", "Art. 14(2)(b): within 72 hours of becoming aware"),
("final_report", "Art. 14(2)(c): no later than 14 days after a corrective or mitigating measure is available"),
];
/// Whether an alert is to be notified under Article 14(1).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Reportability {
/// Actively exploited, and the product affected or under investigation,
/// or fixed after the exploitation was known (the final report is due
/// 14 days after the fix).
Reportable,
/// No source says it is actively exploited.
NotExploited,
/// The manufacturer stated the product is not affected.
NotAffected,
/// 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 {
/// Why an alert is (not) to be notified, in words.
pub const fn reason(self) -> &'static str {
match self {
Self::Reportable => {
"actively exploited while the product is or was affected (Article 14(1))"
}
Self::NotExploited => "not known to be actively exploited",
Self::NotAffected => "the product is not affected (VEX not_affected)",
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"
}
}
}
}
/// Whether `alert` is to be notified: actively exploited (CISA KEV, or SSVC
/// exploitation `active`) and not stated `not_affected`. A `fixed` one
/// stays reportable when a scan found it exploited while the product still
/// contained it: fixing the product does not discharge the notification,
/// and the final report is due 14 days after the fix.
pub fn reportability(alert: &CveAlert) -> Reportability {
let exploited = alert
.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 !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
}
}
}
/// When the fix became available, as far as Prüfwerk knows: when a person
/// 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>> {
alert
.statement()
.filter(|v| v.status == VexStatus::Fixed && !v.by_scan)
.map(|v| v.at)
}
/// The alerts of one vulnerability, grouped by CVE ([`CveAlert::cve`]): a
/// GitHub advisory and the CVE it aliases, or the same CVE in several
/// components, are one notification. In the order first seen.
pub fn group_by_cve(alerts: &[CveAlert]) -> Vec<Vec<&CveAlert>> {
let mut groups: Vec<Vec<&CveAlert>> = Vec::new();
for alert in alerts {
match groups.iter_mut().find(|g| g[0].cve() == alert.cve()) {
Some(group) => group.push(alert),
None => groups.push(vec![alert]),
}
}
groups
}
/// Whether a vulnerability (its alerts) is to be notified: when any of its
/// alerts is; otherwise why not, as its first alert says.
pub fn group_reportability(group: &[&CveAlert]) -> Reportability {
let each: Vec<Reportability> = group.iter().map(|a| reportability(a)).collect();
if each.contains(&Reportability::Reportable) {
Reportability::Reportable
} else {
each.first().copied().unwrap_or(Reportability::NotExploited)
}
}
/// When a scan first found the vulnerability actively exploited, in any of
/// its components.
pub fn exploited_seen_at(group: &[&CveAlert]) -> Option<DateTime<Utc>> {
group.iter().filter_map(|a| a.exploited_seen_at).min()
}
/// When the vulnerability was fixed in the product: once every component
/// is, the last of their fixes.
fn group_fixed_at(group: &[&CveAlert]) -> Option<DateTime<Utc>> {
group
.iter()
.map(|a| fixed_at(a))
.collect::<Option<Vec<_>>>()?
.into_iter()
.max()
}
/// One stage's deadline, as the reporting clock stands at a moment.
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)]
pub struct StageDue {
/// `early_warning`, `vulnerability_notification` or `final_report`.
pub stage: &'static str,
/// `None` for the final report until the fix is known.
pub due_at: Option<DateTime<Utc>>,
/// Whether `due_at` has passed.
pub overdue: bool,
/// Whole hours until `due_at`; negative once overdue.
pub hours_left: Option<i64>,
}
/// The deadlines of the three stages of a vulnerability the manufacturer
/// became aware of at `aware_at`, as they stand at `now`.
pub fn deadlines(
group: &[&CveAlert],
aware_at: DateTime<Utc>,
now: DateTime<Utc>,
) -> Vec<StageDue> {
let due = [
Some(aware_at + Duration::hours(24)),
Some(aware_at + Duration::hours(72)),
group_fixed_at(group).map(|at| at + Duration::days(14)),
];
STAGES
.iter()
.zip(due)
.map(|((stage, _), due_at)| StageDue {
stage,
due_at,
overdue: due_at.is_some_and(|d| d < now),
hours_left: due_at.map(|d| (d - now).num_hours()),
})
.collect()
}
/// What a draft is built from.
pub struct EnisaInput<'a> {
/// The product: the target's name.
pub product: &'a str,
/// The manufacturer: the workspace's name.
pub manufacturer: &'a str,
/// The tool and version that wrote it (`Prüfwerk 0.4.5`).
pub tooling: &'a str,
/// The alerts of one vulnerability (see [`group_by_cve`]).
pub alerts: &'a [&'a CveAlert],
/// When the manufacturer became aware of the exploitation; the
/// deadlines run from here.
pub aware_at: DateTime<Utc>,
pub now: DateTime<Utc>,
}
/// What users can do about one component: the VEX action statement, else
/// the fixed version.
fn user_measures(alert: &CveAlert) -> Option<String> {
alert
.statement()
.and_then(|v| v.action_statement.clone())
.or_else(|| {
(!alert.fixed_versions.is_empty()).then(|| {
format!(
"Update {} to {}.",
alert.affected_package,
alert.fixed_versions.join(" or ")
)
})
})
}
/// The distinct texts `each` gives for the alerts, joined; `None` if none.
fn joined(alerts: &[&CveAlert], each: impl Fn(&CveAlert) -> Option<String>) -> Option<String> {
let mut texts: Vec<String> = Vec::new();
for text in alerts.iter().filter_map(|a| each(a)) {
if !texts.contains(&text) {
texts.push(text);
}
}
(!texts.is_empty()).then(|| texts.join(" "))
}
/// What is known about the exploitation, in words.
fn exploitation_text(alert: &CveAlert) -> Option<String> {
let e = alert.exploitation.as_ref()?;
let mut parts = Vec::new();
if let Some(kev) = &e.kev {
parts.push(format!(
"Listed in CISA's Known Exploited Vulnerabilities catalog since {}.",
kev.date_added
));
}
if let Some(ssvc) = &e.ssvc_exploitation {
parts.push(format!("SSVC exploitation (CISA Vulnrichment): {ssvc}."));
}
if let Some(epss) = &e.epss {
parts.push(format!(
"EPSS (FIRST): {:.1} % probability of exploitation in the next 30 days.",
epss.score * 100.0
));
}
(!parts.is_empty()).then(|| parts.join(" "))
}
/// The affected components, `log4j-core 2.14.1, log4j-api 2.14.1`.
fn components(alerts: &[&CveAlert]) -> String {
let mut names: Vec<String> = Vec::new();
for alert in alerts {
let name = format!("{} {}", alert.affected_package, alert.affected_version);
if !names.contains(&name) {
names.push(name);
}
}
names.join(", ")
}
/// The value Prüfwerk can give field `nr`, if any.
fn value(nr: &str, input: &EnisaInput<'_>) -> Option<serde_json::Value> {
let alerts = input.alerts;
let first = alerts.first()?;
let cve = first.cve();
let text = |s: String| Some(serde_json::Value::String(s));
match nr {
"1" => text("Vulnerability".into()),
"2" => text(format!(
"Active exploitation of {cve} affecting {}",
input.product
)),
"3" => {
let fix = match joined(alerts, user_measures) {
Some(m) => format!(" Users can act: {m}"),
None => String::new(),
};
let place = if alerts.len() > 1 {
"the components"
} else {
"the component"
};
text(format!(
"An actively exploited vulnerability ({cve}) in {place} {} affects {}.{fix}",
components(alerts),
input.product
))
}
"4" => text(input.manufacturer.to_string()),
"6" => text(input.product.to_string()),
"12" => text(components(alerts)),
"14" | "17" => joined(alerts, user_measures).and_then(text),
"16" => joined(alerts, |a| {
a.statement().and_then(|v| v.action_statement.clone())
})
.and_then(text),
"v19" => cve.starts_with("CVE-").then(|| serde_json::json!(cve)),
"v21" => {
let parts: Vec<String> = [
alerts.iter().find_map(|a| a.summary.clone()),
alerts.iter().find_map(|a| exploitation_text(a)),
]
.into_iter()
.flatten()
.collect();
(!parts.is_empty()).then(|| serde_json::json!(parts.join(" ")))
}
"v22" => group_fixed_at(alerts).map(|at| serde_json::json!(rfc3339(at))),
"v23" => joined(alerts, |a| {
(!a.fixed_versions.is_empty()).then(|| {
format!(
"Fixed in {} {}.",
a.affected_package,
a.fixed_versions.join(", ")
)
})
})
.and_then(text),
"v24" => {
let severity = alerts.iter().find_map(|a| a.severity.as_deref())?;
text(match alerts.iter().find_map(|a| a.cvss_score) {
Some(score) => format!("Severity {severity} (CVSS base score {score:.1})."),
None => format!("Severity {severity}."),
})
}
"v25" => joined(alerts, |a| {
a.statement()
.and_then(|v| v.impact_statement.clone())
.or_else(|| a.llm_impact_summary.clone())
})
.and_then(text),
"v26" => text(rfc3339(input.aware_at)),
"v27" => alerts
.iter()
.filter_map(|a| a.exploitation.as_ref()?.kev.as_ref())
.any(|k| k.known_ransomware)
.then(|| {
serde_json::json!(
"CISA's Known Exploited Vulnerabilities catalog lists known use in \
ransomware campaigns."
)
}),
_ => None,
}
}
/// The draft notification package of the vulnerability of `input.alerts`.
pub fn draft(input: &EnisaInput<'_>) -> serde_json::Value {
let mut stages = serde_json::Map::new();
let mut to_complete: Vec<String> = Vec::new();
for (i, (stage, deadline)) in STAGES.iter().enumerate() {
let fields: Vec<serde_json::Value> = FIELDS
.iter()
.filter(|f| f.stages[i] != Need::No)
.map(|f| {
let value = value(f.nr, input);
let need = f.stages[i];
// The Member States are always the manufacturer's to enter.
if value.is_none() && need == Need::Required {
to_complete.push(format!("{stage}: {}. {}", f.nr, f.name));
}
serde_json::json!({
"nr": f.nr,
"field": f.name,
"requirement": need.text(),
"value": value,
"cra_art14_ref": f.cra_art14_ref,
})
})
.collect();
stages.insert(
(*stage).to_string(),
serde_json::json!({ "deadline": deadline, "fields": fields }),
);
}
let due: serde_json::Map<String, serde_json::Value> =
deadlines(input.alerts, input.aware_at, input.now)
.into_iter()
.map(|d| {
let at = d.due_at.map_or_else(
|| "14 days after the date in field v22".to_string(),
rfc3339,
);
(d.stage.to_string(), serde_json::json!(at))
})
.collect();
serde_json::json!({
"status": DRAFT_STAMP,
"submitted": false,
"legal_basis": "Regulation (EU) 2024/2847 (Cyber Resilience Act), Article 14(1) and (2)",
"glossary": GLOSSARY,
"submit_via": SUBMIT_VIA,
"generated_at": rfc3339(input.now),
"generator": input.tooling,
"aware_at": rfc3339(input.aware_at),
"due": due,
"stages": stages,
"to_complete": to_complete,
})
}
#[cfg(test)]
mod tests {
use super::*;
use crate::models::{CveSource, Exploitation, KevEntry, VexAssessment};
fn alert() -> CveAlert {
let mut a = CveAlert::new(
"GHSA-jfh8-c2jp-5v3q".into(),
"t".into(),
"log4j-core".into(),
"2.14.1".into(),
CveSource::Osv,
);
a.aliases = vec!["CVE-2021-44228".into()];
a.summary = Some("Remote code injection in Log4j".into());
a.severity = Some("CRITICAL".into());
a.cvss_score = Some(10.0);
a.fixed_versions = vec!["2.17.1".into()];
a.exploitation = Some(Exploitation {
kev: Some(KevEntry {
date_added: "2021-12-10".into(),
known_ransomware: true,
}),
..Exploitation::default()
});
a
}
fn at(text: &str) -> DateTime<Utc> {
DateTime::parse_from_rfc3339(text)
.map(|d| d.with_timezone(&Utc))
.unwrap_or_default()
}
fn statement(status: VexStatus) -> VexAssessment {
VexAssessment {
status,
justification: None,
impact_statement: Some("JNDI lookups are disabled.".into()),
action_statement: None,
by: "u1".into(),
by_name: None,
at: Utc::now(),
by_scan: false,
}
}
#[test]
fn only_exploited_vulnerabilities_in_the_product_are_reported() {
let mut a = alert();
assert_eq!(reportability(&a), Reportability::Reportable);
a.vex = Some(statement(VexStatus::NotAffected));
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-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",
tooling: "Prüfwerk test",
alerts: &[&a],
aware_at: at("2026-10-01T08:00:00Z"),
now: at("2026-10-06T09:00:00Z"),
});
assert_eq!(doc["due"]["final_report"], "2026-10-19T10:00:00Z");
let v22 = doc["stages"]["final_report"]["fields"]
.as_array()
.into_iter()
.flatten()
.find(|f| f["nr"] == "v22")
.cloned()
.unwrap_or_default();
assert_eq!(v22["value"], "2026-10-05T10:00:00Z");
assert!(doc["to_complete"]
.as_array()
.into_iter()
.flatten()
.all(|t| !t.as_str().unwrap_or_default().contains("v22")));
}
#[test]
fn one_cve_is_one_notification_whatever_alerts_name_it() {
let ghsa = alert();
let mut cve = CveAlert::new(
"CVE-2021-44228".into(),
"t".into(),
"log4j-api".into(),
"2.14.1".into(),
CveSource::Nvd,
);
cve.exploited_seen_at = Some(at("2026-10-02T08:00:00Z"));
let other = CveAlert::new(
"CVE-2024-0001".into(),
"t".into(),
"zlib".into(),
"1.2.11".into(),
CveSource::Osv,
);
let alerts = vec![ghsa, other, cve];
let groups = group_by_cve(&alerts);
assert_eq!(groups.len(), 2);
assert_eq!(groups[0].len(), 2);
// Reportable through the GHSA alert's KEV entry.
assert_eq!(group_reportability(&groups[0]), Reportability::Reportable);
assert_eq!(group_reportability(&groups[1]), Reportability::NotExploited);
assert_eq!(
exploited_seen_at(&groups[0]),
Some(at("2026-10-02T08:00:00Z"))
);
let doc = draft(&EnisaInput {
product: "Pump Remote",
manufacturer: "example-pumps",
tooling: "Prüfwerk test",
alerts: &groups[0],
aware_at: at("2026-10-02T08:00:00Z"),
now: at("2026-10-06T09:00:00Z"),
});
let component = doc["stages"]["early_warning"]["fields"]
.as_array()
.into_iter()
.flatten()
.find(|f| f["nr"] == "12")
.cloned()
.unwrap_or_default();
assert_eq!(component["value"], "log4j-core 2.14.1, log4j-api 2.14.1");
}
#[test]
fn deadlines_say_what_is_overdue() {
let a = alert();
let due = deadlines(
&[&a],
at("2026-10-05T08:00:00Z"),
at("2026-10-06T20:00:00Z"),
);
assert_eq!(due[0].stage, "early_warning");
assert!(due[0].overdue);
assert_eq!(due[0].hours_left, Some(-12));
assert!(!due[1].overdue);
assert_eq!(due[1].hours_left, Some(36));
// No fix yet: the final report has no date.
assert_eq!(due[2].due_at, None);
assert!(!due[2].overdue);
}
#[test]
fn the_glossary_fields_are_complete_and_unique() {
let mut nrs: Vec<&str> = FIELDS.iter().map(|f| f.nr).collect();
let count = nrs.len();
nrs.sort_unstable();
nrs.dedup();
assert_eq!(nrs.len(), count);
// The 24-hour stage requires exactly the glossary's eight.
let required: Vec<&str> = FIELDS
.iter()
.filter(|f| f.stages[0] == Need::Required)
.map(|f| f.nr)
.collect();
assert_eq!(required, ["1", "2", "3", "4", "5", "6", "7", "v26"]);
}
#[test]
fn the_draft_follows_the_srp_glossary() {
let a = alert();
let doc = draft(&EnisaInput {
product: "Pump Remote",
manufacturer: "example-pumps",
tooling: "Prüfwerk test",
alerts: &[&a],
aware_at: at("2026-10-06T08:00:00Z"),
now: at("2026-10-06T09:00:00Z"),
});
assert_eq!(doc["status"], DRAFT_STAMP);
assert_eq!(doc["submitted"], false);
assert_eq!(doc["glossary"]["version"], "1.4");
assert_eq!(doc["due"]["early_warning"], "2026-10-07T08:00:00Z");
assert_eq!(
doc["due"]["vulnerability_notification"],
"2026-10-09T08:00:00Z"
);
let field = |stage: &str, nr: &str| {
doc["stages"][stage]["fields"]
.as_array()
.into_iter()
.flatten()
.find(|f| f["nr"] == nr)
.cloned()
.unwrap_or_default()
};
assert_eq!(field("early_warning", "1")["value"], "Vulnerability");
assert_eq!(field("early_warning", "v19")["value"], "CVE-2021-44228");
assert_eq!(
field("early_warning", "v26")["value"],
"2026-10-06T08:00:00Z"
);
assert_eq!(
field("early_warning", "5")["value"],
serde_json::Value::Null
);
assert_eq!(
field("early_warning", "5")["cra_art14_ref"],
"Art. 14(2)(a)"
);
// The attack vector is not part of the early warning.
assert!(field("early_warning", "18").is_null());
assert_eq!(field("final_report", "16")["requirement"], "Required");
assert_eq!(
field("final_report", "17")["value"],
"Update log4j-core to 2.17.1."
);
assert!(field("vulnerability_notification", "v21")["value"]
.as_str()
.is_some_and(|v| v.contains("Known Exploited Vulnerabilities")));
assert!(field("final_report", "v27")["value"]
.as_str()
.is_some_and(|v| v.contains("ransomware")));
let open: Vec<&str> = doc["to_complete"]
.as_array()
.into_iter()
.flatten()
.filter_map(|t| t.as_str())
.collect();
assert_eq!(
open,
[
"early_warning: 5. Member States where product available (Concerned CSIRT)",
"early_warning: 7. Product Version",
"vulnerability_notification: v26a. Date and time when the Actively Exploited \
Vulnerability occurred (UTC time)",
"final_report: 16. Corrective or mitigating measures taken",
"final_report: v22. Date when corrective or mitigating measure has been available",
"final_report: v25. Full description of the Impact of the vulnerability",
]
);
}
}