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

Skip to content

πŸ› fix(seed): verify sha256 of bundled wheels on load#3119

Merged
gaborbernat merged 1 commit into
pypa:mainfrom
gaborbernat:security/bundle-hash-verify
Apr 14, 2026
Merged

πŸ› fix(seed): verify sha256 of bundled wheels on load#3119
gaborbernat merged 1 commit into
pypa:mainfrom
gaborbernat:security/bundle-hash-verify

Conversation

@gaborbernat
Copy link
Copy Markdown
Contributor

@gaborbernat gaborbernat commented Apr 14, 2026

Security hardening. Bundled seed wheels were loaded straight off disk and handed to pip without any integrity check. A corrupted or tampered wheel sitting next to embed/__init__.py β€” whether from a botched upgrade, a filesystem error, or a supply-chain compromise β€” would have been silently installed into every new environment. πŸ”’

The fix records the SHA-256 of every bundled wheel alongside BUNDLE_SUPPORT in the generated embed/__init__.py, and verifies each wheel the first time it is requested. Hashes are cached per wheel name so the happy path keeps a single file read per interpreter run, and a mismatch aborts with a clear RuntimeError. When virtualenv runs from a zipapp the bytes are read straight from the archive entry, so the check applies to both on-disk and zipapp layouts.

The hash table is produced by tasks/upgrade_wheels.py so future wheel bumps stay in sync without manual bookkeeping. A new --regen mode lets the generator rewrite the module from the wheels currently on disk without re-downloading anything, which is how this PR produced the initial table.

@gaborbernat gaborbernat force-pushed the security/bundle-hash-verify branch 5 times, most recently from d031380 to b0d0c9c Compare April 14, 2026 05:03
Bundled seed wheels were loaded straight from disk and handed to pip
without any integrity check, so a corrupted or tampered wheel sitting
next to ``embed/__init__.py`` would have been installed silently into
every new environment.

Record the sha256 of each wheel alongside ``BUNDLE_SUPPORT`` and
verify it the first time a wheel is requested, failing loud on any
mismatch. Generate the hash table from ``tasks/upgrade_wheels.py`` so
future wheel bumps stay in sync, and add a ``--regen`` mode so the
emitted module can be rewritten without re-downloading.
@gaborbernat gaborbernat force-pushed the security/bundle-hash-verify branch from b0d0c9c to 3d84587 Compare April 14, 2026 05:12
@gaborbernat gaborbernat marked this pull request as ready for review April 14, 2026 14:52
@gaborbernat gaborbernat enabled auto-merge (squash) April 14, 2026 15:03
@gaborbernat gaborbernat merged commit 43deabf 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