fix(csaf): vendor remediations named through product groups (#515) #523
No files matched your search
@@ -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<mongodb::bson::Document> = self
|
||||
.collection
|
||||
.clone_with_type::<mongodb::bson::Document>()
|
||||
.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)
|
||||
|
||||
@@ -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<AdvisoryProduct> {
|
||||
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<String, Vec<String>> {
|
||||
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<String, Vec<String>>,
|
||||
) -> AdvisoryVulnerability {
|
||||
let status = v.get("product_status").cloned().unwrap_or_default();
|
||||
let ids = |keys: &[&str]| -> Vec<String> {
|
||||
let mut out: Vec<String> = 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<Advisory, CsafError> {
|
||||
})
|
||||
.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<Advisory, CsafError> {
|
||||
.and_then(|v| v.as_array())
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.map(vulnerability)
|
||||
.map(|v| vulnerability(v, &groups))
|
||||
.collect(),
|
||||
})
|
||||
}
|
||||
@@ -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"]
|
||||
|
||||
+1
-1
@@ -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.
|
||||
+67
-9
@@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
Reference in new issue
Block a user