Read Fortinet stubs and inline fixed versions
This commit is contained in:
1 parent
716a7c5955
commit
f8e5b1faf1
3 files changed
+36
-5
No files matched your search
@@ -371,9 +371,9 @@ def _csaf(content: bytes, native: str) -> Doc:
|
||||
if _native(tracking.get("id")) != native or tracking.get("status") not in ("final", "interim"):
|
||||
raise InvalidData("Fortinet CSAF identity or status mismatch")
|
||||
tree, scope_by_id, groups = _project_tree(_object(root.get("product_tree", {})))
|
||||
vulnerabilities = _objects(root.get("vulnerabilities"))
|
||||
if not vulnerabilities:
|
||||
raise InvalidData("empty Fortinet CSAF vulnerabilities")
|
||||
# Recent advisories are published as stubs first: identity and dates only,
|
||||
# vulnerabilities appear on a later revision.
|
||||
vulnerabilities = _objects(root.get("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"))}},
|
||||
@@ -383,7 +383,7 @@ def _csaf(content: bytes, native: str) -> Doc:
|
||||
}
|
||||
doc = parse(_SOURCE, projection, _url_for(native))
|
||||
names: dict[str, None] = {}
|
||||
for issue, vulnerability in zip(doc.issues, vulnerabilities, strict=True):
|
||||
for issue, vulnerability in zip(doc.issues, vulnerabilities):
|
||||
for product in issue.products:
|
||||
names[product["name"]] = None
|
||||
if product.get("vendor") in (None, _PUBLISHER, "Fortinet PSIRT", "Fortinet Inc."):
|
||||
|
||||
@@ -602,6 +602,18 @@ def _csaf_issue(raw: dict[str, Any], *, publisher: str, source: str, native: str
|
||||
product_id = _str(product_id)
|
||||
resolved = products.get(product_id)
|
||||
if resolved is None:
|
||||
if source == "fortinet":
|
||||
# Fortinet names a fixed version inline as "<product>-<version>"
|
||||
# inside product_status; recover both halves instead of the ID.
|
||||
prefix, _, tail = product_id.rpartition("-")
|
||||
tail = tail.strip()
|
||||
exact = bool(re.fullmatch(r"[0-9]{1,8}(?:\.[0-9]{1,8}){1,3}", tail))
|
||||
issue.products.append(_compact(
|
||||
product_id=product_id, name=prefix or product_id,
|
||||
version=tail if exact else None, scheme="EXACT" if exact else "UNKNOWN",
|
||||
status=_CSAF_STATUS[key], reported_status=key,
|
||||
))
|
||||
continue
|
||||
if source != "msrc":
|
||||
raise InvalidData("unresolved CSAF status product")
|
||||
# Some MSRC documents omit product definitions. An opaque ID
|
||||
|
||||
+20
-1
@@ -11,7 +11,7 @@ import pytest
|
||||
|
||||
from vuln_mcp.matching import make_asset, product_match, product_status
|
||||
from vuln_mcp.models import AssetFacts
|
||||
from vuln_mcp.sources.feed_fortinet import allowed, fortinet_fix_matches, lookup_fortinet
|
||||
from vuln_mcp.sources.feed_fortinet import _csaf, allowed, fortinet_fix_matches, lookup_fortinet
|
||||
from vuln_mcp.store import Store
|
||||
from vuln_mcp.sync import Sync
|
||||
from vuln_mcp.transport import HttpError
|
||||
@@ -305,3 +305,22 @@ async def test_a_mismatched_feed_link_is_rejected(tmp_path: Path) -> None:
|
||||
wire = IndexWire({RSS: body})
|
||||
async with Store(tmp_path) as store:
|
||||
assert not await Sync(store, wire).refresh_once("fortinet")
|
||||
|
||||
|
||||
def test_stub_document_without_vulnerabilities_still_parses() -> None:
|
||||
body = json.loads(csaf())
|
||||
del body["vulnerabilities"]
|
||||
doc = _csaf(json.dumps(body).encode(), NATIVE)
|
||||
# parse() still yields the advisory identity; no product claims exist yet.
|
||||
assert doc.native_id == NATIVE and [issue.id for issue in doc.issues] == [NATIVE]
|
||||
assert doc.issues[0].products == []
|
||||
|
||||
|
||||
def test_inline_fixed_version_in_product_status_is_recovered() -> None:
|
||||
body = json.loads(csaf())
|
||||
status = body["vulnerabilities"][0]["product_status"]
|
||||
status.setdefault("known_not_affected", []).append("FortiSandbox-5.0.5")
|
||||
doc = _csaf(json.dumps(body).encode(), NATIVE)
|
||||
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")
|
||||
Reference in new issue
Block a user