Repository navigation
fix(pm): verify unpinned package-manager downloads against registry integrity - #3547
Conversation
…ntegrity Without a `packageManager` hash, npm, pnpm 11 and earlier, and Yarn were installed without any integrity check, while bun and pnpm 12+ already verified their platform tarball against the registry `dist.integrity`. Corepack used to verify these downloads before it was removed. An unpinned download now fetches the version metadata and verifies the tarball against `dist.integrity` before extraction. A pinned download keeps using the pin and does not fetch metadata. A registry that omits `dist.integrity` now fails the install with `MissingRegistryIntegrity` for every manager, including the bun and pnpm 12+ platform tarballs.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Match the existing bun and pnpm 12+ platform tarball behavior instead of failing the install, so a mirror without dist.integrity keeps working.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: edf37a510e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The test served only the tarball, so the new metadata request returned 404 before the temp dir existed and the cleanup assertion passed vacuously.
Use is_not_found for registry 404 mapping, name managers by PackageManagerType, and share the test sri and mount helpers. Remove doc and inline comments that restate the code.
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
An unpinned npm download now reads dist.integrity from the version metadata, so the mock registry must answer that request.
…t no pin covers (#3553) ## Summary #3547 checks unpinned package-manager downloads against the registry `dist.integrity`. When the version document omitted the field, the install continued without a check. When the version document returned 404, the install failed with `PackageManagerVersionNotFound`, even if the package document had the integrity. This PR makes one rule: when no `packageManager` pin covers the files that vp runs, vp requires the registry `dist.integrity`. The rule applies to these downloads: - Unpinned installs of every package manager. - The platform package of Bun and pnpm 12+, with or without a pin. A pin for these two managers covers only the main tarball, which holds no executable. Pinned npm, pnpm 11 and earlier, and Yarn installs do not change. They never fetch metadata. ### Lookup 1. vp reads the version document, `<registry>/<name>/<version>`. 2. If that document returns 404 or omits `dist.integrity`, vp reads the abbreviated package document, `<registry>/<name>`. `npm install` reads the same document when no lockfile pins a package. 3. If neither document gives the integrity, the install fails with `PackageManagerIntegrityUnavailable` before the download. | Registry response | Before | After | | --- | --- | --- | | Version document has `dist.integrity` | Verified | Verified | | Version document omits `dist.integrity` | Installed without a check | Verified with the package document | | Version document 404 | `PackageManagerVersionNotFound` | Verified with the package document | | Neither document gives `dist.integrity` | Installed without a check, or `PackageManagerVersionNotFound` on a 404 | `PackageManagerIntegrityUnavailable`, nothing downloaded | | Package document does not list the version | Not read | `PackageManagerVersionNotFound` | On registry.npmjs.org, every version of `npm`, `pnpm`, `yarn`, `@yarnpkg/cli-dist`, and `bun` has `dist.integrity`, and so does every version of the Bun and pnpm platform packages that I sampled. So the first request succeeds there. ### The new error `PackageManagerIntegrityUnavailable` names the package and the package document URL, and gives a hint: - npm, pnpm 11 and earlier, and Yarn: add an integrity hash to the `packageManager` field, or use a registry that serves package metadata. - Bun and pnpm 12+: use a registry that serves package metadata. A pin does not help, because it does not cover the platform package. `Error::is_integrity_failure` includes the new error. So a command that prepares a managed package manager stops with this error, and does not fall back to the package manager on `PATH`. Closes #3554 ### One descriptor for each download `download_and_extract_tgz_with_hash_and_config` took `archive_file`, `expected_hash`, and `tarball_hash`. `expected_hash` covered the archive or one entry, depending on `archive_file`. Without `archive_file`, the two hash parameters were the same check. `download_and_extract_tgz` now takes a `TgzDownload`: - `archive_digest` always covers the `.tgz` bytes, and vp checks it before it reads any entry. - `unpack` is `Unpack::All`, or `Unpack::Entry { path, digest }`, where `digest` covers the extracted file only. `download_package_manager_inner` selects both values in one place. Bun and pnpm 12+ share `verify_pin_and_fetch_platform_integrity`, which checks the pin against the main tarball and then fetches the platform integrity. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Without a
packageManagerhash, Vite+ installed npm, pnpm 11 and earlier, and Yarn without any integrity check. Bun and pnpm 12 and later already verified their platform tarball against the registrydist.integrity, so the same unpinned project was verified or not depending on the package manager. Corepack used to verify these downloads, and that check was lost when it was removed in #2391.An unpinned download now fetches the version metadata and verifies the tarball against
dist.integritybefore extraction. A pinned download is unchanged. It is still verified against the pin and does not fetch metadata, which keeps the principle from #3400 that a declared pin takes precedence over what the registry reports.