Skip to content

fix(sc4): pass version to OSV for all requirement operators, not just == and <=#123

Open
tcconnally wants to merge 1 commit into
NVIDIA:mainfrom
tcconnally:fix/sc4-version-bound-operators
Open

fix(sc4): pass version to OSV for all requirement operators, not just == and <=#123
tcconnally wants to merge 1 commit into
NVIDIA:mainfrom
tcconnally:fix/sc4-version-bound-operators

Conversation

@tcconnally

Copy link
Copy Markdown

Summary

Fixes #43: SC4 reports all historical CVEs when requirements.txt uses >=, >, ~=, or != operators.

Root Cause

_extract_packages_from_requirements() only forwarded the version to query_batch() for == and <= operators. For all other operators (>=, >, ~=, !=), version=None was passed to the OSV.dev API, which returns all historical CVEs for that package.

# Before: only == and <= passed version
version = m.group(3) if m.group(2) in ("==", "<=") else None

# After: all operators pass version
version = m.group(3) if m.group(2) else None

Fix

Pass the bound version for all requirement operators. OSV.dev uses the version to filter CVEs — passing "1.26.0" for "numpy>=1.26.0" returns only CVEs affecting that version, not all 20+ historical advisories.

Example

requirements.txt Before After
numpy>=1.26.0 Reports 20+ CVEs going back to 2019 Reports only CVEs affecting >=1.26.0
Pillow>=10.4.0 Reports all historical CVEs Reports only relevant CVEs
httpx==0.27.0 Correct (unchanged) Correct (unchanged)

Testing

All 622 tests pass. Backward compatible — == and <= behavior unchanged.

… == and <=

When requirements.txt uses >=, >, ~=, or != operators, the version was
set to None before querying OSV.dev, causing all historical CVEs to be
reported. This happened because _extract_packages_from_requirements()
only forwarded the version for == and <= operators.

Fix: pass the bound version for all operators. OSV.dev uses the version
to filter CVEs, so passing e.g. "1.26.0" for "numpy>=1.26.0" returns
only CVEs affecting that version, not all historical advisories.

Fixes NVIDIA#43

Signed-off-by: Perseus Computing <51974392+tcconnally@users.noreply.github.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.

SC4 (OSV known vulnerable dependency) reports all historical CVEs when requirements.txt uses >= operator #42

1 participant