Skip to content

fix: false legal citations and false vulnerability verdicts (law #103 port, not-affected citations, CPE case, platform/edition conditions, KEV by CPE) - #89

Merged
maksimtech merged 5 commits into
mainfrom
fix/legal-verdicts
Nov 17, 2026
Merged

maksimtech merged 5 commits into
mainfrom
fix/legal-verdicts

Conversation

@maksimtech

Copy link
Copy Markdown
Owner

Five defects from the bug hunt of 2026-11-17 that made PatchRadar state something false: a legal citation the scan itself contradicted, or a vulnerability verdict NVD does not support. One commit each; every fix has a test that was seen failing first, on recorded NVD, KEV and Cellar answers (or excerpts of them, declared _derived).

1. Law check: port of maksimtech/mailradar#103 (fix(law))

  • False: a citation was "verified against Cellar" whenever the article was found, even when the paragraph cited (GDPR 32(2)) was missing from the text just downloaded: the old cached hash came back under the "verified" label, or "SHA256: not available". A redirect to a host httpx cannot encode ended the whole law check; redirects could leave the source's host; no size or time bound; a read-only cache hid a change in the law; every failure was printed as "EUR-Lex unreachable".
  • Fix: law_fetcher.py and law_cache.py are mailradar's post-#103 copies (only PATCHRADAR_HOME and names differ); law_checker.check verifies each cited reference, merges with law_cache.merge before saving, and ActStatus gains tried / failure / reason, which scan prints.
  • Tests: mailradar's new tests ported to test_law_fetcher.py, test_law_cache.py, test_law_sources.py, test_law_checker.py (Cellar answered at the HTTP boundary with the recorded GDPR page, or a page derived from it without paragraph 32(2)), test_law_unverifiable.py.

2. The law check cited CVEs the same scan judged "not affected" (fix(cli))

  • False: for 7-Zip 26.06 the scan said "not affecting it: 2" and then cited CVE-2025-0411 (fixed in 24.09) and CVE-2026-14266 (fixed in 26.02) under GDPR art. 25 and 32 (_hunt/scan_7zip_2606.txt).
  • Fix: _scan_target hands the law check every CVE except those judged "not affected". The API runs no law check, so nothing to change there.
  • Test: test_cli_law.py, on NVD's recorded record of CVE-2025-0411: not cited for 26.06, still cited for 24.08.

3. A CPE with capitals made every CVE "not affected" (fix(cpe))

  • False: cpe:2.3:a:Mozilla:Thunderbird was accepted and compared with NVD's lower-case names as strings: nothing matched, every CVE was "not affected" and hidden — a false all-clear.
  • Fix: parse_cpe returns the name in lower case (CLI add and the API store it so); ranges_in compares vendor and product case-insensitively (covers rows stored before).
  • Tests: test_cpe.py, test_watchlist_versions.py, test_api_versioned.py, test_affected_verdict.py.

4. Verdicts ignored the CPE fields after the version and the AND configurations (fix(affected))

  • False (NVD records recorded 2026-11-17): Chrome 150 on Windows "affected" by CVE-2026-16424, which NVD lists for Chrome on Android only; CVE-2026-17709 likewise (macOS only); Firefox ESR 115.17.0 "affected, fix in 131.0.2" by CVE-2024-9680 (ESR fixed in 115.16.1); 7-Zip 4.43 "affected" by 7-zip:4.43:beta entries.
  • Fix: a range carries conditions — the products the other nodes of an AND configuration require, and every field after the version the watched CPE does not name. A conditional range containing the version gives not evaluable, with the condition in the reason ("NVD lists it as affecting 150.0.7871.100 only on Android, which the watchlist does not record"), never "affected". A watched CPE that names the field (cpe:2.3:a:mozilla:firefox:*:*:*:*:esr:*:*:*) selects those entries and drops the others. A - counts as a condition only where the record also names the product with another value in that field (VS Code's lone target_sw: - is unchanged). CLI and API pass the watched CPE to mark.
  • Tests: test_affected_conditions.py — judge on the recorded records, the CLI scan and the API scan.

5. KEV: "chrome" matched 6 of the 72 exploited Chrome CVEs (fix(kev))

  • False: CISA files Chrome as "Chromium V8", "Chromium Mojo", "Chromium", ...; a scan reported 66 exploited CVEs as not known to be exploited.
  • Fix (chosen over an alias table): for an entry with a CPE, the KEV collector also asks NVD once for the CVEs it flags as in KEV for that product (hasKev + virtualMatchString=cpe:2.3:<part>:<vendor>:<product>, paged) and takes those catalogue entries whatever CISA called the product; NVD's records come along, so they are judged without a cveId lookup each. Measured on 2026-11-17: NVD returned all 72, plus 6 Chrome CVEs whose CISA entry names no browser (Flash Player, WebRTC, Skia, Dawn). An alias table would fix Chrome only and need upkeep for every product CISA names by a component. Entries without a CPE keep the keyword match; if NVD fails, the keyword's matches stand and the scan says it is incomplete. docs/nis2-compliance.md lists the new query (held by test_nis2_evidence.py).
  • Tests: test_kev_by_cpe.py on an excerpt of the real 2026.11.17 catalogue and of NVD's real hasKev answer: collector, NVD failure, CLI scan, API scan.

A real run (isolated HOME) of scan chrome for 150.0.7871.100 with --cpe cpe:2.3:a:Google:Chrome found 78 exploited CVEs (6 before), judged with no per-id lookup.

Not in this PR (found, out of scope)

  • _NUMERIC orders a pre-release written 2.0b after 2.0 (_hunt/tests/test_hunt_affected.py::test_prerelease_letter_suffix_orders_after_the_release).

AI disclosure

Written by Claude Code (Claude Opus 5.5) from the bug-hunt evidence. Each fix was checked against the code by a test that failed before it and passes after; the full suite, ruff check and mypy pass locally.

🤖 Generated with Claude Code

maksimtech and others added 5 commits November 17, 2026 20:49
…tches, read-only cache

law_fetcher.py and law_cache.py were mailradar's copies from before
maksimtech/mailradar#103, apart from PATCHRADAR_HOME. They are now its copies
after it (commit e649dea), with the same variable kept, and law_checker.py and
the scan's status lines take the same changes.

- A citation was "verified" per act: download success plus the article being
  found. With article 32 in Cellar's page and paragraph 2 missing from what was
  parsed, GDPR art. 32(2) for a critical CVE fell back to the cache, old
  SHA-256 and date included, under "verified against Cellar", or stood beside
  "SHA256: not available". Each cited reference is now looked up in the text
  just parsed; a missing one is a fetch failure (law_checker.check).
- Only httpx.HTTPError was a fetch failure: a redirect to http://xn--/DOC_1
  raised idna.core.IDNAError out of the whole law check. httpx.InvalidURL and
  ValueError are fetch failures too.
- Redirects stay on the source's host (publications.europa.eu,
  eur-lex.europa.eu, www.normattiva.it), default port only.
- A body is streamed and refused past 32 MiB; a fetch ends after 120 s.
- With a read-only cache a changed law text was cited without the warning and
  an unchanged one was dated to today: law_cache.merge now runs before the
  save, whatever the save does.
- LawFetchError carries source and reached; ActStatus carries tried, failure
  and reason, and `scan` prints "Cellar answered without the text cited" or
  "Cellar and EUR-Lex unreachable" instead of "EUR-Lex unreachable".
- A deeply nested law_cache.json is an empty cache, not a RecursionError;
  Normattiva's -bis/-ter/... paragraphs can be cited.

The tests are mailradar's, adapted: the end-to-end ones answer Cellar with the
recorded GDPR page, or a page derived from it without the ELI id of paragraph
32(2), through httpx.MockTransport. Each was seen failing before the port.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`scan` handed every CVE found by name to the law check, whatever its verdict.
For 7-Zip 26.06 it printed "not affecting it: 2" and then cited CVE-2025-0411
(fixed in 24.09) and CVE-2026-14266 (fixed in 26.02) under GDPR art. 25 and
art. 32 (bug hunt, scan_7zip_2606.txt); a critical unpatched one would have
reached D.Lgs. 138/2024 art. 24 as well.

_scan_target now hands the law check only the CVEs that affect the installed
version, could not be evaluated, or belong to an entry matched by name. The
API runs no law check (docs/nis2-compliance.md: the law sources are contacted
by `scan` from the command line only), so it has nothing to change.

The test answers NVD with its recorded record of CVE-2025-0411
(tests/fixtures/nvd_cve_2025_0411_recorded.json) and scans 7-Zip 26.06 (not
cited) and 24.08 (still cited).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
parse_cpe accepted `cpe:2.3:a:Mozilla:Thunderbird` as typed, from `add --cpe`
and from POST /api/watchlist/{name}?cpe= alike, and affected.ranges_in compared
its vendor and product with NVD's lower-case cpeMatch names as strings
(fields[3] != vendor). Nothing matched, so every CVE of the program was judged
"not affected" and left out of the table: a false all-clear made of a capital
letter.

CPE 2.3 names match without regard to case, and NVD writes them in lower case.
parse_cpe now returns the name in lower case, so both routes store it as NVD
writes it, and ranges_in compares vendor and product case-insensitively, which
also covers entries stored before this change (WatchEntry re-parses them).

Tests: parse_cpe, the CLI and the API store the lower-case form; the verdict on
NVD's recorded CVE-2025-0411 is "affected, fixed in 24.09" for 7-Zip 24.08
whatever case vendor and product are given in. Each failed first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…te or edition

ranges_in read the version of each vulnerable cpeMatch entry and nothing
else: neither the CPE fields after the version (update, sw_edition, ...) nor
the AND configuration the entry sits in. On NVD's records, recorded on
2026-11-17 for the bug hunt:

- CVE-2026-16424 is Chrome < 150.0.7871.182 AND (vulnerable: false) Android:
  Chrome 150.0.7871.100 on Windows was "affected"; CVE-2026-17709, the same
  with macOS, likewise for 151.0.7922.10;
- CVE-2024-9680 has Firefox sw_edition esr < 115.16.1 beside sw_edition -
  < 131.0.2: ESR 115.17.0 was "affected, fix in 131.0.2";
- CVE-2007-4725 lists `7-zip:4.43:beta` ... `4.52:beta`: the final 4.43 was
  "affected" (and python:3.12.0:rc1 would make 3.12.0 final affected).

The watchlist knows the version and the CPE, not the operating system. A range
now carries `conditions`: the products the other nodes of an AND configuration
require ("on Android", "with telco cloud platform"), and every field after the
version that the watched CPE does not name ("for update beta", "for the esr
edition"). A range with conditions that contains the version makes the CVE
"not evaluable", the reason naming the condition, never "affected"; outside
the range it is still "not affected". Where the watched CPE names the field
(cpe:2.3:a:mozilla:firefox:*:*:*:*:esr:*:*:*) the entries with another value
are left out and the matching ones decide alone. A `-` is a condition only
where the record names the product with another value in that field too, so
VS Code's lone `target_sw: -` (CVE-2026-81376) stays an unconditional range.

judge and mark take the watched Cpe, which now keeps its fields; the CLI and
the API pass it. affects() no longer counts a conditional range as a hit.

Tests: tests/test_affected_conditions.py, on the recorded records, through
judge, the CLI scan and the API scan; each failed first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The KEV collector matched the watchlist name against CISA's vendorProject and
product only. CISA files Chrome as "Google / Chromium V8", "Chromium Mojo",
"Chromium" and so on: on the 2026-11-17 catalogue (1782 entries) the word
"chrome" was in 6 of the 72 exploited Chrome CVEs, and a scan reported the
other 66 as not known to be exploited.

For an entry with a CPE, kev.fetch_cves now also asks NVD, once and paged, for
the CVEs it flags as in KEV for that product (nvd.known_exploited_for:
hasKev + virtualMatchString=cpe:2.3:<part>:<vendor>:<product>) and takes those
catalogue entries whatever CISA called the product. Measured the same day, NVD
returned the 72 and six more Chrome CVEs whose CISA entry names no browser
(Adobe Flash Player, WebRTC, Google Skia, Google Dawn). NVD's records come back
too, ahead of CISA's, so the merged rows carry NVD's configurations and the
scan judges them without a cveId lookup each. A real scan of Chrome
150.0.7871.100 in an isolated HOME found 78 exploited CVEs (6 before) with no
per-id request.

Chosen over an alias table (chrome -> Chromium, Chromium V8, ...): that would
fix one product and need upkeep for every other one CISA names by a component
(Win32k, Exchange Server, ...), while the CPE is the name NVD has already
mapped every KEV CVE to. Entries without a CPE keep the keyword match. If NVD
cannot be asked, the keyword's matches stand as `partial` and the scan says it
is incomplete. The CLI and the API pass the entry's CPE; docs/nis2-compliance.md
lists the new query, and test_nis2_evidence.py holds it to the code.

Tests (tests/test_kev_by_cpe.py) answer from excerpts of the real catalogue and
of NVD's real hasKev answer for google:chrome, both declared `_derived`; the
CLI scan found 1 CVE before the fix and 5 after. test_judge_through_nvd.py
routes the new request explicitly instead of letting it fall into its 503.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.83550% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/patchradar/affected.py 96.29% 3 Missing ⚠️
src/patchradar/collectors/kev.py 95.23% 1 Missing ⚠️
src/patchradar/law_fetcher.py 98.24% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Nov 17, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 11 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 17 untouched benchmarks


Comparing fix/legal-verdicts (3f0a8c5) with main (5846ddf)

Open in CodSpeed

@sonarqubecloud

Copy link
Copy Markdown

@maksimtech
maksimtech merged commit e5cc78a into main Nov 17, 2026
23 checks passed
maksimtech added a commit that referenced this pull request Nov 18, 2026
The bug hunt of 2026-11-17 and its fixes (#89, #91), the law check carrying
mailradar#103, the OpenSSL exceptions of 2026-11-10 and the upkeep since
2026.48 ship as 2026.49. RELEASING.md wants the section in place before the
bump; [Unreleased] stays, empty, above it.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant