Repository navigation
fix(install): reject a global-virtual-store slot suffix that is a route - #14787
Conversation
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
PR Summary by QodoHarden global virtual store layout cache suffix validation
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1. A hostile project can swap package files
|
| let digest = suffix.strip_prefix(&expected.slot_prefix(&package_key)?)?; | ||
| if !is_graph_node_digest(digest) { | ||
| return None; |
There was a problem hiding this comment.
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
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Micro-Benchmark ResultsLinux |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Integrated-Benchmark Report (Linux)Commit: 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
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
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
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
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
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
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
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
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
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
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 storeSame 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.
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
}
]
} |
|
| Project | pnpm's project |
| Branch | pr/14787 |
| Testbed | pnpr |
⚠️ 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-thresholdsflag.
Click to view all benchmark results
| Benchmark | Latency | milliseconds (ms) |
|---|---|---|
| gvs-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 120.48 ms |
| isolated-linker.fresh-install.cold-cache.cold-store | 📈 view plot | 1,379.19 ms |
| isolated-linker.fresh-install.cold-cache.hot-store | 📈 view plot | 266.35 ms |
| isolated-linker.fresh-install.hot-cache.hot-store | 📈 view plot | 263.30 ms |
| isolated-linker.fresh-resolve.hot-cache.offline | 📈 view plot | 86.68 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store | 📈 view plot | 1,302.89 ms |
| isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr | 📈 view plot | 3,350.34 ms |
| isolated-linker.fresh-restore.hot-cache.hot-store | 📈 view plot | 221.75 ms |
| isolated-linker.repeat-install.cold-cache.hot-store | 📈 view plot | 5.92 ms |
| isolated-linker.repeat-install.hot-cache.hot-store | 📈 view plot | 6.16 ms |
…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]>
…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.
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::loadvalidated 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/evilpasses that check, andjoin_global_virtual_store_paththen walks it back out of the store, because splitting a suffix into components is that function's job and judging them is not. Slot andnode_modulescreation follow it out.cacheDiris settable from a repository's ownpnpm-workspace.yaml, so a hostile checkout can ship the entry that gets read. The last component must now be the hex digestcalc_graph_node_hashproduces, which is a name rather than a route.AllowBuildPolicy::fingerprinthas no caller. The cache key hashes the gating set throughGvsHasher::write_gating_set; the method is left over from an earlier revision of that key. It ispub, 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, whichloadalready refuses and re-derives.No changeset: the layout cache has not been released — its changeset from #14511 is still pending.
Squash Commit Body
Checklist
already linked to it solves it.
are implemented in every affected version. (v12-only: the cache exists only
in pacquet.)
needed — the affected feature is unreleased.)
🤖 Generated with Claude Code
https://claude.ai/code/session_015YZGn6jMwYeMveHf8RHKfU
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.