Thanks to visit codestin.com
Credit goes to github.com

Skip to content

πŸ› fix(seed): validate distribution and version before pip download#3120

Merged
gaborbernat merged 2 commits into
pypa:mainfrom
gaborbernat:security/acquire-validate-distribution
Apr 14, 2026
Merged

πŸ› fix(seed): validate distribution and version before pip download#3120
gaborbernat merged 2 commits into
pypa:mainfrom
gaborbernat:security/acquire-validate-distribution

Conversation

@gaborbernat
Copy link
Copy Markdown
Contributor

@gaborbernat gaborbernat commented Apr 14, 2026

Security hardening. The distribution name and version specifier handed to pip download in download_wheel were interpolated straight into the subprocess argument list with an f-string. Internal callers always pass sensible values today, but the function is a small function call away from turning a distribution string like pip --index-url=http://evil or pip[extra] into extra pip flags or a different package entirely. πŸ”’ Defense in depth is cheap here and the check runs before the subprocess is ever spawned.

The fix rejects any distribution name that does not match the PEP 503 normalised form, and any non-empty version spec that does not match what Version.as_version_spec can emit. The regexes are written in verbose mode with named groups so the allow-list is readable at a glance. Anything outside those shapes raises a ValueError with the offending string quoted for debugging. Happy-path callers see no behavioural change.

@gaborbernat gaborbernat force-pushed the security/acquire-validate-distribution branch 4 times, most recently from 6f5c824 to e5b0f8e Compare April 14, 2026 05:06
The distribution name and version spec handed to ``pip download`` were
interpolated straight into the argument list, so a caller reaching
``download_wheel`` with a string like ``pip --index-url=http://evil``
or ``pip[extra]`` would have quietly turned it into pip options or a
different package.

Reject anything that does not look like a PEP 503 distribution name or
a spec emitted by ``Version.as_version_spec``. Callers are all internal
today, but defense in depth is cheap and the check runs before the
subprocess is spawned, so there is no cost on the happy path.
@gaborbernat gaborbernat force-pushed the security/acquire-validate-distribution branch from 16fd456 to c3c4449 Compare April 14, 2026 05:12
@gaborbernat gaborbernat marked this pull request as ready for review April 14, 2026 14:53
@gaborbernat gaborbernat enabled auto-merge (squash) April 14, 2026 15:03
@gaborbernat gaborbernat merged commit 4e412b0 into pypa:main Apr 14, 2026
58 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants