From 65caaa4c0239a3c9d71bcea0a721e903969e351f Mon Sep 17 00:00:00 2001 From: JEAN REGIS <190766850+Jean-Regis-M@users.noreply.github.com> Date: Sat, 28 Nov 2026 20:44:22 +0300 Subject: [PATCH] Skip deallocated and withdrawn XSAs in the Xen importer xsa.json lists deallocated numbers (an id and a date) and withdrawn advisories next to the real ones. They were imported as advisories with an empty summary and no aliases. Fixes #2548 Signed-off-by: JEAN REGIS <190766850+Jean-Regis-M@users.noreply.github.com> --- .../pipelines/v2_importers/xen_importer.py | 21 +++++++++++- .../v2_importers/test_xen_importer_v2.py | 33 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/vulnerabilities/pipelines/v2_importers/xen_importer.py b/vulnerabilities/pipelines/v2_importers/xen_importer.py index 6968a23cb..bccef79b8 100644 --- a/vulnerabilities/pipelines/v2_importers/xen_importer.py +++ b/vulnerabilities/pipelines/v2_importers/xen_importer.py @@ -72,7 +72,9 @@ def get_xsa_data(self): def advisories_count(self) -> int: data = self.get_xsa_data() - return len(data[0].get("xsas", [])) if data else 0 + if not data: + return 0 + return sum(1 for xsa in data[0].get("xsas", []) if not is_placeholder(xsa)) def collect_advisories(self) -> Iterable[AdvisoryDataV2]: data = self.get_xsa_data() @@ -80,6 +82,8 @@ def collect_advisories(self) -> Iterable[AdvisoryDataV2]: return for xsa in data[0].get("xsas", []): + if is_placeholder(xsa): + continue yield from self.to_advisories(xsa) def to_advisories(self, xsa) -> Iterable[AdvisoryDataV2]: @@ -103,3 +107,18 @@ def to_advisories(self, xsa) -> Iterable[AdvisoryDataV2]: date_published=parser.parse(date_published), original_advisory_text=json.dumps(xsa, indent=2, ensure_ascii=False), ) + + +def is_placeholder(xsa) -> bool: + """ + Return True for an xsa.json entry that carries no advisory: a deallocated + number (only an id and a date) or a withdrawn advisory. + + >>> is_placeholder({"xsa": "79", "deallocated": True}) + True + >>> is_placeholder({"xsa": "283", "withdrawn": True, "title": "Withdrawn"}) + True + >>> is_placeholder({"xsa": "123", "title": "Sample"}) + False + """ + return bool(xsa.get("deallocated") or xsa.get("withdrawn")) diff --git a/vulnerabilities/tests/pipelines/v2_importers/test_xen_importer_v2.py b/vulnerabilities/tests/pipelines/v2_importers/test_xen_importer_v2.py index 8ff221de8..06d73ed10 100644 --- a/vulnerabilities/tests/pipelines/v2_importers/test_xen_importer_v2.py +++ b/vulnerabilities/tests/pipelines/v2_importers/test_xen_importer_v2.py @@ -100,3 +100,36 @@ def test_to_advisories_missing_fields(pipeline): assert advisory.advisory_id == "XSA-None" assert advisory.aliases == [] assert advisory.summary == None + + +# Placeholders as published in xsa.json: a deallocated number has no title or +# CVE, and a withdrawn advisory only keeps a generic title. +XSA_WITH_PLACEHOLDERS = [ + { + "xsas": [ + {"xsa": "79", "public_time": "2013-11-27 13:20", "deallocated": True}, + { + "xsa": "283", + "title": "Withdrawn Xen Security Advisory number", + "public_time": "2019-02-22 17:42", + "withdrawn": True, + }, + { + "xsa": "123", + "title": "Sample Xen Advisory", + "public_time": "2022-09-15 00:00", + "cve": ["CVE-2022-12345"], + }, + ] + } +] + + +@patch("vulnerabilities.pipelines.v2_importers.xen_importer.fetch_response") +def test_deallocated_and_withdrawn_xsas_are_skipped(mock_fetch, pipeline): + mock_fetch.return_value.json.return_value = XSA_WITH_PLACEHOLDERS + + advisories = list(pipeline.collect_advisories()) + + assert [a.advisory_id for a in advisories] == ["XSA-123"] + assert pipeline.advisories_count() == 1