fix(supply-chain): treat only == / <= as version pins in requirements.txt (#294)#302
fix(supply-chain): treat only == / <= as version pins in requirements.txt (#294)#302Mark2Mac wants to merge 1 commit into
Conversation
….txt
`_extract_packages_from_requirements` kept the captured version for any operator,
so a floor like `pillow>=10.0.0` was recorded as the exact release `10.0.0` and
the OSV/CVE lookup attributed that version's vulnerabilities to an unpinned
dependency — a false CRITICAL on a requirements file that pins nothing.
Only `==` and `<=` bound the dependency to a concrete, CVE-checkable release;
`>=`, `>`, `!=`, `~=` are floors/ranges. This mirrors the guard already present
in `_extract_packages_from_setup_py` (`m.group(2) in ("==", "<=")`), so the two
extractors now agree.
Added a regression test asserting `>=`, `~=`, `!=` and bare names yield
version=None while `==` / `<=` keep the version.
Fixes NVIDIA#294
Signed-off-by: Mark2Mac <Mark2Mac@users.noreply.github.com>
rng1995
left a comment
There was a problem hiding this comment.
[Automated SkillSpector Review]
Requesting changes because the new guard still treats non-exact constraints as concrete installed versions. <=8.1.0 admits every earlier release, and ==1.* is also a wildcard range, so either can still be sent to the vulnerability lookup as a version the dependency may not install. Please retain only truly exact pins, or model ranges explicitly, and add regressions for both cases.
| # version makes a floor like "pillow>=10.0.0" report as "pillow==10.0.0" and | ||
| # attributes that release's CVEs to an unpinned dependency. Mirrors the guard | ||
| # already used by _extract_packages_from_setup_py. | ||
| version = m.group(3) if m.group(2) in ("==", "<=") else None |
There was a problem hiding this comment.
<= is still a range, not a concrete release: pkg<=8.1.0 can install any earlier version, so keeping 8.1.0 here continues the same false CVE attribution. The regex also accepts wildcard equality such as pkg==1.*, which is not exact either. Please retain only a non-wildcard exact equality (or model ranges explicitly), and update both extractors consistently.
What
_extract_packages_from_requirementsrecorded the captured version for any operator, so a floor likepillow>=10.0.0was stored as the exact release10.0.0. The OSV/CVE lookup then attributed that release's vulnerabilities to a dependency that pins nothing — a false CRITICAL supply-chain finding.Only
==and<=bind a dependency to a concrete, CVE-checkable release.>=,>,!=,~=are floors/ranges. The fix applies the same guard already used by_extract_packages_from_setup_py(m.group(2) in ("==", "<=")), so the two extractors agree.Reproduction (before)
Test
Added
test_extract_packages_requirements_specifier_is_not_a_pin: asserts==/<=keep the version while>=,~=,!=and bare names yieldNone. Verified red before the fix (pillowcame back'10.0.0'), green after. Full existing suite for the analyzer stays green (320 passed).Fixes #294