Resolve a Fortinet id through the feed instead of the blocked page
CI / Python 3.13 (push) Successful in 40s
CI / Python 3.12 (push) Successful in 46s
CI / Build and smoke-test image (push) Successful in 13s

This commit is contained in:
omar committed 2026-11-29 15:11:12 +03:00
1 parent 73d01f4d7d
commit 9c1638b5b8
2 files changed
+26 -22

No files matched your search

+9 -12
View File
@@ -528,24 +528,21 @@ async def lookup_fortinet(
raise InvalidData("unsupported Fortinet lookup")
native, known = _target(kind, value)
if known is None:
# Without an indexed document URL the landing page is the only handle,
# and the publisher's WAF denies it to some egress IPs.
try:
page, page_headers = await http.bytes(_SOURCE, _url_for(native), deadline=deadline,
limit=_DETAIL_LIMIT)
except HttpError as error:
if error.status == "not_found":
return ProviderPage(status=Status(source=_SOURCE, as_of=utc_now()))
raise
document_kind, url = await worker(_download_link, page, native)
# The publisher's landing pages are WAF-blocked for some egress IPs, but
# the feed on filestore names each advisory's structured document.
feed, _ = await http.bytes(_SOURCE, FORTINET_RSS, deadline=deadline, limit=_RSS_LIMIT)
entry = (await worker(_rss, feed)).get(native)
if entry is None or len(entry) != 3:
return ProviderPage(status=Status(source=_SOURCE, as_of=utc_now()))
document_kind, url = entry[1], entry[2]
else:
url, page_headers = known, {}
url = known
document_kind = "csaf" if _CSAF.fullmatch(urlsplit(url).path) else "cvrf"
content, document_headers = await http.bytes(_SOURCE, url, deadline=deadline, limit=_DETAIL_LIMIT)
if len(content) > _DETAIL_LIMIT:
raise InvalidData("Fortinet advisory exceeds byte limit")
doc = await worker(_csaf if document_kind == "csaf" else _cvrf, content, native, url)
return ProviderPage(docs=[doc], cacheable=_cacheable(page_headers) and _cacheable(document_headers),
return ProviderPage(docs=[doc], cacheable=_cacheable(document_headers),
status=Status(source=_SOURCE, as_of=utc_now()))
except HttpError as error:
status = "unavailable" if error.status == "not_found" else error.status
+17 -10
View File
@@ -18,6 +18,7 @@ from vuln_mcp.sync import Sync
from vuln_mcp.transport import HttpError
RSS = "https://filestore.fortinet.com/fortiguard/rss/ir.xml"
FEED = RSS
HOST = "fortiguard.fortinet.com"
FILESTORE = "filestore.fortinet.com"
NATIVE = "FG-IR-26-141"
@@ -123,7 +124,7 @@ class LiveWire:
@pytest.mark.anyio
async def test_lookup_prefers_csaf_and_preserves_issue_product_and_branch_scope() -> None:
wire = LiveWire({advisory_url(): advisory(), artifact_url(): csaf()}, no_store=True)
wire = LiveWire({RSS: linked_rss((NATIVE, "first")), artifact_url(): csaf()}, no_store=True)
first = await lookup_fortinet("id", NATIVE.lower(), http=wire, deadline=42)
assert first.status.status == "ok" and not first.cacheable
[doc] = first.docs
@@ -158,7 +159,7 @@ async def test_lookup_prefers_csaf_and_preserves_issue_product_and_branch_scope(
updated = await lookup_fortinet("id", NATIVE, http=wire, deadline=43)
assert updated.docs[0].issues[0].fixes[0]["version"] == "5.0.8"
assert wire.requests == [("fortinet", url, deadline) for deadline in (42, 43)
for url in (advisory_url(), artifact_url())]
for url in (RSS, artifact_url())]
@pytest.mark.anyio
@@ -171,7 +172,7 @@ async def test_legacy_cvrf_returns_identity_without_suspect_product_status() ->
<v:Vulnerability Ordinal="1"><v:CVE>{CVE}</v:CVE><v:ProductStatuses>
<v:Status Type="Known Affected"><v:ProductID>FortiSandbox newer branch</v:ProductID></v:Status>
</v:ProductStatuses></v:Vulnerability></cvrfdoc>'''.encode()
wire = LiveWire({advisory_url(): f'<a href="{url}">CVRF</a>'.encode(), url: payload})
wire = LiveWire({RSS: linked_rss_cvrf((NATIVE, "first"), url), url: payload})
result = await lookup_fortinet("id", NATIVE, http=wire, deadline=42)
assert result.status.status == "ok"
[doc] = result.docs
@@ -188,17 +189,18 @@ async def test_legacy_cvrf_returns_identity_without_suspect_product_status() ->
"https://fortiguard.fortinet.com/psirt/cvrf/FG-IR-26-141/attachment",
])
async def test_unrecognized_download_never_goes_outbound(link: str) -> None:
wire = LiveWire({advisory_url(): f'<a href="{link}">Download</a>'.encode()})
wire = LiveWire({RSS: linked_rss((NATIVE, "first"), link=link)})
result = await lookup_fortinet("id", NATIVE, http=wire, deadline=42)
assert result.status.status == "invalid_data" and not result.docs
assert wire.requests == [("fortinet", advisory_url(), 42)]
assert [url for _source, url, _deadline in wire.requests] == [RSS]
@pytest.mark.anyio
async def test_transport_failure_and_missing_advisory_are_distinguished() -> None:
bad_value = await lookup_fortinet("id", advisory_url(), http=LiveWire({}), deadline=42)
missing = await lookup_fortinet("id", NATIVE, http=LiveWire({advisory_url(): HttpError("not_found")}), deadline=42)
limited = await lookup_fortinet("id", NATIVE, http=LiveWire({advisory_url(): advisory(),
missing = await lookup_fortinet("id", NATIVE,
http=LiveWire({RSS: rss((OTHER, "x"))}), deadline=42)
limited = await lookup_fortinet("id", NATIVE, http=LiveWire({RSS: linked_rss((NATIVE, "first")),
artifact_url(): HttpError("rate_limited", DATE)}), deadline=42)
assert bad_value.status.status == "invalid_data" and not bad_value.docs
assert missing.status.status == "ok" and not missing.docs
@@ -276,19 +278,24 @@ async def test_xml_declarations_and_empty_feeds_never_publish(tmp_path: Path) ->
assert not (await store.state("fortinet"))["checkpoint"]
def linked_rss(*items: tuple[str, str]) -> bytes:
def linked_rss(*items: tuple[str, str], link: str | None = None, cvrf: bool = False) -> bytes:
entries = "".join(
f"<item><title>{IGNORED}</title><description>{revision}</description>"
f"<link>https://www.fortiguard.com/psirt/{native}</link>"
f'<csaf:link>{artifact_url(native)}</csaf:link>'
f'<{"cvrf" if cvrf else "csaf"}:link>{link or artifact_url(native)}</{"cvrf" if cvrf else "csaf"}:link>'
"<pubDate>Tue, 09 Jun 2026 00:00:00 GMT</pubDate></item>"
for native, revision in items
)
return ('<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" '
'xmlns:csaf="https://fortiguard.fortinet.com/rss/ns/csaf">'
'xmlns:csaf="https://fortiguard.fortinet.com/rss/ns/csaf" '
'xmlns:cvrf="https://fortiguard.fortinet.com/rss/ns/cvrf">'
f'<channel>{entries}</channel></rss>').encode()
def linked_rss_cvrf(items: tuple[str, str], link: str) -> bytes:
return linked_rss(items, link=link, cvrf=True)
@pytest.mark.anyio
async def test_feed_supplied_document_skips_the_blocked_advisory_page(tmp_path: Path) -> None:
# The publisher's HTML pages are denied to some egress IPs; the feed names the