Drop unparsable OSV auxiliary references instead of the whole import
This commit is contained in:
1 parent
d798b41747
commit
5c1041d3da
2 files changed
+30
-3
No files matched your search
@@ -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", [])):
|
||||
|
||||
@@ -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"]
|
||||
Reference in new issue
Block a user