Skip to content

fix(install): reject a global-virtual-store slot suffix that is a route - #14787

Merged
zkochan merged 1 commit into
mainfrom
gvs-cache-hardening
Sep 10, 2026
Merged

zkochan merged 1 commit into
mainfrom
gvs-cache-hardening

Conversation

@zkochan

@zkochan zkochan commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Summary

Three fixes to the global-virtual-store layout cache that #14511 landed. They were reviewed on that PR and verified, but arrived after the merge, so they are here instead.

The one that matters. gvs_layout_cache::load validated a suffix it read back off disk by checking that it starts with the <scope>/<name>/<version>/ its snapshot key implies. A prefix is not a whole name: @scope/foo/1.2.3/../../../../tmp/evil passes that check, and join_global_virtual_store_path then walks it back out of the store, because splitting a suffix into components is that function's job and judging them is not. Slot and node_modules creation follow it out.

cacheDir is settable from a repository's own pnpm-workspace.yaml, so a hostile checkout can ship the entry that gets read. The last component must now be the hex digest calc_graph_node_hash produces, which is a name rather than a route.

AllowBuildPolicy::fingerprint has no caller. The cache key hashes the gating set through GvsHasher::write_gating_set; the method is left over from an earlier revision of that key. It is pub, so nothing warned, and its documentation still claimed the cache keys on it — which would have misled the next person to change either one.

The cache write no longer sync_alls. It runs on the miss path, after the map has already been derived, so the fsync is latency spent on the install the cache exists to speed up. A crash mid-write costs a torn entry, which load already refuses and re-derives.

No changeset: the layout cache has not been released — its changeset from #14511 is still pending.

Squash Commit Body

The layout cache validated a suffix it reads back off disk by checking that
it starts with the `<scope>/<name>/<version>/` its snapshot key implies. A
prefix is not a whole name: `@scope/foo/1.2.3/../../../../tmp` passes that
check, and `join_global_virtual_store_path` then walks it back out of the
store, because splitting a suffix into components is that function's job and
judging them is not. `cacheDir` is settable from a repository's own
`pnpm-workspace.yaml`, so a hostile checkout can ship the entry that gets
read. The last component must now be the hex digest `calc_graph_node_hash`
produces.

Removes `AllowBuildPolicy::fingerprint`, which has had no caller since the
cache key moved to `GvsHasher::write_gating_set`, and whose documentation
still claimed the cache keys on it.

Drops the `sync_all` from the cache write: it runs on the miss path, after
the map has been derived, so the fsync is latency spent on the install the
cache exists to speed up, and a torn entry is one `load` already refuses and
re-derives.

Follow-up to pnpm/pnpm#14511. No changeset — that feature has not shipped.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version. (v12-only: the cache exists only
    in pacquet.)
  • Added a changeset if this PR changes any published package. (Not
    needed — the affected feature is unreleased.)
  • Added or updated tests.
  • Updated the documentation if needed.

🤖 Generated with Claude Code

https://claude.ai/code/session_015YZGn6jMwYeMveHf8RHKfU


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

The layout cache validates a suffix it reads back off disk by checking
that it starts with the `<scope>/<name>/<version>/` its snapshot key
implies. A prefix is not a whole name: `@scope/foo/1.2.3/../../../../tmp`
passes that check, and `join_global_virtual_store_path` then walks it
back out of the store, because splitting a suffix into components is
that function's job and judging them is not.

`cacheDir` is settable from a repository's own `pnpm-workspace.yaml`, so
a hostile checkout can ship the entry that gets read. The last component
must now be the hex digest `calc_graph_node_hash` produces, which is a
name rather than a route.

Two things found alongside it. `AllowBuildPolicy::fingerprint` has no
caller - the cache key hashes the gating set through
`GvsHasher::write_gating_set` - and its documentation claimed the cache
keys on it, which would have misled the next person to change either
one. And the cache write no longer `sync_all`s: it runs on the miss
path, after the map has already been derived, so the fsync is latency
spent on the install the cache exists to speed up, and a torn entry is
something `load` already refuses and re-derives.

No changeset: the layout cache landed in #14511 and has not
been released.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015YZGn6jMwYeMveHf8RHKfU
@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Harden global virtual store layout cache suffix validation

🐞 Bug fix 🧪 Tests ✨ Enhancement 🕐 20-40 Minutes

Grey Divider

AI Description

• Reject cached slot suffixes unless they end in a valid 64-character graph digest.
• Remove obsolete policy fingerprinting and skip fsync latency on best-effort cache writes.
• Add regression coverage for path-traversing cache entries and valid digest fixtures.
Diagram

sequenceDiagram
    actor Install
    participant Loader as Cache Loader
    participant File as Cache File
    participant Validator as Suffix Validator
    participant Deriver as Layout Deriver
    participant Store as Global Store
    Install->>Loader: Load layout
    Loader->>File: Read entry
    File-->>Loader: Cached suffixes
    Loader->>Validator: Check prefix and digest
    alt Valid entry
        Validator-->>Loader: Accept
        Loader-->>Install: Reuse map
    else Invalid entry
        Validator-->>Loader: Reject
        Loader->>Deriver: Re-derive map
        Deriver-->>Install: Safe map
        Deriver->>File: Best-effort write
    end
    Install->>Store: Materialize slots
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Canonicalize and enforce containment
  • ➕ Handles path traversal independently of the current digest format.
  • ➕ Could support future suffix formats containing multiple safe components.
  • ➖ Requires filesystem- and platform-sensitive path handling.
  • ➖ Canonicalization may depend on paths existing and introduces extra I/O.
  • ➖ Permits malformed cache values that satisfy containment but violate the cache contract.
2. Recompute graph-node hashes
  • ➕ Verifies the complete semantic identity of every cached slot.
  • ➕ Rejects well-formed but incorrect graph digests.
  • ➖ Repeats the expensive derivation work the cache is designed to avoid.
  • ➖ Reduces or eliminates warm-install performance gains.

Recommendation: Keep the PR's strict format validation. Requiring exactly the lowercase 64-character digest produced by calc_graph_node_hash cheaply guarantees the suffix remainder is one path component, while preserving the cache's performance purpose. Full hash recomputation is stronger but defeats caching, and canonicalization adds filesystem complexity without enforcing the serialized format contract.

Files changed (3) +47 / -41

Bug fix (1) +21 / -2
virtual_store_layout.rsValidate cached graph digests and avoid cache-write fsync +21/-2

Validate cached graph digests and avoid cache-write fsync

• Requires each cached slot suffix to contain the expected package prefix followed by exactly one 64-character lowercase hexadecimal graph-node digest, rejecting traversal routes. Cache writes remain staged and persisted atomically but no longer call 'sync_all', allowing torn entries to be rejected and re-derived after a crash.

pnpm/crates/deps-restorer/src/virtual_store_layout.rs

Refactor (1) +0 / -32
allow_build_policy.rsRemove obsolete build-policy fingerprint API +0/-32

Remove obsolete build-policy fingerprint API

• Removes the unused public 'AllowBuildPolicy::fingerprint' method and its outdated claim that layout-cache keys depend on it. Cache gating sets are already hashed through 'GvsHasher::write_gating_set'.

pnpm/crates/deps-restorer/src/build_modules/allow_build_policy.rs

Tests (1) +26 / -7
tests.rsCover traversal rejection with realistic graph digests +26/-7

Cover traversal rejection with realistic graph digests

• Updates cache fixtures to use full graph-node digest values and adds a hostile suffix containing parent-directory components. The regression verifies that a package-matching traversal route is rejected as a cache miss.

pnpm/crates/deps-restorer/src/virtual_store_layout/tests.rs

@qodo-code-review

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (2) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. A hostile project can swap package files 🐞 Bug ⛨ Security
Description
load accepts any 64-character lowercase hexadecimal tail instead of requiring the suffix generated
for that snapshot, even though that tail encodes integrity, dependency-graph, engine, and
build-policy state. When a repository points cacheDir at a committed cache, it can map peer
variants to one slot or select an existing same-name/version slot, which the global-store warm path
may treat as authoritative and reuse with different package contents or dependency links.
Code

pnpm/crates/deps-restorer/src/virtual_store_layout.rs[R1044-1046]

+            let digest = suffix.strip_prefix(&expected.slot_prefix(&package_key)?)?;
+            if !is_graph_node_digest(digest) {
                return None;
Relevance

●●● Strong

Recent repository history consistently accepts security hardening that validates untrusted
filesystem paths and cache entries.

PR-#14518
PR-#13901

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed predicate validates only lowercase hexadecimal syntax before inserting the
attacker-provided suffix. slot_prefix removes peer context, while the real digest covers recursive
dependencies, package identity/integrity, engine, and build gating; cached suffixes directly become
slot directories, and the warm-slot logic explicitly treats an existing global-store slot as
authoritative when its basic completion and link probes pass.

pnpm/crates/deps-restorer/src/virtual_store_layout.rs[1043-1050]
pnpm/crates/deps-restorer/src/virtual_store_layout.rs[1080-1088]
pnpm/crates/graph-hasher/src/global_virtual_store_path.rs[25-44]
pnpm/crates/graph-hasher/src/global_virtual_store_path.rs[71-98]
pnpm/crates/deps-restorer/src/virtual_store_layout.rs[376-394]
pnpm/crates/deps-restorer/src/create_virtual_store/snapshot_plan.rs[231-258]
pnpm/crates/deps-restorer/src/create_virtual_store/snapshot_plan.rs[312-369]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The cache loader verifies only the shape of a graph-node digest, so repository-controlled cache data can select an incompatible same-name/version slot. Because validating the exact digest requires deriving the graph hash, cached suffix mappings cannot safely be trusted from `cacheDir` without authentication.

## Fix Focus Areas
- pnpm/crates/deps-restorer/src/virtual_store_layout.rs[264-294]
- pnpm/crates/deps-restorer/src/virtual_store_layout.rs[1043-1050]

## Recommended Fix
Stop loading suffix mappings from the repository-configurable cache and always derive them through `GvsHasher::suffixes`; remove the corresponding cache write path until the cached mapping can be authenticated or independently verified. Add a regression test where two expected peer variants receive the same valid-looking digest, and another where a valid-looking digest selects an existing slot with different integrity, asserting neither mapping is reused.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

2. Policy cleanup is bundled with the fix 📘 Rule violation ⚙ Maintainability
Description
Removing AllowBuildPolicy::fingerprint is dead-code cleanup unrelated to validating cached slot
suffixes. Neither the vulnerable load path nor its regression test uses this method, so its removal
changes a separate public Rust interface within the security fix.
Code

pnpm/crates/deps-restorer/src/build_modules/allow_build_policy.rs[L38-40]

-    #[must_use]
-    pub fn fingerprint(&self) -> String {
-        use sha2::Digest as _;
Relevance

●●● Strong

Recent history accepts cleanup and documentation improvements; the PR explicitly identifies this
method as unused and misleading.

PR-#14142
PR-#14554

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 2255067 requires bug-fix changes to remain directly related to the failing path. The
deleted method is outside the cache loader and is described by the PR itself as unused cleanup found
alongside the vulnerability.

Rule 2255067: Bug fix changes must not include unrelated refactors or reformatting
pnpm/crates/deps-restorer/src/build_modules/allow_build_policy.rs[29-30]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The PR removes an unused public policy method while fixing an unrelated cache path-traversal vulnerability, expanding the review scope beyond the vulnerable path.

## Fix Focus Areas
- pnpm/crates/deps-restorer/src/build_modules/allow_build_policy.rs[29-30]

## Recommended Fix
Restore the removed method in this PR and move its deletion, documentation cleanup, and any API-impact assessment into a separate maintenance PR.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Cache durability changes without metrics 📘 Rule violation ⚙ Maintainability
Description
store removes sync_all from every layout-cache write, although suffix validation neither
requires nor depends on changing write durability. This runs on each cache miss and is justified as
latency reduction without measurements, so the crash-recovery trade-off cannot be evaluated within
this security fix.
Code

pnpm/crates/deps-restorer/src/virtual_store_layout.rs[R1120-1124]

+        // No `sync_all`: this runs on the miss path, after the map has
+        // already been derived, and an fsync there is latency spent on
+        // the install this cache exists to speed up. A crash mid-write
+        // costs a torn entry, which `load` refuses and re-derives.
+        if file.write_all(&bytes).is_ok() {
Relevance

●● Moderate

Durability concerns have rejection precedents, but none closely match removing sync_all from this
cache’s miss-path writer.

PR-#12642
PR-#14606

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
Compliance rule 2255067 excludes behavioral changes that are unnecessary for the stated bug fix,
while the repository performance guide requires performance changes to be measured. These lines
independently remove a durability operation from the cache writer and provide only a qualitative
latency claim.

Rule 2255067: Bug fix changes must not include unrelated refactors or reformatting
pnpm/crates/deps-restorer/src/virtual_store_layout.rs[1120-1124]
REVIEW_GUIDE.md[119-122]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The security fix also removes cache-write synchronization as an unmeasured performance optimization, independently changing crash durability on the cache-miss path.

## Fix Focus Areas
- pnpm/crates/deps-restorer/src/virtual_store_layout.rs[1120-1124]

## Recommended Fix
Restore the synchronized write condition in this PR. Evaluate removing it separately with cache-miss benchmarks across multiple runs and explicit crash-recovery validation.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Context sources
✅ Compliance rules (platform): 37 rules
✅ Cross-repo context — repo relationships
Review mode: ⚖️ Balanced: This security-sensitive cache-validation change affects path traversal prevention and install performance, but its localized logic does not warrant redundant extended passes.
ⓘ  1 issues published inline · 3 in summary

Grey Divider

Tip of the day
💡 Did you know, you can turn these tips off under Display preferences

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment on lines +1044 to 1046
let digest = suffix.strip_prefix(&expected.slot_prefix(&package_key)?)?;
if !is_graph_node_digest(digest) {
return None;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. A hostile project can swap package files 🐞 Bug ⛨ Security

load accepts any 64-character lowercase hexadecimal tail instead of requiring the suffix generated
for that snapshot, even though that tail encodes integrity, dependency-graph, engine, and
build-policy state. When a repository points cacheDir at a committed cache, it can map peer
variants to one slot or select an existing same-name/version slot, which the global-store warm path
may treat as authoritative and reuse with different package contents or dependency links.
Agent Prompt
## Issue description
The cache loader verifies only the shape of a graph-node digest, so repository-controlled cache data can select an incompatible same-name/version slot. Because validating the exact digest requires deriving the graph hash, cached suffix mappings cannot safely be trusted from `cacheDir` without authentication.

## Fix Focus Areas
- pnpm/crates/deps-restorer/src/virtual_store_layout.rs[264-294]
- pnpm/crates/deps-restorer/src/virtual_store_layout.rs[1043-1050]

## Recommended Fix
Stop loading suffix mappings from the repository-configurable cache and always derive them through `GvsHasher::suffixes`; remove the corresponding cache write path until the cached mapping can be authenticated or independently verified. Add a regression test where two expected peer variants receive the same valid-looking digest, and another where a valid-looking digest selects an existing slot with different integrity, asserting neither mapping is reused.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@github-actions

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.12     14.2±1.00ms    26.4 MB/sec    1.00     12.6±0.38ms    29.6 MB/sec
packument/parse                                  1.07     42.4±0.66µs  1564.8 MB/sec    1.00     39.7±0.98µs  1669.8 MB/sec
tarball/download_dependency                      1.11      5.0±0.53ms   864.5 KB/sec    1.00      4.5±0.16ms   959.0 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.03   216.9±18.01ms 73.8 KElem/sec    1.00   211.5±13.29ms 75.7 KElem/sec
workspace_resolution/hoist_heavy                 1.34   339.0±17.20ms        ? ?/sec    1.00    252.6±4.34ms        ? ?/sec
workspace_sort/chained_projects                  1.13     15.2±1.71ms        ? ?/sec    1.00     13.4±1.40ms        ? ?/sec

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.56%. Comparing base (e2a91d4) to head (2a93ccd).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##             main   #14787    +/-   ##
========================================
  Coverage   90.55%   90.56%            
========================================
  Files         801      801            
  Lines      155978   156294   +316     
========================================
+ Hits       141250   141543   +293     
- Misses      14728    14751    +23     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 2a93ccd3c80f

Regular scenarios report direct and pnpr installs. The peer-heavy resolver scenario compares current Rust, main Rust, and TypeScript pnpm. Bencher consumes pacquet@HEAD and pnpr@HEAD.

The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time).

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.558 ± 0.094 2.394 2.690 1.81 ± 0.20
pacquet@main 2.526 ± 0.091 2.393 2.678 1.79 ± 0.19
pnpr@HEAD 1.512 ± 0.144 1.303 1.681 1.07 ± 0.15
pnpr@main 1.413 ± 0.144 1.299 1.643 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.55772120232,
      "stddev": 0.09395482864804336,
      "median": 2.56049872692,
      "user": 1.7715283,
      "system": 1.5339790799999997,
      "min": 2.39375688792,
      "max": 2.68985107792
    },
    {
      "command": "pacquet@main",
      "mean": 2.52628535192,
      "stddev": 0.09069441303871682,
      "median": 2.5265594489200005,
      "user": 1.6488471999999998,
      "system": 1.4915425799999995,
      "min": 2.3934971009200003,
      "max": 2.6780587699200002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.51241320662,
      "stddev": 0.14396926842175942,
      "median": 1.5737427734199998,
      "user": 1.2905162000000001,
      "system": 1.43644038,
      "min": 1.30289033292,
      "max": 1.6808156989199998
    },
    {
      "command": "pnpr@main",
      "mean": 1.41327453352,
      "stddev": 0.14374029072334166,
      "median": 1.35284860442,
      "user": 1.2688175999999998,
      "system": 1.4238327799999997,
      "min": 1.29851104492,
      "max": 1.64255071292
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 221.3 ± 16.3 200.6 260.7 1.05 ± 0.10
pacquet@main 211.4 ± 12.5 193.8 240.3 1.00
pnpr@HEAD 251.4 ± 39.2 221.8 353.6 1.19 ± 0.20
pnpr@main 250.4 ± 11.6 233.0 270.2 1.18 ± 0.09
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.2212906785,
      "stddev": 0.016270737045152226,
      "median": 0.22021774700000002,
      "user": 0.24401544,
      "system": 0.5298295599999999,
      "min": 0.20056755500000004,
      "max": 0.260663127
    },
    {
      "command": "pacquet@main",
      "mean": 0.21135328859999997,
      "stddev": 0.01246005179630205,
      "median": 0.21076457750000002,
      "user": 0.23061144000000003,
      "system": 0.5113055599999999,
      "min": 0.193792859,
      "max": 0.240266886
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.2513519459,
      "stddev": 0.039212001187518504,
      "median": 0.23818573200000004,
      "user": 0.26540764,
      "system": 0.5681017599999999,
      "min": 0.22175144000000002,
      "max": 0.353577889
    },
    {
      "command": "pnpr@main",
      "mean": 0.2504115858,
      "stddev": 0.011618298862830301,
      "median": 0.24977635650000002,
      "user": 0.26854233999999993,
      "system": 0.55455856,
      "min": 0.23296893100000002,
      "max": 0.270202443
    }
  ]
}

Scenario: Isolated linker: repeat install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 7.6 ± 0.7 6.4 11.0 1.11 ± 0.11
pacquet@main 6.8 ± 0.3 6.2 8.1 1.00
pnpr@HEAD 7.2 ± 0.6 6.2 9.6 1.05 ± 0.10
pnpr@main 7.3 ± 1.2 6.0 12.7 1.08 ± 0.18
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.007550904757142854,
      "stddev": 0.0006702666862393779,
      "median": 0.0074531839,
      "user": 0.004368520714285714,
      "system": 0.0036308642857142874,
      "min": 0.0063825714,
      "max": 0.0110361524
    },
    {
      "command": "pacquet@main",
      "mean": 0.006807403413513507,
      "stddev": 0.0002858939991648549,
      "median": 0.0067889029,
      "user": 0.004194297837837836,
      "system": 0.0030117902702702713,
      "min": 0.0061657254000000005,
      "max": 0.008137941400000001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.0071502902666666715,
      "stddev": 0.0006198424589113135,
      "median": 0.0070010714,
      "user": 0.004208857333333335,
      "system": 0.003374806933333335,
      "min": 0.0061634414000000005,
      "max": 0.009593628400000002
    },
    {
      "command": "pnpr@main",
      "mean": 0.0073376161857142885,
      "stddev": 0.001168705164557605,
      "median": 0.0069672479,
      "user": 0.0045148219230769235,
      "system": 0.003253008241758241,
      "min": 0.0060052744,
      "max": 0.012657621400000001
    }
  ]
}

Scenario: Isolated linker: repeat install, cold cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 8.4 ± 1.0 6.6 15.9 1.10 ± 0.19
pacquet@main 7.6 ± 1.0 6.0 11.4 1.00
pnpr@HEAD 7.7 ± 0.9 5.9 10.3 1.01 ± 0.18
pnpr@main 7.8 ± 1.0 6.0 11.0 1.02 ± 0.19
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.008362601347647061,
      "stddev": 0.0009551295778864267,
      "median": 0.00828737698,
      "user": 0.0049100170588235285,
      "system": 0.003916539558823528,
      "min": 0.006591662979999999,
      "max": 0.01587272698
    },
    {
      "command": "pacquet@main",
      "mean": 0.007597394690526313,
      "stddev": 0.0010059654389346622,
      "median": 0.00762731948,
      "user": 0.0045164320300751905,
      "system": 0.003511307218045113,
      "min": 0.0059648589799999995,
      "max": 0.011416485980000002
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.007677420417062941,
      "stddev": 0.00094864006183808,
      "median": 0.007751502480000001,
      "user": 0.004299616503496502,
      "system": 0.0038239430769230805,
      "min": 0.005921718980000001,
      "max": 0.010330129980000002
    },
    {
      "command": "pnpr@main",
      "mean": 0.007786593419597311,
      "stddev": 0.000975652207342898,
      "median": 0.0077861219800000004,
      "user": 0.00460765147651007,
      "system": 0.003619576241610736,
      "min": 0.00601222798,
      "max": 0.01101502398
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.462 ± 0.014 2.440 2.482 1.64 ± 0.14
pacquet@main 2.452 ± 0.031 2.424 2.528 1.63 ± 0.14
pnpr@HEAD 1.504 ± 0.131 1.379 1.727 1.00
pnpr@main 1.525 ± 0.148 1.378 1.738 1.01 ± 0.13
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.4622288023400003,
      "stddev": 0.01353631015264503,
      "median": 2.4579381375400002,
      "user": 1.73651014,
      "system": 1.50369648,
      "min": 2.4401890070400003,
      "max": 2.48246817404
    },
    {
      "command": "pacquet@main",
      "mean": 2.45170736574,
      "stddev": 0.03111347513179728,
      "median": 2.44103640804,
      "user": 1.7044247399999999,
      "system": 1.4940495799999995,
      "min": 2.42408736104,
      "max": 2.52752751504
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5044337336399998,
      "stddev": 0.13118200929468748,
      "median": 1.4357646985399999,
      "user": 1.12035814,
      "system": 1.2181301799999997,
      "min": 1.37919296304,
      "max": 1.7269921280399998
    },
    {
      "command": "pnpr@main",
      "mean": 1.5248820149399998,
      "stddev": 0.14840624783678782,
      "median": 1.46715216154,
      "user": 1.0529791400000001,
      "system": 1.21852348,
      "min": 1.37789894904,
      "max": 1.73845000904
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 340.2 ± 8.7 324.8 355.7 1.26 ± 0.04
pacquet@main 345.8 ± 27.5 309.7 401.6 1.28 ± 0.10
pnpr@HEAD 269.4 ± 3.9 263.3 274.7 1.00
pnpr@main 273.7 ± 18.1 244.2 309.0 1.02 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.34020534338,
      "stddev": 0.008729947215870112,
      "median": 0.34070154888000004,
      "user": 0.50809734,
      "system": 0.76929912,
      "min": 0.32476963138000003,
      "max": 0.35574825538000004
    },
    {
      "command": "pacquet@main",
      "mean": 0.34575870897999994,
      "stddev": 0.027452561339224035,
      "median": 0.3458132018800001,
      "user": 0.5110096399999999,
      "system": 0.78026502,
      "min": 0.30972128238,
      "max": 0.40158472138000006
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.26935098558000004,
      "stddev": 0.003922947906889906,
      "median": 0.26933487438000003,
      "user": 0.21446944,
      "system": 0.5019889199999998,
      "min": 0.26329803638000004,
      "max": 0.27468832238
    },
    {
      "command": "pnpr@main",
      "mean": 0.27366253968,
      "stddev": 0.018136477631388717,
      "median": 0.27649753288,
      "user": 0.21914244,
      "system": 0.50378222,
      "min": 0.24419492738,
      "max": 0.30895730038
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.552 ± 0.044 1.508 1.647 5.80 ± 0.26
pacquet@main 1.536 ± 0.017 1.509 1.559 5.75 ± 0.21
pnpr@HEAD 0.279 ± 0.008 0.266 0.294 1.04 ± 0.05
pnpr@main 0.267 ± 0.009 0.257 0.284 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.55221051878,
      "stddev": 0.04413111877931932,
      "median": 1.53987852238,
      "user": 0.83806406,
      "system": 0.87562558,
      "min": 1.50769809138,
      "max": 1.64704515738
    },
    {
      "command": "pacquet@main",
      "mean": 1.5363469809799999,
      "stddev": 0.016770442556289948,
      "median": 1.53661389288,
      "user": 0.79584946,
      "system": 0.9079450800000002,
      "min": 1.50934809438,
      "max": 1.55873894338
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.27852234498,
      "stddev": 0.007678944237076598,
      "median": 0.27785983988,
      "user": 0.21565496,
      "system": 0.52153438,
      "min": 0.26634874838,
      "max": 0.29433501738
    },
    {
      "command": "pnpr@main",
      "mean": 0.26740204258,
      "stddev": 0.009094342172531153,
      "median": 0.26760318588,
      "user": 0.20744455999999997,
      "system": 0.5052389799999999,
      "min": 0.25665893638,
      "max": 0.28380422738
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 206.3 ± 23.3 179.9 247.6 2.32 ± 0.27
pacquet@main 190.3 ± 11.5 176.2 209.2 2.14 ± 0.14
pnpr@HEAD 90.3 ± 3.1 86.7 97.4 1.01 ± 0.04
pnpr@main 89.1 ± 2.3 86.2 94.7 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.20632031390571431,
      "stddev": 0.023254283638942785,
      "median": 0.20189141962,
      "user": 0.2043475514285714,
      "system": 0.07358731999999998,
      "min": 0.17991745112000002,
      "max": 0.24762301012000001
    },
    {
      "command": "pacquet@main",
      "mean": 0.19025244645333333,
      "stddev": 0.01145192851837188,
      "median": 0.18641639212,
      "user": 0.19923551333333336,
      "system": 0.06302748666666665,
      "min": 0.17615006912,
      "max": 0.20918745512
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.09025987584727271,
      "stddev": 0.003121346398431515,
      "median": 0.08927376812,
      "user": 0.03218907090909091,
      "system": 0.012766078787878788,
      "min": 0.08667554612,
      "max": 0.09743797012
    },
    {
      "command": "pnpr@main",
      "mean": 0.08910222245333332,
      "stddev": 0.00232605802487052,
      "median": 0.08800227412,
      "user": 0.028394343636363634,
      "system": 0.015314825454545457,
      "min": 0.08622649512,
      "max": 0.09472981512
    }
  ]
}

Scenario: Isolated linker: peer-heavy resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 677.9 ± 50.5 607.4 757.8 1.00
pacquet@main 695.0 ± 79.8 590.5 814.9 1.03 ± 0.14
pnpm@HEAD 3050.4 ± 99.1 2876.1 3157.0 4.50 ± 0.37
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.67793843304,
      "stddev": 0.05047152925426071,
      "median": 0.66069501504,
      "user": 0.6961421866666666,
      "system": 0.18113910444444445,
      "min": 0.6074269090400001,
      "max": 0.7578249770400001
    },
    {
      "command": "pacquet@main",
      "mean": 0.6950483014844445,
      "stddev": 0.07977425763133614,
      "median": 0.7092514190400001,
      "user": 0.7076654088888888,
      "system": 0.18098221555555555,
      "min": 0.5904818760400001,
      "max": 0.8149341840400001
    },
    {
      "command": "pnpm@HEAD",
      "mean": 3.0503969561511104,
      "stddev": 0.09909420027902434,
      "median": 3.0935407960399997,
      "user": 4.7434112977777785,
      "system": 0.25462866,
      "min": 2.87612732304,
      "max": 3.1570023410399997
    }
  ]
}

Scenario: Isolated linker: fresh restore, cold cache + cold store + cold pnpr

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.582 ± 0.155 4.398 4.895 1.34 ± 0.05
pacquet@main 4.567 ± 0.127 4.392 4.766 1.34 ± 0.04
pnpr@HEAD 3.413 ± 0.060 3.350 3.557 1.00
pnpr@main 3.444 ± 0.047 3.390 3.554 1.01 ± 0.02
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.582090228799999,
      "stddev": 0.15523307939099706,
      "median": 4.5690085772,
      "user": 1.9246385399999997,
      "system": 1.6162477399999997,
      "min": 4.397926592199999,
      "max": 4.8945753482
    },
    {
      "command": "pacquet@main",
      "mean": 4.5671047284999995,
      "stddev": 0.12654393556544816,
      "median": 4.5696469677,
      "user": 1.83018844,
      "system": 1.5770707399999997,
      "min": 4.3924432942,
      "max": 4.7662457662
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.412830437,
      "stddev": 0.060043625186354935,
      "median": 3.3901489262,
      "user": 1.32950704,
      "system": 1.4324346399999999,
      "min": 3.3503358412,
      "max": 3.5572402582000002
    },
    {
      "command": "pnpr@main",
      "mean": 3.4438198763,
      "stddev": 0.04721734990863024,
      "median": 3.4330043547000004,
      "user": 1.3987248399999999,
      "system": 1.4657944399999998,
      "min": 3.3897379722000003,
      "max": 3.5541351382
    }
  ]
}

Scenario: GVS linker: fresh restore, hot cache + hot store

Same install as the isolated fresh-restore hot/hot scenario, into the shared virtual store — the layout pnpm 12 installs into by default. Comparable to that scenario head-to-head.

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 121.5 ± 9.6 102.6 138.4 1.00
pacquet@main 130.5 ± 18.4 103.7 168.9 1.07 ± 0.17
pnpr@HEAD 133.0 ± 11.0 120.5 168.1 1.09 ± 0.12
pnpr@main 133.2 ± 4.5 124.8 141.8 1.10 ± 0.09
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.12150253646736847,
      "stddev": 0.009562622765901743,
      "median": 0.12072602852000001,
      "user": 0.14004542105263157,
      "system": 0.1392771610526316,
      "min": 0.10259666752,
      "max": 0.13843138252
    },
    {
      "command": "pacquet@main",
      "mean": 0.13052970220181817,
      "stddev": 0.01843811927957442,
      "median": 0.12976939802,
      "user": 0.1466334090909091,
      "system": 0.14468496727272726,
      "min": 0.10373456052,
      "max": 0.16894238852000001
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.1329688609866667,
      "stddev": 0.010992827476793539,
      "median": 0.13292570352000002,
      "user": 0.14551753333333334,
      "system": 0.13954620666666664,
      "min": 0.12047518752000001,
      "max": 0.16812341452000001
    },
    {
      "command": "pnpr@main",
      "mean": 0.13321831287000002,
      "stddev": 0.00453410205043356,
      "median": 0.13372296302000003,
      "user": 0.15027359999999995,
      "system": 0.13383249,
      "min": 0.12476290452000002,
      "max": 0.14184387852000002
    }
  ]
}

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/14787
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
gvs-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
102.60 ms
(-17.86%)Baseline: 124.90 ms
149.88 ms
(68.45%)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
2,440.19 ms
(-0.57%)Baseline: 2,454.08 ms
2,944.89 ms
(82.86%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,507.70 ms
(-2.38%)Baseline: 1,544.45 ms
1,853.34 ms
(81.35%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
324.77 ms
(-11.94%)Baseline: 368.80 ms
442.56 ms
(73.38%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
179.92 ms
(-11.53%)Baseline: 203.38 ms
244.05 ms
(73.72%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,393.76 ms
(+0.88%)Baseline: 2,372.78 ms
2,847.34 ms
(84.07%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,397.93 ms
(+0.24%)Baseline: 4,387.59 ms
5,265.11 ms
(83.53%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
200.57 ms
(-9.13%)Baseline: 220.73 ms
264.87 ms
(75.72%)
isolated-linker.peer-heavy-resolve.hot-cache.offline📈 view plot
🚷 view threshold
607.43 ms
(+10.01%)Baseline: 552.14 ms
662.57 ms
(91.68%)
isolated-linker.repeat-install.cold-cache.hot-store📈 view plot
🚷 view threshold
6.59 ms
(-0.98%)Baseline: 6.66 ms
7.99 ms
(82.52%)
isolated-linker.repeat-install.hot-cache.hot-store📈 view plot
🚷 view threshold
6.38 ms
(-0.93%)Baseline: 6.44 ms
7.73 ms
(82.56%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Projectpnpm's project
Branchpr/14787
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
gvs-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
120.48 ms
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,379.19 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
266.35 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
263.30 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
86.68 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,302.89 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,350.34 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
221.75 ms
isolated-linker.repeat-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
5.92 ms
isolated-linker.repeat-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
6.16 ms
🐰 View full continuous benchmarking report in Bencher

@zkochan
zkochan merged commit 537a281 into main Sep 10, 2026
35 checks passed
@zkochan
zkochan deleted the gvs-cache-hardening branch September 10, 2026 13:24
biisal pushed a commit to biisal/pnpm that referenced this pull request Sep 15, 2026
…te (pnpm#14787)

The layout cache validates a suffix it reads back off disk by checking
that it starts with the `<scope>/<name>/<version>/` its snapshot key
implies. A prefix is not a whole name: `@scope/foo/1.2.3/../../../../tmp`
passes that check, and `join_global_virtual_store_path` then walks it
back out of the store, because splitting a suffix into components is
that function's job and judging them is not.

`cacheDir` is settable from a repository's own `pnpm-workspace.yaml`, so
a hostile checkout can ship the entry that gets read. The last component
must now be the hex digest `calc_graph_node_hash` produces, which is a
name rather than a route.

Two things found alongside it. `AllowBuildPolicy::fingerprint` has no
caller - the cache key hashes the gating set through
`GvsHasher::write_gating_set` - and its documentation claimed the cache
keys on it, which would have misled the next person to change either
one. And the cache write no longer `sync_all`s: it runs on the miss
path, after the map has already been derived, so the fsync is latency
spent on the install the cache exists to speed up, and a torn entry is
something `load` already refuses and re-derives.

No changeset: the layout cache landed in pnpm#14511 and has not
been released.


Claude-Session: https://claude.ai/code/session_015YZGn6jMwYeMveHf8RHKfU

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
u9g pushed a commit to u9g/pnpm that referenced this pull request Sep 25, 2026
…te (pnpm#14787)

The layout cache validates a suffix it reads back off disk by checking
that it starts with the `<scope>/<name>/<version>/` its snapshot key
implies. A prefix is not a whole name: `@scope/foo/1.2.3/../../../../tmp`
passes that check, and `join_global_virtual_store_path` then walks it
back out of the store, because splitting a suffix into components is
that function's job and judging them is not.

`cacheDir` is settable from a repository's own `pnpm-workspace.yaml`, so
a hostile checkout can ship the entry that gets read. The last component
must now be the hex digest `calc_graph_node_hash` produces, which is a
name rather than a route.

Two things found alongside it. `AllowBuildPolicy::fingerprint` has no
caller - the cache key hashes the gating set through
`GvsHasher::write_gating_set` - and its documentation claimed the cache
keys on it, which would have misled the next person to change either
one. And the cache write no longer `sync_all`s: it runs on the miss
path, after the map has already been derived, so the fsync is latency
spent on the install the cache exists to speed up, and a torn entry is
something `load` already refuses and re-derives.

No changeset: the layout cache landed in pnpm#14511 and has not
been released.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants