From af76e516a1431c50d48b6f3c38ca78ce1564f775 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar Date: Mon, 16 Nov 2026 23:09:27 +0000 Subject: [PATCH] feat(vex): what a supplier states about its component's vulnerabilities (#1025) (#1032) --- compliance-agent/src/pipeline/orchestrator.rs | 26 +- .../src/pipeline/sbom/supplied.rs | 377 +++++++++++++++++- .../src/pipeline/vex_lifecycle.rs | 11 +- compliance-agent/tests/vex_lifecycle.rs | 48 +++ compliance-core/src/cve_matrix.rs | 1 + compliance-core/src/models/cve.rs | 7 + compliance-core/src/models/mod.rs | 2 +- compliance-core/src/models/vex.rs | 38 ++ docs/guide/sbom.md | 7 + 9 files changed, 489 insertions(+), 28 deletions(-) diff --git a/compliance-agent/src/pipeline/orchestrator.rs b/compliance-agent/src/pipeline/orchestrator.rs index d6bfb22..438d899 100644 --- a/compliance-agent/src/pipeline/orchestrator.rs +++ b/compliance-agent/src/pipeline/orchestrator.rs @@ -671,7 +671,7 @@ impl PipelineOrchestrator { &repo_id, )); let yocto_recipes = yocto.recipes; - let mut supplied = self.read_supplier_sboms(repo, &repo_id).await?; + let (mut supplied, supplier_statements) = self.read_supplier_sboms(repo, &repo_id).await?; supplied.extend( repo.supplier .as_ref() @@ -900,6 +900,8 @@ impl PipelineOrchestrator { .await; self.match_supplier_advisories(repo, &repo_id, &mut sbom_entries, &mut cve_alerts) .await; + // What the supplier states about each, beside the alert (#1025). + crate::pipeline::sbom::supplied::attach(&supplier_statements, &mut cve_alerts); self.enrich_cves(&repo_id, &mut cve_alerts, &mut sbom_entries) .await; @@ -3254,20 +3256,28 @@ impl PipelineOrchestrator { &self, repo: &RepoView, repo_id: &str, - ) -> Result, AgentError> { - let mut entries = Vec::new(); + ) -> Result< + ( + Vec, + Vec, + ), + AgentError, + > { + let (mut entries, mut statements) = (Vec::new(), Vec::new()); for (path, label) in &repo.supplier_sboms { let (file, id, name) = (path.clone(), repo_id.to_string(), label.clone()); let read = tokio::task::spawn_blocking(move || { - crate::pipeline::sbom::supplied::read(&file, &id, &name) + crate::pipeline::sbom::supplied::read_with_statements(&file, &id, &name) }) .await - .map_err(|e| AgentError::Other(format!("reading the supplier SBOM {label}: {e}")))?; - entries.extend(read.map_err(|e| { + .map_err(|e| AgentError::Other(format!("reading the supplier SBOM {label}: {e}")))? + .map_err(|e| { AgentError::Other(format!("the supplier SBOM {label} cannot be read: {e}")) - })?); + })?; + entries.extend(read.entries); + statements.extend(read.statements); } - Ok(entries) + Ok((entries, statements)) } /// What the target's build outputs say: the images their SPDX archives diff --git a/compliance-agent/src/pipeline/sbom/supplied.rs b/compliance-agent/src/pipeline/sbom/supplied.rs index e721819..b90b857 100644 --- a/compliance-agent/src/pipeline/sbom/supplied.rs +++ b/compliance-agent/src/pipeline/sbom/supplied.rs @@ -15,7 +15,7 @@ use std::path::Path; -use compliance_core::models::SbomEntry; +use compliance_core::models::{CveAlert, SbomEntry, SupplierVex}; use super::syft::{canonical_purl, extract_ecosystem_from_purl}; @@ -119,32 +119,171 @@ pub fn parse( repo_id: &str, label: &str, ) -> Result, SuppliedSbomError> { + parse_with_statements(bytes, repo_id, label).map(|sbom| sbom.entries) +} + +/// A supplier SBOM as read: its components, and what the supplier states +/// about their vulnerabilities (CycloneDX VEX; #1025). +#[derive(Debug)] +pub struct SuppliedSbom { + /// The components, as SBOM entries. + pub entries: Vec, + /// The supplier's statements, one per vulnerability and component. + pub statements: Vec, +} + +/// What the supplier states about one vulnerability of one component. +#[derive(Debug, Clone, PartialEq)] +pub struct SuppliedStatement { + /// The vulnerability as the supplier names it (`CVE-…`, `GHSA-…`). + pub vulnerability: String, + /// The component's name, as its SBOM entry has it. + pub name: String, + /// The component's version. + pub version: String, + /// The component's purl, when it has one. + pub purl: Option, + /// The statement. + pub vex: SupplierVex, +} + +/// [`read`] with the supplier's statements. +/// +/// # Errors +/// +/// A [`SuppliedSbomError`] saying why the file is not read. +pub fn read_with_statements( + path: &Path, + repo_id: &str, + label: &str, +) -> Result { + let size = std::fs::metadata(path) + .map_err(|e| SuppliedSbomError::Io(e.to_string()))? + .len(); + if size > MAX_BYTES { + return Err(SuppliedSbomError::TooLarge); + } + let bytes = std::fs::read(path).map_err(|e| SuppliedSbomError::Io(e.to_string()))?; + parse_with_statements(&bytes, repo_id, label) +} + +/// [`parse`] with the supplier's statements. +/// +/// # Errors +/// +/// A [`SuppliedSbomError`] saying why the document is not read. +pub fn parse_with_statements( + bytes: &[u8], + repo_id: &str, + label: &str, +) -> Result { if bytes.len() as u64 > MAX_BYTES { return Err(SuppliedSbomError::TooLarge); } let text = std::str::from_utf8(bytes) .map_err(|_| SuppliedSbomError::UnknownFormat(" (not UTF-8 text)".to_string()))?; let text = text.trim_start_matches('\u{feff}').trim_start(); - let components = match text.as_bytes().first() { + let doc = match text.as_bytes().first() { Some(b'<') => cyclonedx_xml(text)?, Some(b'{') => json(text)?, _ => return Err(SuppliedSbomError::UnknownFormat(String::new())), }; - if components.len() > MAX_COMPONENTS { + if doc.components.len() > MAX_COMPONENTS { return Err(SuppliedSbomError::TooManyComponents); } - if components.is_empty() { + if doc.components.is_empty() { return Err(SuppliedSbomError::Empty); } - Ok(components + let refs: Vec> = doc.components.iter().map(|c| c.bom_ref.clone()).collect(); + let entries: Vec = doc + .components .into_iter() .map(|c| c.entry(repo_id, label)) - .collect()) + .collect(); + let statements = doc + .statements + .into_iter() + .filter_map(|raw| { + let status = SupplierVex::status_of_state(&raw.state)?; + let vex = SupplierVex { + status, + state: raw.state, + justification: raw.justification, + detail: raw.detail, + response: raw.response, + source: label.to_string(), + }; + Some((raw.id, raw.refs, vex)) + }) + .flat_map(|(id, targets, vex)| { + let (refs, entries) = (&refs, &entries); + targets.into_iter().filter_map(move |target| { + let i = refs + .iter() + .position(|r| r.as_deref() == Some(target.as_str()))?; + Some(SuppliedStatement { + vulnerability: id.clone(), + name: entries[i].name.clone(), + version: entries[i].version.clone(), + purl: entries[i].purl.clone(), + vex: vex.clone(), + }) + }) + }) + .collect(); + Ok(SuppliedSbom { + entries, + statements, + }) +} + +/// Give each of `alerts` the supplier's statement about it, if `statements` +/// has one: the same vulnerability (its id or an alias) in the same +/// component (by purl, else by name and version). An alert the supplier no +/// longer states anything about loses its statement. +pub fn attach(statements: &[SuppliedStatement], alerts: &mut [CveAlert]) { + for alert in alerts { + alert.supplier_vex = statements + .iter() + .find(|st| { + let vulnerability = + st.vulnerability == alert.cve_id || alert.aliases.contains(&st.vulnerability); + let component = match (&st.purl, &alert.purl) { + (Some(ours), Some(theirs)) => ours == theirs, + _ => { + st.name.eq_ignore_ascii_case(&alert.affected_package) + && st.version == alert.affected_version + } + }; + vulnerability && component + }) + .map(|st| st.vex.clone()); + } +} + +/// What a document gives: its components and the supplier's raw statements. +#[derive(Debug, Default)] +struct Doc { + components: Vec, + statements: Vec, +} + +/// One CycloneDX `vulnerabilities[]` entry with an analysis, as written. +#[derive(Debug, Default)] +struct RawStatement { + id: String, + /// The `bom-ref`s of the components it is about (`affects[].ref`). + refs: Vec, + state: String, + justification: Option, + detail: Option, + response: Vec, } /// One component as the document names it. #[derive(Debug, Default, PartialEq)] struct Component { + bom_ref: Option, group: Option, name: String, version: Option, @@ -189,19 +328,25 @@ fn is_part(kind: Option<&str>) -> bool { } /// A JSON document: CycloneDX or SPDX 2, told apart by their markers. -fn json(text: &str) -> Result, SuppliedSbomError> { +fn json(text: &str) -> Result { let doc: serde_json::Value = serde_json::from_str(text).map_err(|e| SuppliedSbomError::Malformed { format: "JSON", reason: e.to_string(), })?; if doc.get("bomFormat").and_then(|v| v.as_str()) == Some("CycloneDX") { - let mut out = Vec::new(); - cyclonedx_json_components(doc.get("components"), &mut out)?; - return Ok(out); + let mut components = Vec::new(); + cyclonedx_json_components(doc.get("components"), &mut components)?; + return Ok(Doc { + components, + statements: cyclonedx_json_statements(doc.get("vulnerabilities")), + }); } match doc.get("spdxVersion").and_then(|v| v.as_str()) { - Some(v) if v.starts_with("SPDX-2.") => spdx2(&doc), + Some(v) if v.starts_with("SPDX-2.") => spdx2(&doc).map(|components| Doc { + components, + statements: Vec::new(), + }), Some(v) => Err(SuppliedSbomError::UnknownFormat(format!( " ({v} is not read yet)" ))), @@ -229,6 +374,7 @@ fn cyclonedx_json_components( if is_part(c.get("type").and_then(|v| v.as_str())) { if let Some(name) = text("name").filter(|n| !n.trim().is_empty()) { out.push(Component { + bom_ref: text("bom-ref"), group: text("group"), name, version: text("version"), @@ -243,6 +389,39 @@ fn cyclonedx_json_components( Ok(()) } +/// The supplier's statements of a CycloneDX JSON `vulnerabilities` array: +/// those with an analysis state. +fn cyclonedx_json_statements(list: Option<&serde_json::Value>) -> Vec { + let text = |v: Option<&serde_json::Value>| v.and_then(|v| v.as_str()).map(str::to_string); + list.and_then(|v| v.as_array()) + .into_iter() + .flatten() + .filter_map(|v| { + let analysis = v.get("analysis")?; + Some(RawStatement { + id: text(v.get("id"))?, + refs: v + .get("affects") + .and_then(|a| a.as_array()) + .into_iter() + .flatten() + .filter_map(|a| text(a.get("ref"))) + .collect(), + state: text(analysis.get("state"))?, + justification: text(analysis.get("justification")), + detail: non_blank(text(analysis.get("detail"))), + response: analysis + .get("response") + .and_then(|r| r.as_array()) + .into_iter() + .flatten() + .filter_map(|r| text(Some(r))) + .collect(), + }) + }) + .collect() +} + /// A CycloneDX JSON `licenses` array as one licence: its expression, else /// the ids or names, all of which apply. fn cyclonedx_json_license(licenses: Option<&serde_json::Value>) -> Option { @@ -267,7 +446,7 @@ fn cyclonedx_json_license(licenses: Option<&serde_json::Value>) -> Option Result, SuppliedSbomError> { +fn cyclonedx_xml(text: &str) -> Result { let doc = roxmltree::Document::parse(text).map_err(|e| SuppliedSbomError::Malformed { format: "XML", reason: e.to_string(), @@ -283,11 +462,51 @@ fn cyclonedx_xml(text: &str) -> Result, SuppliedSbomError> { " (an XML document, but not a CycloneDX BOM)".to_string(), )); } - let mut out = Vec::new(); + let mut components = Vec::new(); if let Some(list) = child(root, "components") { - cyclonedx_xml_components(list, &mut out)?; + cyclonedx_xml_components(list, &mut components)?; } - Ok(out) + Ok(Doc { + components, + statements: child(root, "vulnerabilities") + .map(cyclonedx_xml_statements) + .unwrap_or_default(), + }) +} + +/// The supplier's statements of a CycloneDX XML `vulnerabilities` element, +/// as for JSON. +fn cyclonedx_xml_statements(list: roxmltree::Node<'_, '_>) -> Vec { + elements(list, "vulnerability") + .filter_map(|v| { + let analysis = child(v, "analysis")?; + Some(RawStatement { + id: child_text(v, "id")?, + refs: child(v, "affects") + .into_iter() + .flat_map(|a| elements(a, "target")) + .filter_map(|t| child_text(t, "ref")) + .collect(), + state: child_text(analysis, "state")?, + justification: child_text(analysis, "justification"), + detail: non_blank(child_text(analysis, "detail")), + response: child(analysis, "responses") + .into_iter() + .flat_map(|r| elements(r, "response")) + .filter_map(|r| r.text().map(str::to_string)) + .collect(), + }) + }) + .collect() +} + +/// The child elements of `node` named `name`. +fn elements<'a, 'input>( + node: roxmltree::Node<'a, 'input>, + name: &'static str, +) -> impl Iterator> { + node.children() + .filter(move |n| n.is_element() && n.tag_name().name() == name) } /// The child element of `node` named `name`. @@ -320,6 +539,7 @@ fn cyclonedx_xml_components( if is_part(c.attribute("type")) { if let Some(name) = child_text(c, "name").filter(|n| !n.trim().is_empty()) { out.push(Component { + bom_ref: c.attribute("bom-ref").map(str::to_string), group: child_text(c, "group"), name, version: child_text(c, "version"), @@ -396,6 +616,7 @@ fn spdx2(doc: &serde_json::Value) -> Result, SuppliedSbomError> { }; let name = text("name").filter(|n| !n.trim().is_empty())?; Some(Component { + bom_ref: None, group: None, name, version: text("versionInfo"), @@ -515,6 +736,132 @@ mod tests { assert!(product_entry(&supplier(Some(url), None), "t1").is_none()); } + const CDX_VEX_JSON: &str = r#"{ + "bomFormat": "CycloneDX", "specVersion": "1.5", + "components": [ + {"type": "library", "bom-ref": "lodash@4.17.20", "name": "lodash", "version": "4.17.20", + "purl": "pkg:npm/lodash@4.17.20"}, + {"type": "library", "bom-ref": "blob", "name": "vendor-blob", "version": "2.0"} + ], + "vulnerabilities": [ + {"id": "CVE-2021-23337", "affects": [{"ref": "lodash@4.17.20"}], + "analysis": {"state": "not_affected", "justification": "code_not_reachable", + "detail": " template() is never called. ", "response": ["will_not_fix"]}}, + {"id": "CVE-2026-1", "affects": [{"ref": "blob"}, {"ref": "nowhere"}], + "analysis": {"state": "exploitable", "response": ["update"]}}, + {"id": "CVE-2026-2", "affects": [{"ref": "blob"}], "analysis": {"state": "unheard_of"}}, + {"id": "CVE-2026-3", "affects": [{"ref": "blob"}]} + ] + }"#; + + #[test] + fn a_suppliers_cyclonedx_vex_is_read_per_component() { + use compliance_core::models::VexStatus; + let sbom = parse_with_statements(CDX_VEX_JSON.as_bytes(), "t1", "pump.cdx.json").unwrap(); + assert_eq!(sbom.entries.len(), 2); + // Unknown states and statements without an analysis are left out, + // and so is a ref that names no component. + assert_eq!(sbom.statements.len(), 2, "{:?}", sbom.statements); + let lodash = &sbom.statements[0]; + assert_eq!(lodash.vulnerability, "CVE-2021-23337"); + assert_eq!(lodash.purl.as_deref(), Some("pkg:npm/lodash@4.17.20")); + assert_eq!(lodash.vex.status, VexStatus::NotAffected); + assert_eq!( + lodash.vex.justification.as_deref(), + Some("code_not_reachable") + ); + assert_eq!( + lodash.vex.detail.as_deref(), + Some("template() is never called.") + ); + assert_eq!(lodash.vex.response, ["will_not_fix"]); + assert_eq!(lodash.vex.source, "pump.cdx.json"); + let blob = &sbom.statements[1]; + assert_eq!( + (blob.name.as_str(), blob.version.as_str()), + ("vendor-blob", "2.0") + ); + assert_eq!(blob.vex.status, VexStatus::Affected); + } + + #[test] + fn a_suppliers_cyclonedx_xml_vex_reads_as_its_json() { + let xml = r#" + + + lodash4.17.20 + pkg:npm/lodash@4.17.20 + + + CVE-2021-23337 + not_affectedcode_not_reachable + template() is never called. + will_not_fix + lodash@4.17.20 + + +"#; + let from_xml = parse_with_statements(xml.as_bytes(), "t1", "pump.cdx.json").unwrap(); + let from_json = + parse_with_statements(CDX_VEX_JSON.as_bytes(), "t1", "pump.cdx.json").unwrap(); + assert_eq!(from_xml.statements, from_json.statements[..1]); + } + + #[test] + fn a_statement_goes_to_the_alert_of_its_vulnerability_and_component() { + use compliance_core::models::CveSource; + let sbom = parse_with_statements(CDX_VEX_JSON.as_bytes(), "t1", "pump.cdx.json").unwrap(); + let alert = |id: &str, package: &str, version: &str, purl: Option<&str>| { + let mut a = CveAlert::new( + id.into(), + "t1".into(), + package.into(), + version.into(), + CveSource::Osv, + ); + a.purl = purl.map(String::from); + a + }; + let mut by_alias = alert( + "GHSA-35jh-r3h4-6jhm", + "lodash", + "4.17.20", + Some("pkg:npm/lodash@4.17.20"), + ); + by_alias.aliases = vec!["CVE-2021-23337".into()]; + let mut stale = alert( + "CVE-2021-23337", + "lodash", + "4.17.21", + Some("pkg:npm/lodash@4.17.21"), + ); + stale.supplier_vex = sbom.statements[0].vex.clone().into(); + let mut alerts = vec![ + by_alias, + alert("CVE-2026-1", "vendor-blob", "2.0", None), + stale, + ]; + + attach(&sbom.statements, &mut alerts); + + assert!( + alerts[0].supplier_vex.is_some(), + "matched by its alias and purl" + ); + assert!( + alerts[1].supplier_vex.is_some(), + "matched by name and version" + ); + assert!( + alerts[2].supplier_vex.is_none(), + "another version: the statement goes" + ); + // It settles nothing: the alert's own status is unchanged. + assert!(alerts + .iter() + .all(|a| a.vex.is_none() && !a.is_resolved_by_vex())); + } + #[test] fn an_xml_sbom_with_a_dtd_is_refused() { let xml = r#" diff --git a/compliance-agent/src/pipeline/vex_lifecycle.rs b/compliance-agent/src/pipeline/vex_lifecycle.rs index 48abfa8..cb0442a 100644 --- a/compliance-agent/src/pipeline/vex_lifecycle.rs +++ b/compliance-agent/src/pipeline/vex_lifecycle.rs @@ -128,11 +128,14 @@ pub async fn upsert_reported(db: &Database, alert: &CveAlert) -> Result<(), Agen .update_one(other_component, doc! { "$unset": { "purl": "" } }) .await?; } + // A supplier's statement (#1025) is restated by every scan; one the + // supplier no longer makes goes. + let mut unset = doc! { "resolved_at": "" }; + if alert.supplier_vex.is_none() { + unset.insert("supplier_vex", ""); + } db.cve_alerts() - .update_one( - filter.clone(), - doc! { "$set": found, "$unset": { "resolved_at": "" } }, - ) + .update_one(filter.clone(), doc! { "$set": found, "$unset": unset }) .upsert(true) .await?; // The first scan that finds it actively exploited starts the CRA's diff --git a/compliance-agent/tests/vex_lifecycle.rs b/compliance-agent/tests/vex_lifecycle.rs index 9e040a5..75dc865 100644 --- a/compliance-agent/tests/vex_lifecycle.rs +++ b/compliance-agent/tests/vex_lifecycle.rs @@ -468,3 +468,51 @@ async fn not_affected_and_fixed_raise_no_notification_until_withdrawn() { pool.drop_tenant(tenant).await.ok(); } + +/// #1025: a supplier's statement is stored with the alert as the scan read +/// it, beside (never in) the alert's own VEX, and goes once a scan's SBOM no +/// longer states it. +#[tokio::test] +async fn a_suppliers_statement_is_restated_by_each_scan() { + let uri = std::env::var("TEST_MONGODB_URI") + .unwrap_or_else(|_| "mongodb://root:example@localhost:27017/?authSource=admin".into()); + let prefix = format!( + "vexsup_{}", + &uuid::Uuid::new_v4().simple().to_string()[..10] + ); + let Ok(pool) = DatabasePool::connect(&uri, &prefix).await else { + eprintln!("SKIP vex_lifecycle: no MongoDB reachable at {uri}"); + return; + }; + let tenant = "vex-supplier"; + let Ok(db) = pool.for_tenant_id(tenant).await else { + eprintln!("SKIP vex_lifecycle: MongoDB at {uri} not usable"); + return; + }; + let mut stated = alert("CVE-7"); + stated.supplier_vex = Some(compliance_core::models::SupplierVex { + status: VexStatus::NotAffected, + state: "not_affected".into(), + justification: Some("code_not_reachable".into()), + detail: None, + response: Vec::new(), + source: "pump.cdx.json".into(), + }); + + upsert_reported(&db, &stated).await.unwrap(); + let first = stored(&db, "CVE-7").await; + assert_eq!( + first.supplier_vex.as_ref().map(|v| v.status), + Some(VexStatus::NotAffected) + ); + assert!( + first.vex.is_none(), + "it is not the manufacturer's statement" + ); + assert!(!first.is_resolved_by_vex(), "and settles nothing"); + + upsert_reported(&db, &alert("CVE-7")).await.unwrap(); + assert!(stored(&db, "CVE-7").await.supplier_vex.is_none()); + + pool.drop_tenant(tenant).await.ok(); +} diff --git a/compliance-core/src/cve_matrix.rs b/compliance-core/src/cve_matrix.rs index 8528046..1b36b77 100644 --- a/compliance-core/src/cve_matrix.rs +++ b/compliance-core/src/cve_matrix.rs @@ -318,6 +318,7 @@ mod tests { at: chrono::Utc::now(), by_scan: false, }), + supplier_vex: None, resolved_at: None, exploited_seen_at: None, created_at: chrono::Utc::now(), diff --git a/compliance-core/src/models/cve.rs b/compliance-core/src/models/cve.rs index c68a240..c732770 100644 --- a/compliance-core/src/models/cve.rs +++ b/compliance-core/src/models/cve.rs @@ -118,6 +118,12 @@ pub struct CveAlert { /// The VEX statement on it (#498); none until someone states one. #[serde(default, skip_serializing_if = "Option::is_none")] pub vex: Option, + /// What the supplier of a bought-in component states about it in its SBOM + /// (#1025). Restated by every scan from the current SBOM, dropped when the + /// supplier no longer states it. Never the manufacturer's own statement: + /// it settles nothing and is not exported as one. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub supplier_vex: Option, /// When a complete scan last found it gone (the component removed or /// past a fixed version); `None` while it is reported. #[serde( @@ -237,6 +243,7 @@ impl CveAlert { exploitation: None, advisories: Vec::new(), vex: None, + supplier_vex: None, resolved_at: None, exploited_seen_at: None, created_at: Utc::now(), diff --git a/compliance-core/src/models/mod.rs b/compliance-core/src/models/mod.rs index d8ab851..88996bb 100644 --- a/compliance-core/src/models/mod.rs +++ b/compliance-core/src/models/mod.rs @@ -91,7 +91,7 @@ pub use scan::{ RunErrorCode, RunNote, ScanPhase, ScanRun, ScanRunStatus, ScanStep, ScanType, SkipCode, SkippedStage, }; -pub use vex::{VexAssessment, VexError, VexJustification, VexStatus}; +pub use vex::{SupplierVex, VexAssessment, VexError, VexJustification, VexStatus}; pub use webhook_delivery::{DeliveryResult, WebhookDelivery, DELIVERIES_SHOWN}; pub use werkbank::{ CompleteRequest, CompleteResponse, DastCollect, Executor, HeartbeatAck, HeartbeatRequest, diff --git a/compliance-core/src/models/vex.rs b/compliance-core/src/models/vex.rs index 20908c7..c40c871 100644 --- a/compliance-core/src/models/vex.rs +++ b/compliance-core/src/models/vex.rs @@ -94,6 +94,44 @@ pub struct VexAssessment { pub by_scan: bool, } +/// A supplier's VEX statement on a vulnerability of its component, as its +/// SBOM gives it (CycloneDX `vulnerabilities[].analysis`; #1025). Shown to +/// the person who decides, beside the manufacturer's own statement; it +/// settles nothing by itself. +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct SupplierVex { + /// The status as OpenVEX names it, read from `state`. + pub status: VexStatus, + /// CycloneDX's `state` as the supplier wrote it (`not_affected`, + /// `resolved`, `exploitable`, `in_triage`, `false_positive`, …). + pub state: String, + /// CycloneDX's `justification` as the supplier wrote it. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub justification: Option, + /// The supplier's explanation (`detail`). + #[serde(default, skip_serializing_if = "Option::is_none")] + pub detail: Option, + /// What the supplier says to do (`response`: `update`, `workaround_available`, …). + #[serde(default, skip_serializing_if = "Vec::is_empty")] + pub response: Vec, + /// The SBOM it was read from (its file name). + pub source: String, +} + +impl SupplierVex { + /// The OpenVEX status of a CycloneDX analysis `state`; `None` for one + /// CycloneDX does not define. + pub fn status_of_state(state: &str) -> Option { + Some(match state { + "resolved" | "resolved_with_pedigree" => VexStatus::Fixed, + "exploitable" => VexStatus::Affected, + "in_triage" => VexStatus::UnderInvestigation, + "not_affected" | "false_positive" => VexStatus::NotAffected, + _ => return None, + }) + } +} + /// Why a VEX statement cannot be stored. #[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)] pub enum VexError { diff --git a/docs/guide/sbom.md b/docs/guide/sbom.md index 6945953..6060a72 100644 --- a/docs/guide/sbom.md +++ b/docs/guide/sbom.md @@ -123,6 +123,13 @@ go through the same CVE groups, VEX statements and ENISA drafts. the supplier's name and version for it, and against its components by purl. A matching advisory raises a CVE alert with the supplier's remediation and fixed versions. +- **What the supplier states about a vulnerability:** a CycloneDX SBOM can + carry the supplier's VEX (`vulnerabilities[].analysis`: state, + justification, detail, response). Prüfwerk reads it for each component and + keeps it with the alert as the supplier's statement (`supplier_vex`). Every + scan reads it again from the current SBOM. It is shown to whoever decides, + but it is not your statement: it settles no alert, closes no issue and is + not exported as yours. Your own VEX status stays yours to state. ### When the SBOM is empty or incomplete