From 048fdfa552c8bd04c972635db0931f4b98b26b33 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Tue, 6 Oct 2026 19:10:56 +0200 Subject: [PATCH] fix(csaf): vendor remediations named through product groups (#515) Found in the pre-verification of the staging test plan (check 36): every CODESYS alert from a CSAF advisory came without the vendor's remediation. CERT@VDE's vendors name a remediation's products through `group_ids` (product_tree.product_groups), and the reader only took `product_ids`. - csaf_ingest: remediations resolve their group_ids through the product groups. PARSER_VERSION (2) records how advisories were read. - csaf_feed: stored rows carry the parser version; a row read by an older one counts as unknown, so the next refresh fetches and reads it again (CERT@VDE's providers come before Siemens, so CODESYS's 36 are re-read in the first run). - The synthetic VDE-shaped fixture names its remediation through a group, as the real ones do; the matcher test's remediation assertion now covers it. Co-Authored-By: Claude Opus 5.5 (1M context) Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p --- compliance-agent/src/pipeline/csaf_feed.rs | 9 ++- compliance-core/src/csaf_ingest.rs | 42 +++++++++- compliance-core/tests/csaf_ingest.rs | 2 + compliance-core/tests/fixtures/csaf/README.md | 2 +- .../tests/fixtures/csaf/vde-synthetic.json | 76 ++++++++++++++++--- 5 files changed, 116 insertions(+), 15 deletions(-) diff --git a/compliance-agent/src/pipeline/csaf_feed.rs b/compliance-agent/src/pipeline/csaf_feed.rs index a952219..a978b92 100644 --- a/compliance-agent/src/pipeline/csaf_feed.rs +++ b/compliance-agent/src/pipeline/csaf_feed.rs @@ -198,6 +198,10 @@ pub(crate) struct StoredAdvisory { pub updated: String, pub advisory: Advisory, pub fetched_at: mongodb::bson::DateTime, + /// The [`csaf_ingest::PARSER_VERSION`] it was read with; a row read by + /// an older one is read again. + #[serde(default)] + pub parser: u32, } /// The index in the admin database (`csaf_advisories`), shared by all @@ -231,7 +235,9 @@ impl AdvisoryStore for MongoAdvisoryStore { let rows: Vec = self .collection .clone_with_type::() - .find(doc! { "provider": provider }) + // A row an older reading stored counts as unknown, so it is + // fetched and read again. + .find(doc! { "provider": provider, "parser": csaf_ingest::PARSER_VERSION }) .projection(doc! { "advisory.id": 1, "updated": 1 }) .await .map_err(|e| e.to_string())? @@ -261,6 +267,7 @@ impl AdvisoryStore for MongoAdvisoryStore { updated: updated.to_string(), advisory: advisory.clone(), fetched_at: mongodb::bson::DateTime::now(), + parser: csaf_ingest::PARSER_VERSION, }; self.collection .replace_one(doc! { "_id": &row.key }, &row) diff --git a/compliance-core/src/csaf_ingest.rs b/compliance-core/src/csaf_ingest.rs index 1d84493..e15e53e 100644 --- a/compliance-core/src/csaf_ingest.rs +++ b/compliance-core/src/csaf_ingest.rs @@ -9,10 +9,18 @@ //! are its ancestors'; `full_product_names` and the products relationships //! define (a component `installed_on` a platform) are products too. +use std::collections::HashMap; + use serde::{Deserialize, Serialize}; use crate::version::{cmp_dotted, Vers}; +/// The version of this reading. Bump it when [`parse`] reads more or +/// differently, so the advisory index reads its stored advisories again. +/// +/// 2: remediations name their products through product groups too. +pub const PARSER_VERSION: u32 = 2; + /// A product an advisory names. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct AdvisoryProduct { @@ -277,8 +285,22 @@ fn products(tree: &serde_json::Value) -> Vec { out } -/// One vulnerability. -fn vulnerability(v: &serde_json::Value) -> AdvisoryVulnerability { +/// The product groups of `tree`: group id to its product ids. +fn product_groups(tree: &serde_json::Value) -> HashMap> { + tree.get("product_groups") + .and_then(|g| g.as_array()) + .into_iter() + .flatten() + .filter_map(|g| Some((text(g, "group_id")?, strings(g, "product_ids")))) + .collect() +} + +/// One vulnerability; `groups` resolves the product groups a remediation +/// names (CERT@VDE's vendors name theirs that way). +fn vulnerability( + v: &serde_json::Value, + groups: &HashMap>, +) -> AdvisoryVulnerability { let status = v.get("product_status").cloned().unwrap_or_default(); let ids = |keys: &[&str]| -> Vec { let mut out: Vec = Vec::new(); @@ -330,11 +352,19 @@ fn vulnerability(v: &serde_json::Value) -> AdvisoryVulnerability { .into_iter() .flatten() .filter_map(|r| { + let mut product_ids = strings(r, "product_ids"); + for group in strings(r, "group_ids") { + for id in groups.get(&group).into_iter().flatten() { + if !product_ids.contains(id) { + product_ids.push(id.clone()); + } + } + } Some(Remediation { category: text(r, "category")?, details: text(r, "details").unwrap_or_default(), url: text(r, "url"), - product_ids: strings(r, "product_ids"), + product_ids, }) }) .collect(); @@ -386,6 +416,10 @@ pub fn parse(doc: &serde_json::Value) -> Result { }) .or(selves.first()) .cloned(); + let groups = doc + .get("product_tree") + .map(product_groups) + .unwrap_or_default(); Ok(Advisory { id, title: text(document, "title").unwrap_or_default(), @@ -405,7 +439,7 @@ pub fn parse(doc: &serde_json::Value) -> Result { .and_then(|v| v.as_array()) .into_iter() .flatten() - .map(vulnerability) + .map(|v| vulnerability(v, &groups)) .collect(), }) } diff --git a/compliance-core/tests/csaf_ingest.rs b/compliance-core/tests/csaf_ingest.rs index a200843..c405e0f 100644 --- a/compliance-core/tests/csaf_ingest.rs +++ b/compliance-core/tests/csaf_ingest.rs @@ -49,6 +49,8 @@ fn a_vendor_advisory_gives_ranges_fixes_and_remediations() { Some("A crafted request can crash the runtime.") ); assert_eq!(v.remediations[0].category, "vendor_fix"); + // Named through its product group, as CERT@VDE's vendors do. + assert_eq!(v.remediations[0].product_ids, ["CSAFPID-51001"]); assert_eq!( a.fixed_versions(v, "Example Control for Linux SL"), ["3.5.22.40"] diff --git a/compliance-core/tests/fixtures/csaf/README.md b/compliance-core/tests/fixtures/csaf/README.md index db68e2e..f6692fa 100644 --- a/compliance-core/tests/fixtures/csaf/README.md +++ b/compliance-core/tests/fixtures/csaf/README.md @@ -4,6 +4,6 @@ |---|---|---| | `icsa-26-260-07.json` | CISA ICS advisory ICSA-26-260-07, from https://raw.githubusercontent.com/cisagov/CSAF/develop/csaf_files/OT/white/2026/icsa-26-260-07.json (original: https://www.cisa.gov/news-events/ics-advisories/icsa-26-260-07) | US government work; CISA notification and privacy & use policy | | `ssa-240718.json` | Siemens ProductCERT SSA-240718, from https://cert-portal.siemens.com/productcert/csaf/ssa-240718.json (original: https://cert-portal.siemens.com/productcert/html/ssa-240718.html) | Siemens Security Advisories terms of use (https://www.siemens.com/productcert/terms-of-use): redistribution allowed with a link to the original, given here | -| `vde-synthetic.json` | Written for these tests in the shape of CERT@VDE's vendor advisories; every name, id and CVE is made up | ours | +| `vde-synthetic.json` | Written for these tests in the shape of CERT@VDE's vendor advisories (remediations name product groups); every name, id and CVE is made up | ours | Unchanged copies of the published documents; replace them only by copying the upstream file again. diff --git a/compliance-core/tests/fixtures/csaf/vde-synthetic.json b/compliance-core/tests/fixtures/csaf/vde-synthetic.json index 24e4572..21ad15d 100644 --- a/compliance-core/tests/fixtures/csaf/vde-synthetic.json +++ b/compliance-core/tests/fixtures/csaf/vde-synthetic.json @@ -8,10 +8,23 @@ "name": "Example Automation GmbH", "namespace": "https://example.invalid" }, - "distribution": { "tlp": { "label": "WHITE", "url": "https://www.first.org/tlp/" } }, + "distribution": { + "tlp": { + "label": "WHITE", + "url": "https://www.first.org/tlp/" + } + }, "references": [ - { "category": "self", "summary": "CSAF", "url": "https://example.invalid/csaf/white/2026/vde-2026-9001.json" }, - { "category": "self", "summary": "Advisory", "url": "https://certvde.com/en/advisories/VDE-2026-9001" } + { + "category": "self", + "summary": "CSAF", + "url": "https://example.invalid/csaf/white/2026/vde-2026-9001.json" + }, + { + "category": "self", + "summary": "Advisory", + "url": "https://certvde.com/en/advisories/VDE-2026-9001" + } ], "tracking": { "id": "VDE-2026-9001", @@ -19,7 +32,13 @@ "version": "1", "current_release_date": "2026-10-01T08:00:00.000Z", "initial_release_date": "2026-10-01T08:00:00.000Z", - "revision_history": [{ "date": "2026-10-01T08:00:00.000Z", "number": "1", "summary": "Initial" }] + "revision_history": [ + { + "date": "2026-10-01T08:00:00.000Z", + "number": "1", + "summary": "Initial" + } + ] } }, "product_tree": { @@ -42,7 +61,9 @@ "product": { "name": "Example Control for Linux SL <3.5.22.40", "product_id": "CSAFPID-51001", - "product_identification_helper": { "cpe": "cpe:2.3:a:example:example_control_for_linux_sl:*:*:*:*:*:*:*:*" } + "product_identification_helper": { + "cpe": "cpe:2.3:a:example:example_control_for_linux_sl:*:*:*:*:*:*:*:*" + } } }, { @@ -59,19 +80,56 @@ } ] } + ], + "product_groups": [ + { + "group_id": "CSAFGID-1001", + "product_ids": [ + "CSAFPID-51001" + ] + } ] }, "vulnerabilities": [ { "cve": "CVE-2026-90001", "title": "Improper input validation in the example runtime", - "notes": [{ "category": "description", "text": "A crafted request can crash the runtime." }], - "product_status": { "known_affected": ["CSAFPID-51001"], "fixed": ["CSAFPID-52001"] }, + "notes": [ + { + "category": "description", + "text": "A crafted request can crash the runtime." + } + ], + "product_status": { + "known_affected": [ + "CSAFPID-51001" + ], + "fixed": [ + "CSAFPID-52001" + ] + }, "remediations": [ - { "category": "vendor_fix", "details": "Update to version 3.5.22.40.", "url": "https://example.invalid/download", "product_ids": ["CSAFPID-51001"] } + { + "category": "vendor_fix", + "details": "Update to version 3.5.22.40.", + "url": "https://example.invalid/download", + "group_ids": [ + "CSAFGID-1001" + ] + } ], "scores": [ - { "products": ["CSAFPID-51001"], "cvss_v3": { "version": "3.1", "vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H", "baseScore": 7.5, "baseSeverity": "HIGH" } } + { + "products": [ + "CSAFPID-51001" + ], + "cvss_v3": { + "version": "3.1", + "vectorString": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H", + "baseScore": 7.5, + "baseSeverity": "HIGH" + } + } ] } ] -- 2.54.1