From 796aa7a10fc40fbb12437c9fe3a3abb56b2f0432 Mon Sep 17 00:00:00 2001 From: georgiedekker Date: Sun, 15 Nov 2026 08:18:34 +0000 Subject: [PATCH 1/2] lane: start From 59839bdb866fbafd320e52c21c560ec8694033bb Mon Sep 17 00:00:00 2001 From: georgiedekker Date: Sun, 15 Nov 2026 08:29:16 +0000 Subject: [PATCH 2/2] fix(osv): match CVE catalogue hosts by parsed hostname, not substring The OSV reference check used `"cve.mitre.org" in url` / `"nvd.nist.gov" in url`, so a URL that merely embeds a catalogue name in its path (or a host prefix like nvd.nist.gov.evil.example) was accepted as a CVE catalogue reference. Compare urlsplit(url).hostname against the catalogue hosts instead, and add a regression test covering both bypass shapes plus the legitimate mitre URL. Co-Authored-By: Claude Code --- CHANGELOG.md | 5 +++++ src/services/osv_scanner.py | 16 +++++++++++++++- tests/unit/test_osv_scanner.py | 21 +++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c83200a..bb83614 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ All notable changes to this project are documented here. The format follows ### Fixed +- OSV reference URLs are matched by parsed hostname, not substring. A reference that merely + embedded `cve.mitre.org` or `nvd.nist.gov` in its path (`https://evil.example/nvd.nist.gov/CVE-…`) + or as a host prefix (`https://nvd.nist.gov.evil.example/…`) was accepted as a CVE catalogue + reference; `_is_cve_reference_url()` now compares `urlsplit(url).hostname` against the catalogue + hosts, and a regression test covers both bypass shapes. - `requires-python` is bounded to `>=3.14,<3.15`. With an open upper bound, `uv` had to resolve a second split for `python_full_version >= '3.15'`, and no solution exists there — which is what made Dependabot's update job fail on `main` with `dependency_file_not_resolvable` against diff --git a/src/services/osv_scanner.py b/src/services/osv_scanner.py index 5b388f4..ec3f647 100644 --- a/src/services/osv_scanner.py +++ b/src/services/osv_scanner.py @@ -30,6 +30,7 @@ from datetime import UTC, datetime, timedelta from pathlib import Path from typing import Any +from urllib.parse import urlsplit import httpx @@ -68,6 +69,19 @@ REQUESTS_PER_SECOND = 10 CACHE_DURATION_HOURS = 24 +#: Hosts whose vulnerability-detail pages carry the CVE id in the URL. This is a +#: parsed-hostname test, never a substring one: ``https://evil.example/nvd.nist.gov/CVE-...`` +#: must not be treated as a catalogue reference. +CVE_REFERENCE_HOSTS = ("cve.mitre.org", "nvd.nist.gov") + + +def _is_cve_reference_url(url: str) -> bool: + """Whether *url*'s host is a CVE catalogue (exact host or a subdomain of one).""" + host = urlsplit(url).hostname + return host is not None and any( + host == catalogue or host.endswith(f".{catalogue}") for catalogue in CVE_REFERENCE_HOSTS + ) + class OSVScanner: """Service for scanning vulnerabilities using OSV.dev API. @@ -318,7 +332,7 @@ def _parse_osv_response( url = ref.get("url", "") references.append(url) - if "cve.mitre.org" in url or "nvd.nist.gov" in url: + if _is_cve_reference_url(url): # Extract CVE ID from URL cve_match = re.search(r"(CVE-\d{4}-\d{4,})", url) if cve_match: diff --git a/tests/unit/test_osv_scanner.py b/tests/unit/test_osv_scanner.py index cfa190a..3316d08 100644 --- a/tests/unit/test_osv_scanner.py +++ b/tests/unit/test_osv_scanner.py @@ -198,6 +198,27 @@ def test_parse_osv_response_valid(self, scanner): assert result[0].id == "GHSA-1234" assert result[0].severity == "HIGH" + def test_parse_osv_response_cve_reference_requires_catalogue_host(self, scanner): + """A catalogue name embedded in a URL's path or host prefix is not a reference.""" + data = { + "vulns": [ + { + "id": "GHSA-5678", + "summary": "Test vuln", + "affected": [{"package": {"name": "django"}}], + "references": [ + {"url": "https://evil.example/nvd.nist.gov/CVE-2023-1111"}, + {"url": "https://nvd.nist.gov.evil.example/CVE-2023-2222"}, + {"url": "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-3333"}, + ], + } + ] + } + result = scanner._parse_osv_response(data, "PyPI", "django") + assert len(result) == 1 + # Only the real catalogue host's CVE id is extracted. + assert result[0].cve_ids == ["CVE-2023-3333"] + def test_parse_osv_response_empty(self, scanner): """Empty vulns returns empty list.""" result = scanner._parse_osv_response({"vulns": []}, "PyPI", "django")