From 908e6b844925713e7c52db28ef8421e95a21e4e8 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Tue, 6 Oct 2026 15:36:38 +0000 Subject: [PATCH] feat(vex): ENISA deadlines evaluated by the agent, one notification per CVE (#498 follow-up) (#514) --- compliance-agent/src/api/handlers/vex.rs | 74 +++-- compliance-agent/src/evidence/mod.rs | 13 +- compliance-core/src/enisa_docs.rs | 289 ++++++++++++++---- compliance-dashboard/assets/main.css | 5 + .../src/components/vex_panel.rs | 138 ++++++++- compliance-dashboard/src/i18n/texts.rs | 22 +- .../src/infrastructure/vex.rs | 47 +++ docs/guide/sbom.md | 5 +- docs/guide/vex-en.md | 9 +- docs/guide/vex.md | 9 +- .../release/staging-test-plan-after-v0.4.5.md | 20 ++ 11 files changed, 520 insertions(+), 111 deletions(-) diff --git a/compliance-agent/src/api/handlers/vex.rs b/compliance-agent/src/api/handlers/vex.rs index 8ecb3c2..5191c68 100644 --- a/compliance-agent/src/api/handlers/vex.rs +++ b/compliance-agent/src/api/handlers/vex.rs @@ -279,25 +279,28 @@ pub async fn export_csaf( download(&body, &filename) } -/// One alert in [`list_enisa`]: whether CRA Article 14 asks for it to be -/// notified, and since when. +/// One vulnerability in [`list_enisa`]: its alerts, whether CRA Article +/// 14 asks for it to be notified, and its deadlines as they stand now. #[derive(Debug, serde::Serialize)] pub struct EnisaCandidate { - pub alert_id: String, pub cve: String, - pub component: String, + /// Its alerts: a GitHub advisory and the CVE it aliases, or the CVE in + /// several components. + pub alert_ids: Vec, + pub components: Vec, pub reportable: bool, pub reason: &'static str, /// When a scan first found it actively exploited. #[serde(skip_serializing_if = "Option::is_none")] pub exploited_seen_at: Option>, - /// When the early warning is due (24 hours after that). - #[serde(skip_serializing_if = "Option::is_none")] - pub early_warning_due: Option>, + /// The three stages' deadlines, evaluated at the request; empty until a + /// scan found it exploited. + pub stages: Vec, } -/// GET /api/v1/targets/{id}/enisa — the target's actively exploited CVE -/// alerts and whether each is to be notified under CRA Article 14 (#498). +/// GET /api/v1/targets/{id}/enisa — the target's actively exploited +/// vulnerabilities, one per CVE, whether each is to be notified under CRA +/// Article 14 (#498), and how its deadlines stand. #[tracing::instrument(skip_all, fields(target_id = %id))] pub async fn list_enisa( Extension(agent): AgentExt, @@ -312,20 +315,31 @@ pub async fn list_enisa( Vec::new() } }; - let candidates: Vec = alerts - .iter() - .filter_map(|a| { - let reportability = enisa_docs::reportability(a); - (reportability != Reportability::NotExploited).then(|| EnisaCandidate { - alert_id: a.id.map(|o| o.to_hex()).unwrap_or_default(), - cve: a.cve().to_string(), - component: format!("{} {}", a.affected_package, a.affected_version), + let now = chrono::Utc::now(); + let candidates: Vec = enisa_docs::group_by_cve(&alerts) + .into_iter() + .filter_map(|group| { + let reportability = enisa_docs::group_reportability(&group); + if reportability == Reportability::NotExploited { + return None; + } + let seen = enisa_docs::exploited_seen_at(&group); + Some(EnisaCandidate { + cve: group[0].cve().to_string(), + alert_ids: group + .iter() + .filter_map(|a| a.id.map(|o| o.to_hex())) + .collect(), + components: group + .iter() + .map(|a| format!("{} {}", a.affected_package, a.affected_version)) + .collect(), reportable: reportability == Reportability::Reportable, reason: reportability.reason(), - exploited_seen_at: a.exploited_seen_at, - early_warning_due: a - .exploited_seen_at - .map(|at| at + chrono::Duration::hours(24)), + exploited_seen_at: seen, + stages: seen + .map(|at| enisa_docs::deadlines(&group, at, now)) + .unwrap_or_default(), }) }) .collect(); @@ -378,7 +392,17 @@ pub async fn export_enisa( .await .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)? .ok_or(StatusCode::NOT_FOUND)?; - let reportability = enisa_docs::reportability(&alert); + // The notification is the vulnerability's: every alert of its CVE in + // this target. + let siblings: Vec = collect_cursor_async( + db.cve_alerts() + .find(doc! { "repo_id": &alert.repo_id }) + .await + .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?, + ) + .await; + let group: Vec<&CveAlert> = siblings.iter().filter(|a| a.cve() == alert.cve()).collect(); + let reportability = enisa_docs::group_reportability(&group); if reportability != Reportability::Reportable { let body = Json(serde_json::json!({ "error": reportability.reason() })); return Ok((StatusCode::UNPROCESSABLE_ENTITY, body).into_response()); @@ -400,8 +424,10 @@ pub async fn export_enisa( product: &product, manufacturer: &manufacturer, tooling: &tooling, - alert: &alert, - aware_at: aware_at.or(alert.exploited_seen_at).unwrap_or(now), + alerts: &group, + aware_at: aware_at + .or_else(|| enisa_docs::exploited_seen_at(&group)) + .unwrap_or(now), now, }); let filename = format!( diff --git a/compliance-agent/src/evidence/mod.rs b/compliance-agent/src/evidence/mod.rs index 0e1c3e8..2778de9 100644 --- a/compliance-agent/src/evidence/mod.rs +++ b/compliance-agent/src/evidence/mod.rs @@ -115,17 +115,16 @@ pub fn build_pack( ]; // Draft CRA Article 14 notifications of the actively exploited // vulnerabilities in the product (#498), when there are any. - let enisa: Vec = inputs - .cves - .iter() - .filter(|a| enisa_docs::reportability(a) == enisa_docs::Reportability::Reportable) - .map(|alert| { + let enisa: Vec = enisa_docs::group_by_cve(&inputs.cves) + .into_iter() + .filter(|g| enisa_docs::group_reportability(g) == enisa_docs::Reportability::Reportable) + .map(|group| { enisa_docs::draft(&enisa_docs::EnisaInput { product: subject, manufacturer: vex.author, tooling: &tooling, - alert, - aware_at: alert.exploited_seen_at.unwrap_or(at), + aware_at: enisa_docs::exploited_seen_at(&group).unwrap_or(at), + alerts: &group, now: at, }) }) diff --git a/compliance-core/src/enisa_docs.rs b/compliance-core/src/enisa_docs.rs index b352b37..0ece5f3 100644 --- a/compliance-core/src/enisa_docs.rs +++ b/compliance-core/src/enisa_docs.rs @@ -198,6 +198,85 @@ fn fixed_at(alert: &CveAlert) -> Option> { .or(alert.resolved_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> { + let mut groups: Vec> = 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 = 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> { + 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> { + group + .iter() + .map(|a| fixed_at(a)) + .collect::>>()? + .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>, + /// Whether `due_at` has passed. + pub overdue: bool, + /// Whole hours until `due_at`; negative once overdue. + pub hours_left: Option, +} + +/// 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, + now: DateTime, +) -> Vec { + 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. @@ -206,14 +285,16 @@ pub struct EnisaInput<'a> { pub manufacturer: &'a str, /// The tool and version that wrote it (`Prüfwerk 0.4.5`). pub tooling: &'a str, - pub alert: &'a CveAlert, + /// 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, pub now: DateTime, } -/// What users can do: the VEX action statement, else the fixed version. +/// What users can do about one component: the VEX action statement, else +/// the fixed version. fn user_measures(alert: &CveAlert) -> Option { alert .vex @@ -230,6 +311,17 @@ fn user_measures(alert: &CveAlert) -> Option { }) } +/// The distinct texts `each` gives for the alerts, joined; `None` if none. +fn joined(alerts: &[&CveAlert], each: impl Fn(&CveAlert) -> Option) -> Option { + let mut texts: Vec = 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 { let e = alert.exploitation.as_ref()?; @@ -252,10 +344,23 @@ fn exploitation_text(alert: &CveAlert) -> Option { (!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 = 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 { - let alert = input.alert; - let cve = alert.cve(); + 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()), @@ -264,63 +369,71 @@ fn value(nr: &str, input: &EnisaInput<'_>) -> Option { input.product )), "3" => { - let fix = match user_measures(alert) { + 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 the component {} {} affects {}.{fix}", - alert.affected_package, alert.affected_version, input.product + "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(format!( - "{} {}", - alert.affected_package, alert.affected_version - )), - "14" | "17" => user_measures(alert).and_then(text), - "16" => alert - .vex - .as_ref() - .and_then(|v| v.action_statement.clone()) - .and_then(text), + "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()) + }) + .and_then(text), "v19" => cve.starts_with("CVE-").then(|| serde_json::json!(cve)), "v21" => { - let parts: Vec = [alert.summary.clone(), exploitation_text(alert)] - .into_iter() - .flatten() - .collect(); + let parts: Vec = [ + 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" => fixed_at(alert).map(|at| serde_json::json!(rfc3339(at))), - "v23" => (!alert.fixed_versions.is_empty()).then(|| { - serde_json::json!(format!( - "Fixed in {} {}.", - alert.affected_package, - alert.fixed_versions.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 = alert.severity.as_deref()?; - text(match alert.cvss_score { + 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" => alert - .vex - .as_ref() - .and_then(|v| v.impact_statement.clone()) - .or_else(|| alert.llm_impact_summary.clone()) - .and_then(text), + "v25" => joined(alerts, |a| { + a.vex + .as_ref() + .and_then(|v| v.impact_statement.clone()) + .or_else(|| a.llm_impact_summary.clone()) + }) + .and_then(text), "v26" => text(rfc3339(input.aware_at)), - "v27" => alert - .exploitation - .as_ref() - .and_then(|e| e.kev.as_ref()) - .filter(|k| k.known_ransomware) - .map(|_| { + "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." @@ -330,7 +443,7 @@ fn value(nr: &str, input: &EnisaInput<'_>) -> Option { } } -/// The draft notification package of `input.alert`. +/// 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 = Vec::new(); @@ -359,6 +472,17 @@ pub fn draft(input: &EnisaInput<'_>) -> serde_json::Value { serde_json::json!({ "deadline": deadline, "fields": fields }), ); } + let due: serde_json::Map = + 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, @@ -368,13 +492,7 @@ pub fn draft(input: &EnisaInput<'_>) -> serde_json::Value { "generated_at": rfc3339(input.now), "generator": input.tooling, "aware_at": rfc3339(input.aware_at), - "due": { - "early_warning": rfc3339(input.aware_at + Duration::hours(24)), - "vulnerability_notification": rfc3339(input.aware_at + Duration::hours(72)), - "final_report": fixed_at(input.alert) - .map(|at| rfc3339(at + Duration::days(14))) - .unwrap_or_else(|| "14 days after the date in field v22".to_string()), - }, + "due": due, "stages": stages, "to_complete": to_complete, }) @@ -453,7 +571,7 @@ mod tests { product: "Pump Remote", manufacturer: "example-pumps", tooling: "Prüfwerk test", - alert: &a, + alerts: &[&a], aware_at: at("2026-10-01T08:00:00Z"), now: at("2026-10-06T09:00:00Z"), }); @@ -473,6 +591,71 @@ mod tests { .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(); @@ -496,7 +679,7 @@ mod tests { product: "Pump Remote", manufacturer: "example-pumps", tooling: "Prüfwerk test", - alert: &a, + alerts: &[&a], aware_at: at("2026-10-06T08:00:00Z"), now: at("2026-10-06T09:00:00Z"), }); diff --git a/compliance-dashboard/assets/main.css b/compliance-dashboard/assets/main.css index cfcc597..961cc86 100644 --- a/compliance-dashboard/assets/main.css +++ b/compliance-dashboard/assets/main.css @@ -5013,6 +5013,11 @@ tbody tr:last-child td { margin-top: 4px; } +.vex-overdue { + font-size: 12.5px; + color: var(--danger); +} + .vex-csaf { display: flex; flex-wrap: wrap; diff --git a/compliance-dashboard/src/components/vex_panel.rs b/compliance-dashboard/src/components/vex_panel.rs index d6c601b..1f04f59 100644 --- a/compliance-dashboard/src/components/vex_panel.rs +++ b/compliance-dashboard/src/components/vex_panel.rs @@ -7,7 +7,6 @@ use dioxus::prelude::*; use dioxus_free_icons::icons::bs_icons::BsDownload; use dioxus_free_icons::Icon; -use compliance_core::enisa_docs::{reportability, Reportability}; use compliance_core::models::{CveAlert, VexJustification, VexStatus}; use compliance_core::vex_docs::status_of; @@ -17,8 +16,9 @@ use crate::components::toast::{ToastType, Toasts}; use crate::i18n::texts::{common, vex as tx}; use crate::i18n::{use_lang, Lang, Text}; use crate::infrastructure::vex::{ - csaf_filename, enisa_filename, fetch_csaf_export, fetch_enisa_draft, fetch_target_cves, - fetch_vex_export, save_cve_vex, VexFormat, VexStatementDto, + csaf_filename, enisa_filename, fetch_csaf_export, fetch_enisa_candidates, fetch_enisa_draft, + fetch_target_cves, fetch_vex_export, save_cve_vex, EnisaCandidateDto, StageDueDto, VexFormat, + VexStatementDto, }; /// Every status, in the order the editor offers them. @@ -113,6 +113,13 @@ pub fn VexPanel(target_id: String) -> Element { let id = id_for_load.clone(); async move { fetch_target_cves(id).await.ok() } }); + // The CRA Article 14 view of the same alerts, deadlines evaluated by the + // agent at each load. + let id_for_enisa = target_id.clone(); + let mut enisa = use_resource(move || { + let id = id_for_enisa.clone(); + async move { fetch_enisa_candidates(id).await.unwrap_or_default() } + }); let mut editing = use_signal(|| Option::::None); rsx! { @@ -168,8 +175,12 @@ pub fn VexPanel(target_id: String) -> Element { {tx::EDIT.get(lang)} } } - if reportability(alert) == Reportability::Reportable { - EnisaDraftButton { alert: alert.clone() } + if let Some(candidate) = enisa + .read() + .as_ref() + .and_then(|c| reportable_candidate(c, &alert_id)) + { + EnisaDraftButton { alert_id: alert_id.clone(), candidate } } } } @@ -182,6 +193,7 @@ pub fn VexPanel(target_id: String) -> Element { editing.set(None); if saved { alerts.restart(); + enisa.restart(); } }, } @@ -230,20 +242,57 @@ fn VexExportButton(target_id: String, format: VexFormat) -> Element { } } +/// The reportable vulnerability among `candidates` that alert `alert_id` +/// belongs to. +fn reportable_candidate( + candidates: &[EnisaCandidateDto], + alert_id: &str, +) -> Option { + candidates + .iter() + .find(|c| c.reportable && c.alert_ids.iter().any(|id| id == alert_id)) + .cloned() +} + +/// A stage's deadline in words: `24 h: überfällig seit 2026-10-07 08:00 UTC` +/// or `72 h: fällig in 36 h`. +fn stage_text(due: &StageDueDto, lang: Lang) -> Option { + let at = due.due_at?; + let stage = match due.stage.as_str() { + "early_warning" => tx::ENISA_EARLY_WARNING, + "vulnerability_notification" => tx::ENISA_NOTIFICATION, + _ => tx::ENISA_FINAL_REPORT, + }; + Some(if due.overdue { + format!( + "{}: {} {}", + stage.get(lang), + tx::ENISA_OVERDUE_SINCE.get(lang), + at.format("%Y-%m-%d %H:%M UTC") + ) + } else { + format!( + "{}: {} {} h", + stage.get(lang), + tx::ENISA_DUE_IN.get(lang), + due.hours_left.unwrap_or_default() + ) + }) +} + /// The draft CRA Article 14 notification of an actively exploited -/// vulnerability, and when its early warning is due. +/// vulnerability, and how its deadlines stand. #[component] -fn EnisaDraftButton(alert: CveAlert) -> Element { +fn EnisaDraftButton(alert_id: String, candidate: EnisaCandidateDto) -> Element { let lang = use_lang()(); let mut toasts = use_context::(); let mut busy = use_signal(|| false); - let alert_id = alert.id.map(|o| o.to_hex()).unwrap_or_default(); - let filename = enisa_filename(alert.cve()); - let due = alert.exploited_seen_at.map(|at| { - (at + chrono::Duration::hours(24)) - .format("%Y-%m-%d %H:%M UTC") - .to_string() - }); + let filename = enisa_filename(&candidate.cve); + let deadlines: Vec<(bool, String)> = candidate + .stages + .iter() + .filter_map(|d| stage_text(d, lang).map(|t| (d.overdue, t))) + .collect(); rsx! { div { class: "vex-enisa", button { @@ -264,8 +313,8 @@ fn EnisaDraftButton(alert: CveAlert) -> Element { Icon { icon: BsDownload, width: 14, height: 14 } {tx::ENISA_DRAFT.get(lang)} } - if let Some(due) = due { - span { class: "target-muted", "{tx::ENISA_DUE.get(lang)} {due}" } + for (overdue, text) in deadlines { + span { class: if overdue { "vex-overdue" } else { "target-muted" }, "{text}" } } } } @@ -449,6 +498,63 @@ mod tests { assert_eq!(missing(&statement(VexStatus::Fixed)), None); } + #[test] + fn deadlines_read_as_overdue_or_due_in() { + let at = chrono::DateTime::parse_from_rfc3339("2026-10-07T08:00:00Z") + .map(|d| d.with_timezone(&chrono::Utc)) + .ok(); + let overdue = StageDueDto { + stage: "early_warning".into(), + due_at: at, + overdue: true, + hours_left: Some(-12), + }; + assert_eq!( + stage_text(&overdue, Lang::De).as_deref(), + Some("Frühwarnung (24 h): überfällig seit 2026-10-07 08:00 UTC") + ); + let open = StageDueDto { + stage: "vulnerability_notification".into(), + due_at: at, + overdue: false, + hours_left: Some(36), + }; + assert_eq!( + stage_text(&open, Lang::En).as_deref(), + Some("Notification (72 h): due in 36 h") + ); + let unknown = StageDueDto { + stage: "final_report".into(), + due_at: None, + overdue: false, + hours_left: None, + }; + assert_eq!(stage_text(&unknown, Lang::De), None); + } + + #[test] + fn every_alert_of_a_reportable_cve_offers_its_draft() { + let candidates = vec![ + EnisaCandidateDto { + cve: "CVE-2021-44228".into(), + alert_ids: vec!["a1".into(), "a2".into()], + reportable: true, + stages: vec![], + }, + EnisaCandidateDto { + cve: "CVE-2024-0001".into(), + alert_ids: vec!["a3".into()], + reportable: false, + stages: vec![], + }, + ]; + assert_eq!( + reportable_candidate(&candidates, "a2").map(|c| c.cve), + Some("CVE-2021-44228".into()) + ); + assert_eq!(reportable_candidate(&candidates, "a3"), None); + } + #[test] fn options_round_trip_through_their_wire_names() { for s in STATUSES { diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index 2429d61..c2d5de7 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -2294,9 +2294,25 @@ pub mod vex { holds the fields of ENISA's reporting platform; you check, complete and submit \ it yourself.", }; - pub const ENISA_DUE: Text = Text { - de: "Frühwarnung fällig bis", - en: "Early warning due by", + pub const ENISA_EARLY_WARNING: Text = Text { + de: "Frühwarnung (24 h)", + en: "Early warning (24 h)", + }; + pub const ENISA_NOTIFICATION: Text = Text { + de: "Meldung (72 h)", + en: "Notification (72 h)", + }; + pub const ENISA_FINAL_REPORT: Text = Text { + de: "Abschlussbericht", + en: "Final report", + }; + pub const ENISA_OVERDUE_SINCE: Text = Text { + de: "überfällig seit", + en: "overdue since", + }; + pub const ENISA_DUE_IN: Text = Text { + de: "fällig in", + en: "due in", }; pub const EXPORT_CSAF: Text = Text { de: "CSAF-Entwurf herunterladen", diff --git a/compliance-dashboard/src/infrastructure/vex.rs b/compliance-dashboard/src/infrastructure/vex.rs index a0d384d..c14236b 100644 --- a/compliance-dashboard/src/infrastructure/vex.rs +++ b/compliance-dashboard/src/infrastructure/vex.rs @@ -146,6 +146,53 @@ pub async fn fetch_enisa_draft(alert_id: String) -> Result>, + #[serde(default)] + pub overdue: bool, + /// Whole hours left; negative once overdue. + #[serde(default)] + pub hours_left: Option, +} + +/// One actively exploited vulnerability of a target, as the agent's +/// `/enisa` list gives it: its alerts, whether to notify, its deadlines. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] +pub struct EnisaCandidateDto { + pub cve: String, + pub alert_ids: Vec, + pub reportable: bool, + #[serde(default)] + pub stages: Vec, +} + +/// The agent's `/enisa` reply (read on the server only). +#[cfg(feature = "server")] +#[derive(Debug, Deserialize)] +struct CandidatesResponse { + data: Vec, +} + +/// The actively exploited vulnerabilities of target `target_id`, one per +/// CVE, with their CRA Article 14 deadlines as they stand now. +#[server] +pub async fn fetch_enisa_candidates( + target_id: String, +) -> Result, ServerFnError> { + let resp = super::agent_client::agent_get(&format!("/api/v1/targets/{target_id}/enisa")) + .await? + .send() + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + let body: CandidatesResponse = super::agent_client::json_or_error(resp).await?; + Ok(body.data) +} + /// The file name of the draft notification of `cve`. pub fn enisa_filename(cve: &str) -> String { format!("enisa-draft-{}.json", cve.to_ascii_lowercase()) diff --git a/docs/guide/sbom.md b/docs/guide/sbom.md index 2a4ca3f..0bb839f 100644 --- a/docs/guide/sbom.md +++ b/docs/guide/sbom.md @@ -283,8 +283,9 @@ API: `GET /api/v1/targets/{id}/cves` lists the alerts with their statements, `GET /api/v1/targets/{id}/csaf?namespace=&lang=de|en` the same statements as a CSAF 2.0 VEX advisory (a TLP:AMBER draft; see [Assessing vulnerabilities](./vex-en.md#csaf-draft)). -`GET /api/v1/targets/{id}/enisa` lists the actively exploited alerts and whether -CRA Art. 14 asks for a notification; `GET /api/v1/cves/{id}/enisa?aware_at=` +`GET /api/v1/targets/{id}/enisa` lists the actively exploited vulnerabilities, one +per CVE, whether CRA Art. 14 asks for a notification, and each stage's `due_at`, +`overdue` and `hours_left` at the time of the request; `GET /api/v1/cves/{id}/enisa?aware_at=` downloads the draft notification in the fields of ENISA's reporting platform (see [Assessing vulnerabilities](./vex-en.md#enisa-notification-cra-art-14)). diff --git a/docs/guide/vex-en.md b/docs/guide/vex-en.md index 74cca62..5284907 100644 --- a/docs/guide/vex-en.md +++ b/docs/guide/vex-en.md @@ -89,9 +89,12 @@ after a corrective measure is available. Prüfwerk recognises actively exploited vulnerabilities from CISA's KEV catalog and the SSVC exploitation "active". Where the product is affected or under investigation, or the vulnerability was fixed after a scan found it -exploited (then the final report is due), the row shows **ENISA notification (draft)** and when -the early warning is due (24 hours after the scan that first found the -exploitation). The draft +exploited (then the final report is due), the row shows +**ENISA notification (draft)** and the three stages' deadlines as they stand +when the page loads: "due in N h", or in red "overdue since …". The deadlines +run from the scan that first found the exploitation. A vulnerability is one +notification, also when several alerts name it (a GitHub advisory and its +CVE) or it affects several components. The draft - holds the platform's fields in their order, per stage (early warning, 72-hour notification, final report), with number, name, requirement as diff --git a/docs/guide/vex.md b/docs/guide/vex.md index ee604af..57c8a63 100644 --- a/docs/guide/vex.md +++ b/docs/guide/vex.md @@ -93,9 +93,12 @@ spätestens 14 Tage**, nachdem eine Abhilfe verfügbar ist. Prüfwerk erkennt aktiv ausgenutzte Schwachstellen über den KEV-Katalog der CISA und die SSVC-Bewertung „active“. Ist das Produkt betroffen oder in Prüfung, oder wurde die Schwachstelle behoben, nachdem eine Prüfung ihre -Ausnutzung fand (dann ist der Abschlussbericht fällig), zeigt die Zeile **ENISA-Meldung (Entwurf)** und die Frist der -Frühwarnung (24 Stunden ab der Prüfung, die die Ausnutzung zuerst fand). Der -Entwurf +Ausnutzung fand (dann ist der Abschlussbericht fällig), zeigt die Zeile +**ENISA-Meldung (Entwurf)** und die Fristen der drei Phasen, wie sie beim +Laden stehen: „fällig in N h“, oder rot „überfällig seit …“. Die Fristen +laufen ab der Prüfung, die die Ausnutzung zuerst fand. Eine Schwachstelle ist +eine Meldung, auch wenn mehrere Meldungen sie nennen (ein GitHub-Advisory und +die CVE dazu) oder sie mehrere Komponenten betrifft. Der Entwurf - enthält die Felder der Meldeplattform in ihrer Reihenfolge, je Phase (Frühwarnung, 72-Stunden-Meldung, Abschlussbericht), mit Nummer, Name, diff --git a/docs/release/staging-test-plan-after-v0.4.5.md b/docs/release/staging-test-plan-after-v0.4.5.md index 1c6b539..2e243c3 100644 --- a/docs/release/staging-test-plan-after-v0.4.5.md +++ b/docs/release/staging-test-plan-after-v0.4.5.md @@ -31,6 +31,7 @@ together on stage in one pass before the next prod promotion. | #508 (B1) | Lockfile hashes and download URLs in the SBOM | | #508 (B2) | Component creator (project URL) in the SBOM | | #498 (4/4) | Draft ENISA notifications (CRA Art. 14) for actively exploited vulnerabilities | +| #498 (follow-up) | ENISA deadlines evaluated by the agent; one notification per CVE | **Customer-visible on the next prod rescan** is marked **[visible]**: these change what a customer sees on their existing targets, without them doing @@ -682,6 +683,25 @@ Use the log4j target of check 19 (CVE-2021-44228 is in CISA's KEV). vulnerabilities; the evidence pack gains `enisa-drafts.json` where there are any. +### 32. #498 follow-up: ENISA deadlines and one notification per CVE + +Use the log4j target of check 31. + +- **Do:** `GET /api/v1/targets//enisa`. **Expect:** one entry per CVE + with `alert_ids` (a GHSA alert and the CVE alert of the same CVE share + one), `components`, and `stages` with `due_at`, `overdue`, `hours_left` + for the early warning and the 72 h notification (the final report once a + fix is known), evaluated now: a second call later shows fewer hours. +- **Do:** open the target. **Expect:** the log4j rows show "Frühwarnung + (24 h): fällig in N h" or, once past, in red "überfällig seit "; + "Meldung (72 h)" likewise. Every row of a reportable CVE has the button, + and both download the same draft. +- **Do:** download it. **Expect:** field 12 names every affected component + (`log4j-core 2.14.1, log4j-api 2.14.1`); the evidence pack's + `enisa-drafts.json` holds one draft for the CVE. +- **[visible]** deadlines as "fällig in"/"überfällig seit"; one draft per + vulnerability. + ## After the pass - The nightly job on `main` is green with the new mobile targets.