fix(install): verify modern Yarn hashes against the CLI binary - #2227
fix(install): verify modern Yarn hashes against the CLI binary#2227leslieeilsel wants to merge 2 commits into
Conversation
✅ Deploy Preview for viteplus-preview canceled.
|
f7cdc8f to
26615d1
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Local verification results (run on macOS,
|
07ce1cf to
c3609f2
Compare
|
@leslieeilsel Can you convert the reproduction steps described in #2209 into a snapshot test? This would ensure that this issue continues to be validated. |
Added verification for Yarn binary hash for modern Yarn installations. Updated download logic to handle Yarn 2+ package manager correctly. Signed-off-by: Leslie Lau <1178273431@qq.com>
c3609f2 to
35de2cb
Compare
|
Thanks for the suggestion — I’ve added CLI snapshot coverage based on #2209’s cold-cache reproduction. It uses the exact Corepack-generated Yarn 4.17.1 pin, runs I also added a |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 35de2cb5d9
ℹ️ 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".
| if is_modern_yarn { | ||
| verify_yarn_binary_hash(&extracted_package_dir, expected_hash).await?; |
There was a problem hiding this comment.
Retry failed Yarn binary integrity checks
When a registry or CDN returns a successfully extractable archive whose yarn.js is corrupted, this check returns HashMismatch only after download_and_extract_tgz_with_hash has completed, bypassing that helper's retry loop even though it explicitly treats hash mismatches as retryable download failures. Consequently, a transient bad response immediately aborts an otherwise valid Yarn installation; include the binary verification in the retried download pipeline or apply equivalent retries around this check.
Useful? React with 👍 / 👎.
| let tmp_dir = tempfile::tempdir_in(parent_dir)?; | ||
| let target_dir_tmp = tmp_dir.path().to_path_buf(); | ||
|
|
||
| let archive_hash = if is_modern_yarn { None } else { expected_hash }; |
There was a problem hiding this comment.
Do not extract unauthenticated Yarn archive entries
When the configured npm registry or its delivery path is compromised, clearing the archive hash here lets an attacker supply a tarball containing the correctly pinned bin/yarn.js plus arbitrary unauthenticated entries. The code extracts the entire archive before checking only yarn.js; for example, a bin/yarn symlink to an absolute user-writable path survives verification and create_shim_files later writes the generated shim through it, allowing arbitrary file overwrite. Extract only the authenticated CLI entry into a clean layout, as Corepack does, or independently authenticate the complete archive before installing it.
Useful? React with 👍 / 👎.
| if is_modern_yarn { | ||
| verify_yarn_binary_hash(&install_dir, expected_hash).await?; |
There was a problem hiding this comment.
Verify cached Yarn before global shim dispatch
When a project invokes yarn or yarnpkg directly through the global Vite+ shim and that version is already cached, resolve_matching_package_manager_tool in crates/vp_global_cli/src/shim/dispatch.rs returns the existing executable at lines 690-697 without calling download_package_manager. This new warm-cache check therefore never runs on that primary command path, so a corrupted or replaced yarn.js is executed despite the project's integrity pin; route hash-pinned modern Yarn through verification before taking the shim fast path.
AGENTS.md reference: AGENTS.md:L182-L182
Useful? React with 👍 / 👎.
Summary
packageManagerhashes against the extractedbin/yarn.js, matching CorepackWhy
Corepack writes Yarn 2+ integrity pins from the extracted CLI binary, while Vite+ previously compared them with the npm tarball hash. This made valid Corepack pins fail with a cold Vite+ cache and appear to pass with a warm cache because the cached artifact was not re-verified.
Fixes #2209
Test Plan
cargo fmt --all -- --checkcargo test -p vite_install --lockedcargo check -p vite_install --all-features --all-targets --lockedcargo clippy -p vite_install --all-targets --all-features --locked -- --deny warningsvp installrejects a Corepack-writtenpackageManagerpin: vp hashes the .tgz, Corepack hashes the extracted binary #2209 with cold and warm cachesyarn.jsreturnsHashMismatchwithout downloading again