From 5c1041d3daa2a6f52ea0c9794b56878657aa23d7 Mon Sep 17 00:00:00 2001 From: omar Date: Sun, 29 Nov 2026 08:04:03 +0300 Subject: [PATCH] Drop unparsable OSV auxiliary references instead of the whole import --- src/vuln_mcp/sources/parsers.py | 18 +++++++++++++++--- tests/test_sources.py | 15 +++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/vuln_mcp/sources/parsers.py b/src/vuln_mcp/sources/parsers.py index ed33f8b..40ecd71 100644 --- a/src/vuln_mcp/sources/parsers.py +++ b/src/vuln_mcp/sources/parsers.py @@ -76,6 +76,18 @@ def _id(raw: object, *, cve: bool = False) -> str: return value.upper() if cve else value +def _ids(raw: object) -> list[str]: + # Auxiliary references are sometimes URLs or free text; one odd value must + # not throw away a whole document, so unparsable entries are dropped. + found = [] + for value in _array(raw): + try: + found.append(_id(value)) + except InvalidData: + continue + return list(dict.fromkeys(found)) + + def _text(raw: object, *, limit: int = 800) -> str: if not isinstance(raw, str): return "" @@ -401,12 +413,12 @@ def _osv(raw: dict[str, Any], url: str) -> Doc: if withdrawn is not None: _str(withdrawn) publisher = native.split("-", 1)[0] - issue = Issue(id=native, aliases=[_id(value) for value in _array(raw.get("aliases", []))], + issue = Issue(id=native, aliases=_ids(raw.get("aliases", [])), summary=details or summary, facts={"data_source_terms": "https://google.github.io/osv.dev/data/#current-data-sources"}) issue.facts.update(_compact(withdrawn=withdrawn, - related=[_id(value) for value in _array(raw.get("related", []))], - upstream=[_id(value) for value in _array(raw.get("upstream", []))])) + related=_ids(raw.get("related", [])), + upstream=_ids(raw.get("upstream", [])))) if not withdrawn: issue.refs = _refs(raw.get("references", [])) for value in _array(raw.get("affected", [])): diff --git a/tests/test_sources.py b/tests/test_sources.py index 128da53..1758c9b 100644 --- a/tests/test_sources.py +++ b/tests/test_sources.py @@ -372,3 +372,18 @@ async def test_epss_rejects_invalid_probabilities(invalid: str | bool) -> None: http = _Http({"data": [{"cve": _CVE, "epss": invalid, "percentile": "0.1", "date": "2025-10-02"}]}) page = await lookup("epss", "id", _CVE, http=http, deadline=10) assert page.status.status == "invalid_data" and not page.docs + + +def test_osv_drops_unparsable_auxiliary_references_but_keeps_the_document(): + from vuln_mcp.sources.parsers import _osv + + doc = _osv({ + "id": "GHSA-aaaa-bbbb-cccc", + "schema_version": "1.6.0", + "modified": "2026-01-01T00:00:00Z", + "aliases": ["CVE-2026-0001", "https://example.test/alias"], + "related": ["https://example.test/x", "GHSA-dddd-eeee-ffff"], + }, "https://osv.dev/GHSA-aaaa-bbbb-cccc") + issue = doc.issues[0] + assert issue.aliases == ["CVE-2026-0001"] + assert issue.facts["related"] == ["GHSA-dddd-eeee-ffff"]