Skip to content

Pinned Bun and pnpm 12+ installs cache an unchecked executable when the registry omits dist.integrity #3554

Closed

Description

@fengmk2

Summary

For Bun and pnpm 12+, a packageManager hash covers only the main tarball. The executable comes from a platform package (@oven/bun-<os>-<arch> or @pnpm/exe.<os>-<arch>), and vp checks it only against the registry dist.integrity of that package. When the platform version document has no dist.integrity, vp installs the executable without any check. The install goes into the .verified-v1 namespace, and later runs with the same pin and registry reuse it without a check.

Why the pin cannot cover the executable

The main tarballs contain only placeholders:

  • bun-1.2.0.tgz: package/bin/bun.exe is 0 bytes. postinstall runs install.js.
  • pnpm-12.21.0.tgz: package/pnpm is a 4 KB sh script. Its comment says "pnpm's native binary replaces this file during installation".

In these versions, package.json lists the platform packages by version only (11 for Bun, 15 for pnpm), with no hashes. All platforms share one packageManager value, so one hash cannot describe the different platform executables. The registry dist.integrity is the only check of the file that vp runs.

Code path

Bun is shown. pnpm 12+ (download_pnpm_native_package_manager) is the same. Links point to fc8cf35.

  1. The install directory is keyed by the pin and the platform origin, under .verified-v1 (L2016).
  2. A complete install in that directory is reused with no check (L2023).
  3. The pin is checked against the main tarball.
  4. fetch_registry_integrity returns None when dist.integrity is absent (L2193-L2199).
  5. The platform tarball is downloaded and extracted with no expected digest (L2074).
  6. publish_install moves it into the directory from step 1 (L2132).

The namespace documentation says "Only a download verified against its pin creates a directory here, so a reuse check can trust a complete entry without re-reading the pin" (L211-L216). This path does not follow that rule.

Reproduction

A mock registry serves these responses for each manager:

  • the main tarball, with a matching packageManager hash
  • the platform tarball
  • the platform version document {"dist": {}}

download_package_manager(kind, version, Some(pin)) then gives these results:

pnpm 12.0.0-beta.0 Bun 1.2.0
First install Ok, in .verified-v1/<version>/<key>/ Ok, in .verified-v1/<version>/<key>/
Installed executable The unchecked platform file The unchecked platform file
Second run, after the registry serves a dist.integrity that does not match Ok, 0 metadata requests Ok, 0 metadata requests

No message appears at the default log level.

Impact

Low, in my assessment. The registry serves both the tarball and dist.integrity, so this check cannot stop a malicious registry. The check detects inconsistency, such as a mirror sync error or a wrong file from a CDN. Without the field, vp cannot detect such a file, and the pinned install keeps it until the user removes it.

registry.npmjs.org serves dist.integrity for these platform packages, so this path needs a third-party mirror or a private registry. I did not check which registry products omit the field.

History

On main, a 404 for the platform version document fails, but an absent field continues. Both cases mean that the registry cannot supply an integrity. #3553 (draft) keeps the 404 failure for pinned Bun and pnpm 12+ installs, and lets unpinned installs continue.

Options

  1. Fail for pinned native installs. When the field is absent, a pinned Bun or pnpm 12+ install fails with a dedicated error. Unpinned installs continue. This matches the 404 rule in fix(pm): require registry integrity for package-manager downloads that no pin covers #3553 and keeps the .verified-v1 rule true. A pinned project on a mirror without dist.integrity stops working.
  2. Continue with a warning. Show a warning that users can see, and correct the .verified-v1 documentation. vp still reuses the unchecked file.
  3. No behavior change. Correct the documentation only.

I recommend option 1. A project that declares a hash asks for a strict check. The open question is how many mirrors omit dist.integrity.

A separate, later step could check dist.signatures against the npm registry keys. That check authenticates the integrity itself, but it needs embedded keys and a key rotation policy.

Activity

  1. added theissue type on Nov 23, 2026
  2. voidzero-bot commented on Nov 23, 2026

    @voidzero-bot
    Contributor
    • Reproduced: Yes — on current main, with a mock registry serving {"dist": {}} for the platform package, a pinned pnpm 12.0.0-beta.0 and Bun 1.2.0 install both succeeded into .verified-v1 with the unchecked platform executable, and a second run reused it with 0 metadata requests.
    • Exploration: Yes — View branch
    • Unit Test: Yes — crates/vp_pm_cli/src/package_manager.rs (pinned_native_install_requires_platform_integrity, covering both pnpm 12 and Bun)
    • Priority: Priority P3: minor bug. It violates the documented .verified-v1 invariant, but only on the narrow configuration described here (a hash-pinned Bun/pnpm ≥ 12 install against a mirror or private registry that omits dist.integrity), and the issue itself rates the impact low: the check detects registry/CDN inconsistency rather than stopping a malicious registry. A workaround exists (use a registry that serves the field, or drop the packageManager hash), though dropping the pin forfeits the strict check the pin asks for.

    For Bun and pnpm ≥ 12, the packageManager hash covers only the main tarball, and the executed binary comes from a platform package (@oven/bun-* / @pnpm/exe.*). fetch_registry_integrity in crates/vp_pm_cli/src/package_manager.rs returns Ok(None) when the version document omits dist.integrity, so download_bun_package_manager / download_pnpm_native_package_manager download and extract the platform tarball with no digest check, then publish_install writes it into the keyed .verified-v1 directory — breaking that namespace's documented rule that only a verified download creates an entry there. The completeness fast path then reuses the unchecked executable on every later run with zero registry requests, even if the registry later serves an integrity that would not match.

    I found a potential fix for this issue. Following the issue's option 1 (and the direction of draft PR #3553 for the 404 case), the fix in the triagebot/fix-3554 branch fails a pinned Bun or pnpm ≥ 12 install with a new, actionable PackageManagerIntegrityUnavailable error before the platform tarball is downloaded, while unpinned installs keep the #3547 fallback so mirrors without dist.integrity keep working. The regression test fails without the guard and passes with it; this still needs human review, in particular the trade-off that a pinned project on an integrity-less mirror stops working.

    Full Triage Report

    Triage report — gh-3554

    Step: reproduce
    Result: REPRODUCED on current main (Bug)
    Classification: Bug — a pinned Bun / pnpm ≥ 12 install caches an unchecked executable in the .verified-v1 namespace when the registry's platform version document omits dist.integrity.

    Summary

    • download_bun_package_manager / download_pnpm_native_package_manager (crates/vp_pm_cli/src/package_manager.rs) verify the platform tarball only against the registry dist.integrity of the platform package.
    • fetch_registry_integrity returns None when the field is absent (package_manager.rs, RegistryVersionMetadata/RegistryDist use #[serde(default)], dist.integrity: Option<Str>).
    • The None is forwarded as the expected digest to download_and_extract_tgz_with_hash_and_config, so the platform tarball is downloaded and extracted with no check.
    • publish_install then moves it into the keyed .verified-v1 directory that install_cache_key derived from the pin and the registry origin — although nothing was verified.
    • On later runs with the same pin and registry, is_package_manager_install_complete reuses that directory with no check and no metadata request.
    • This contradicts the namespace rule documented at VERIFIED_NAMESPACE: "Only a download verified against its pin creates a directory here, so a reuse check can trust a complete entry without re-reading the pin."

    Versions

    • Vite+ checkout: main at the workflow HEAD (branch triagebot/fix-3554); vp v1.7.0 from the installed local build
    • Node.js v24.22.3, pnpm v12.11.2, Ubuntu x64 runner
    • Rust unit test inside crates/vp_pm_cli (cargo test -p vp_pm_cli --lib)

    Reproduction

    The issue's reproduction is a Rust API-level one (download_package_manager(kind, version, Some(pin)) against a mock registry), so I reproduced it with a temporary unit test in crates/vp_pm_cli/src/package_manager.rs using the crate's existing httpmock-based test helpers (create_tgz, sri, EnvConfig::with_vars_async). Test logic (both pnpm 12.0.0-beta.0 and bun 1.2.0):

    1. Mock registry serves the main tarball, the platform tarball, and the platform version document {"dist": {}} (no integrity).
    2. download_package_manager(kind, version, Some(pin)) with a pin that matches the main tarball.
    3. Assert the install lands under .verified-v1, is complete, and its native executable is the unchecked platform file.
    4. Reset the mock registry to serve a dist.integrity that does not match the platform tarball, then call download_package_manager again with the same pin.

    Command

    cargo test -p vp_pm_cli --lib repro_3554 -- --nocapture

    Output (exit code 0)

    running 1 test
    test package_manager::tests::repro_3554_pinned_native_install_without_registry_integrity ... ok
    
    test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 988 filtered out; finished in 0.05s
    

    The test passing means the reported behavior held exactly as the issue describes:

    pnpm 12.0.0-beta.0 Bun 1.2.0
    First install (no dist.integrity) Ok, directory under .verified-v1/<version>/<key>/ Ok, directory under .verified-v1/<version>/<key>/
    Installed executable the unchecked platform file the unchecked platform file
    Second run, registry serves a mismatching dist.integrity Ok, 0 metadata requests (cache reused, no check) Ok, 0 metadata requests (cache reused, no check)

    No error or warning is emitted at the default log level.

    Control

    The existing test test_download_bun_package_manager_verifies_hashes (unmodified, current main) shows the intended behavior when the registry does serve a mismatching integrity for the platform package: the pinned install fails with Error::HashMismatch (1 metadata hit, tarball downloaded, nothing installed). This rules out an unrelated failure in the harness: the only difference between the control and the reproduction is the absence of the dist.integrity field, and absence is exactly what lets the unchecked executable through.

    Code path confirmed (current main)

    • fetch_registry_integrity returns Ok(None) when dist is {} — no error, no fallback.
    • download_and_extract_tgz_with_hash_and_config(..., platform_hash.as_deref(), ...) receives None → no digest check.
    • install_cache_key(Some(pin), Some(origin)) still derives a key, so publish_install writes the unchecked install into .verified-v1.
    • is_package_manager_install_complete fast path reuses it on later runs with zero registry requests.

    Diagnosis — gh-3554

    Confidence: high — the failing logic and its effect are proven by code inspection and by the reproduction in the previous step.

    Affected layer

    crates/vp_pm_cli/src/package_manager.rs (package-manager install/download) and crates/vp_pm_cli/src/request.rs (download-verify-extract pipeline). No JS, global-CLI, or upstream-involvement component.

    Root cause

    For platform-binary managers (Bun, pnpm ≥ 12), the executed file comes from a platform package (@oven/bun-{os}-{arch} / @pnpm/exe.{os}-{arch}) that the packageManager pin does not cover, so the only integrity check on that file is the registry's dist.integrity. Three pieces of code combine into the bug:

    1. fetch_registry_integrity (~L2172–L2203): parses the platform version document with #[serde(default)], so {"dist": {}} deserializes successfully and the function returns Ok(None). Only a 404 is mapped to PackageManagerVersionNotFound; a document without the field is not an error. This tolerant "None means no check" contract dates from feat(pm): verify bun platform tarball against dist.integrity #2310 (e642d04).

    2. The native download functions (download_bun_package_manager ~L1998, download_pnpm_native_package_manager ~L2205): they compute install_cache_key(Some(pin), Some(platform_origin)) before verification and pass platform_hash.as_deref() (i.e. None) into download_and_extract_tgz_with_hash_and_config for the platform tarball. In request.rs, download_and_extract_tgz_once (~L549) runs verify_file_hash only if let Some(tarball_hash), so with None the tarball is downloaded and extracted with no digest check. publish_install then moves the unchecked content into the .verified-v1/<version>/<key>/ directory. The pin was verified only against the main tarball, which holds placeholders, not the executed binary — e.g. bun-1.2.0.tgz has a 0-byte package/bin/bun.exe, and pnpm-12.21.0.tgz ships a shell-script stub.

    3. The reuse fast path (is_package_manager_install_complete at the top of both functions, ~L2023/L2226): a complete directory in the keyed namespace is returned immediately with zero registry requests. This trust is licensed by the invariant documented at VERIFIED_NAMESPACE (~L215): "Only a download verified against its pin creates a directory here, so a reuse check can trust a complete entry without re-reading the pin." Step 2 breaks that invariant: a complete .verified-v1 entry can now hold never-verified content, and it is reused forever — even if the registry later serves a mismatching dist.integrity, no recheck ever happens because no metadata request is made.

    Why the generic (non-platform) manager path does not have this bug

    In the tarball-manager branch (download_package_manager_inner ~L1844), a pin covers the executed files themselves, so registry_integrity is only fetched unpinned; there, Ok(None) is the deliberate #3547 fallback ("a mirror without dist.integrity keeps working") and the install goes to the unkeyed version directory, not .verified-v1. The bug is specific to the platform-binary managers with a pin, where the fallback semantics of fetch_registry_integrity are reused even though the caller intends a verified, keyed install.

    Regression evidence (history)

    Suggested fix approach (issue option 1 — fail pinned native installs)

    In download_bun_package_manager and download_pnpm_native_package_manager, treat an absent platform dist.integrity as an error only when expected_hash is Some, before any download/extract happens:

    • A dedicated, actionable error variant (PackageManagerIntegrityUnavailable { name, version, url }) rather than reusing a hash-mismatch error, since nothing was compared.
    • Unpinned native installs keep the fix(pm): verify unpinned package-manager downloads against registry integrity #3547 tolerant fallback and stay on the unkeyed version directory, mirroring the generic path.
    • This keeps the .verified-v1 invariant literally true, which is what makes the lock-free, no-recheck reuse safe.

    Edge cases: a pinned project on a third-party mirror or private registry that omits dist.integrity stops working; the error message says what to do (serve the integrity, or drop the pin). The issue accepts this trade-off; npmjs itself serves the field. A 404 on the platform version document already fails (PackageManagerVersionNotFound) for both pinned and unpinned; after the fix the two "registry cannot supply an integrity" cases behave consistently for pinned installs, matching #3553's draft direction. The dist.signatures idea in the issue is out of scope for this fix.


    Verification — gh-3554

    Verdict: bug — the behavior contradicts documented design intent in the code and in the pull requests that built this layout.
    Confidence: high — direct written evidence from the code comments, the commit that introduced the namespace, and a maintainer-authored open PR.

    Evidence of intent (this is not a chosen behavior)

    1. Code documentation contradicts the behavior. VERIFIED_NAMESPACE in crates/vp_pm_cli/src/package_manager.rs (L215–216, PR fix(pm): verify and content-key managed package-manager installs #3400): "Only a download verified against its pin creates a directory here, so a reuse check can trust a complete entry without re-reading the pin." The reproduced path violates both halves: the directory is created by an unverified download, and the completeness fast path then trusts it without any check.
    2. PR fix(pm): verify and content-key managed package-manager installs #3400 states the design: ".verified-v1 … a hidden namespace only a verified download writes to", and "bun and pnpm 12+ pins cover the main tarball, with the platform binary verified against the registry's dist.integrity". The absent-field case is not acknowledged anywhere in the PR.
    3. The tolerant Option contract predates the namespace. fetch_registry_integrity returning None when the field is absent was introduced by feat(pm): verify bun platform tarball against dist.integrity #2310, before .verified-v1 existed. fix(pm): verify and content-key managed package-manager installs #3400 reused the helper without handling None for pinned installs — a gap, not a decision. No comment, doc, or test in the repository asserts that a pinned native install may proceed without an integrity.
    4. PR fix(pm): require registry integrity for package-manager downloads that no pin covers #3553 (open, maintainer direction) scopes tolerance to unpinned installs only. Its description keeps the hard failure for pinned Bun/pnpm ≥ 12: "A pinned Bun or pnpm 12+ install keeps the error from before this PR. Its pin covers only the main tarball, so the registry integrity is the only check of the platform executable." Its tolerance table ("A 404 now has the same result as a document that omits dist.integrity") is explicitly restricted to installs with no pin.
    5. fix(pm): verify unpinned package-manager downloads against registry integrity #3547 tolerance is unpinned-only by its own description: "An unpinned download now fetches the version metadata … A pinned download is unchanged." Nothing in fix(pm): verify unpinned package-manager downloads against registry integrity #3547 extends absent-field tolerance to pinned native installs.
    6. No tests license the behavior. All existing pinned native tests mount a registry that always serves dist.integrity; no test pins and omits the field.

    Counter-considerations (weighed)


    Fix — gh-3554

    Result: fixed. Implemented the issue's option 1, matching the direction maintainers already chose in draft PR #3553: a pinned Bun or pnpm ≥ 12 install fails with a dedicated error when the platform version document omits dist.integrity; unpinned installs keep the tolerant fallback.

    Changed files

    1. crates/vp_error/src/lib.rs — new error variant PackageManagerIntegrityUnavailable { name, version, url } with an actionable two-line message (use a registry that serves dist.integrity, or remove the packageManager hash). name is the platform package (@oven/bun-* / @pnpm/exe.*), url the platform version document.
    2. crates/vp_pm_cli/src/package_manager.rs — in download_bun_package_manager and download_pnpm_native_package_manager, after fetch_registry_integrity, a pinned install that received None now returns PackageManagerIntegrityUnavailable before the platform tarball is downloaded. Documented the Ok(None) contract on fetch_registry_integrity. The .verified-v1 invariant is restored: no unverified content can enter the keyed namespace, so the no-recheck reuse fast path stays sound.
    3. crates/vp_pm_cli/src/package_manager.rs (tests) — regression test pinned_native_install_requires_platform_integrity next to test_download_bun_package_manager_verifies_hashes, covering both pnpm 12.0.0-beta.0 and Bun 1.2.0: pinned + {"dist": {}} → the new error (fields asserted, nothing installed, platform tarball never requested); unpinned + {"dist": {}} → still installs via the fallback, outside VERIFIED_NAMESPACE.

    Alternatives considered (from the issue)

    • Option 2 (continue with a warning): rejected — it keeps reusing the unchecked file, leaving the verified-namespace invariant broken and the trust model wrong.
    • Option 3 (documentation only): rejected for the same reason; the invariant comment describes the mechanism other code relies on.

    Regression test evidence

    • With the fix: cargo test -p vp_pm_cli --lib pinned_native_install_requires_platform_integrity → 1 passed.
    • Without the fix (guard blocks temporarily reverted): the same test fails with a pinned pnpm install without 'dist.integrity' must fail.
    • The reproduction from the reproduce step now ends in Err(PackageManagerIntegrityUnavailable) for the pinned cases; the unpinned control (and all existing integrity-serving tests) behave unchanged.

    Validation

    Check Result
    cargo test -p vp_pm_cli (lib 989 + package_manager_pin_verification integration) all passed
    RUST_MIN_STACK=8388608 cargo test -p <all workspace crates> -p vite-plus-cli (just test, minus trampoline) all suites ok, 0 failures
    cargo check --workspace --all-features --all-targets --locked (just check) clean (pre-existing nix v0.28.0 future-incompat warning only)
    cargo clippy --workspace --all-targets --all-features -- --deny warnings … (just lint main part) clean
    cargo fmt --all --check clean
    git diff --check clean

    Skipped checks (with reasons)

    • cargo test --manifest-path crates/vp_trampoline/Cargo.toml (part of just test): the trampoline is outside the workspace and untouched by this change.
    • just snapshot-test / just snapshot-test-global: no snapshot fixture exercises a hash-pinned native manager against an integrity-less registry (fixture pins are hashless for pnpm 12, e.g. [email protected], and hashed pins are pnpm 10, a tarball manager), and the global-flavor runner executes the pre-installed vp binary, which predates this change.
    • pnpm bootstrap-cli end-to-end: the JS CLI is untouched.

    Follow-up notes (not in this fix)

    • An install already cached under .verified-v1 by a pre-fix binary is still trusted by the completeness fast path; clearing it would need a layout migration (a .verified-v2 bump) and is a separate decision.
    • is_integrity_failure was left unchanged: the new error says a check was impossible, not that an artifact failed a check, and it currently has no non-test callers.
    • dist.signatures verification (issue's last paragraph) remains future work.

    This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.

    I've opened a pull request with this fix: #3555

  3. added
    - P3: minor bug
    on Nov 23, 2026
  4. self-assigned this
    on Nov 23, 2026
  5. added a commit that references this issue on Nov 23, 2026
    5ccfbb3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

- P3: minor bugtriage: fix verified

Type

Fields

Priority

None yet

Effort

None yet

Target date

None yet

Start date

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions