Merge a CVE that Fortinet lists once per product family
CI / Python 3.13 (push) Successful in 39s
CI / Python 3.12 (push) Successful in 42s
CI / Build and smoke-test image (push) Successful in 10s

This commit is contained in:
omar committed 2026-11-29 10:15:14 +03:00
1 parent f8e5b1faf1
commit b169643c0e
2 files changed
+37

No files matched your search

+25
View File
@@ -313,6 +313,30 @@ def _project_tree(tree: dict[str, object]) -> tuple[dict[str, object], dict[str,
}, scope_by_id, groups)
def _merged(rows: list[dict[str, object]]) -> list[dict[str, object]]:
"""A CVE may repeat once per product family; the parser wants each one once."""
merged: dict[object, dict[str, object]] = {}
for row in rows:
key = row.get("cve")
target = merged.get(key)
if target is None:
merged[key] = dict(row)
continue
for field in ("product_status", "remediations", "cwe"):
if field in row:
current = target.get(field)
if isinstance(current, list) and isinstance(row[field], list):
current.extend(row[field])
else:
target[field] = row[field]
if "product_status" in target:
status = target["product_status"]
for name, values in status.items():
if isinstance(values, list):
status[name] = list(dict.fromkeys(values))
return list(merged.values())
def _remediations(issue: Issue, raw: object, groups: dict[str, list[str]], scope_by_id: dict[str, str]) -> None:
products = {row["product_id"]: row for row in issue.products}
for value in _list(raw):
@@ -374,6 +398,7 @@ def _csaf(content: bytes, native: str) -> Doc:
# Recent advisories are published as stubs first: identity and dates only,
# vulnerabilities appear on a later revision.
vulnerabilities = _objects(root.get("vulnerabilities", []))
vulnerabilities = _merged(vulnerabilities)
projection = {
"document": {"csaf_version": document.get("csaf_version"), "title": native, "publisher": {"name": _PUBLISHER},
"tracking": {"id": native, "current_release_date": _date(tracking.get("current_release_date"))}},
+12
View File
@@ -324,3 +324,15 @@ def test_inline_fixed_version_in_product_status_is_recovered() -> None:
recovered = [p for issue in doc.issues for p in issue.products if p["product_id"] == "FortiSandbox-5.0.5"]
[product] = recovered
assert (product["name"], product["version"], product["status"]) == ("FortiSandbox", "5.0.5", "not_affected")
def test_repeated_cve_entry_is_merged_into_one_issue() -> None:
body = json.loads(csaf())
first = body["vulnerabilities"][0]
second = json.loads(json.dumps(first))
second["product_status"] = {"known_not_affected": ["FortiSandbox-5.2.0"]}
body["vulnerabilities"].append(second)
doc = _csaf(json.dumps(body).encode(), NATIVE)
assert [issue.id for issue in doc.issues].count(first["cve"]) == 1
issue = next(i for i in doc.issues if i.id == first["cve"])
assert any(p["product_id"] == "FortiSandbox-5.2.0" for p in issue.products)