Skip to content

Stop attesting a vendored pnpm package through an override its pnpm 10 release does not read - #2441

Merged
Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
arch-refactor/2403-pnpm-lock-off-override-source
Dec 2, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 5 commits into
mainfrom
arch-refactor/2403-pnpm-lock-off-override-source

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Dec 2, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code

Fixes #2403.

Problem

With pnpm's lockfile setting off, pnpm never reads pnpm-lock.yaml, so a vendored package installs from its committed artifact only through an override. vex attests such a package "only while the override map the governing pnpm reads without a lock routes the package" to the artifact (CLI_CONTRACT.md, pnpm with its lockfile off).

The reader that applies the rule went by pnpm major and took either file for pnpm 10. Real pnpm 10 reads one of them, by release:

  • 10.0 to 10.5.0 read package.json alone;
  • 10.5.1 and newer read pnpm-workspace.yaml only while package.json declares no override of its own (pnpm.overrides, or the top-level resolutions).

With the vendored override in the file that release does not read, pnpm install installs the upstream release and exits 0. There is no frozen install to fail. vex exits 0 and attests not_affected.

A project gets there without editing a wiring line: vendor writes the override to pnpm-workspace.yaml alone when that file already holds overrides (the issue's step 2), and the project later adds a resolutions entry for another package.

The same rule was fixed for the lock-on reader in #2396 (OverrideSource, with the 10.5.1 boundary). The lock-off reader kept its own pnpm10 flag.

Evidence on main (7d78f2f)

Real pnpm, lockfile=false in .npmrc, a patched left-pad 1.3.0 tarball under .socket/vendor/npm/, packageManager pinning the pnpm that runs:

9.15.9   override in workspace only                          -> exit 0, installs UPSTREAM
10.4.1   override in manifest                                -> exit 0, installs patched
10.4.1   override in workspace only                          -> exit 0, installs UPSTREAM
10.5.0   override in workspace only                          -> exit 0, installs UPSTREAM
10.5.1   override in workspace only                          -> exit 0, installs patched
10.28.0  override in workspace only                          -> exit 0, installs patched
10.28.0  override in workspace; own pnpm.overrides           -> exit 0, installs UPSTREAM
10.28.0  override in workspace; own resolutions              -> exit 0, installs UPSTREAM
10.28.0  pnpm.overrides holds own + vendored; workspace too  -> exit 0, installs patched

The binary and real pnpm 10.28.0 on one tree. The vendored tree of a project whose pnpm-workspace.yaml has an override of its own, then a resolutions entry for another package added to package.json:

$ pnpm install                                   # the vendored tree
exit 0; SOCKET-PATCHED lines in node_modules/left-pad/index.js: 1
$ rm -rf node_modules && pnpm install            # "resolutions": {"is-number": "7.0.0"} added
exit 0; SOCKET-PATCHED lines in node_modules/left-pad/index.js: 0

$ socket-patch vex --product pkg:npm/app@1.0.0   # main
Warning: pkg:npm/left-pad@1.3.0: the installed tree does not match its vendored artifact; […] re-run your package manager's install to resync it.
Wrote OpenVEX document with 1 statement to out.vex.json
exit 0
"status": "not_affected"

$ socket-patch vex --product pkg:npm/app@1.0.0   # this branch
Warning: pkg:npm/left-pad@1.3.0: patch 1a2b3c4d-… is wired, but its pin is in pnpm-lock.yaml, and `lockfile=false` in .npmrc makes pnpm neither read nor write pnpm-lock.yaml, […] and package.json `pnpm.overrides` does not route this package to it (pnpm@10.28.0 (node_modules/.modules.yaml) reads package.json's overrides when it declares any (`pnpm.overrides` or `resolutions`), and pnpm-workspace.yaml `overrides` when it declares none); not attested […]
Warning: omitting pkg:npm/left-pad@1.3.0 from VEX: the patch could not be verified (vex_lock_not_read)
Error: No applied patches with vulnerability metadata to attest.
exit 1

Two tests, red on main and green here. The unit test from the issue, beside the existing lock-off test:

test vex::discover::npm::tests::pnpm_disabled_lockfile_reads_the_map_its_pnpm_10_release_reads ... FAILED
attested from pnpm-workspace.yaml, which that pnpm does not read: [
    "pnpm@10.4.1",
    "pnpm@10.5.0",
    "pnpm@10.28.0,\"pnpm\":{\"overrides\":{\"is-number\":\"7.0.0\"}}",
    "pnpm@10.28.0,\"resolutions\":{\"is-number\":\"7.0.0\"}",
]

and a CLI test in e2e_vex_vendor, run against the binary built from main's sources:

test vendored_pnpm_pin_with_the_lock_off_needs_the_override_its_release_reads ... FAILED
["--offline"]: nothing may attest: {"command":"vex","status":"success", […] "events":[{"action":"verified","purl":"pkg:npm/foo@1.0.0","details":{[…]"status":"not_affected"}}] […]
  left: Some(0)
 right: Some(1)

The fix

One answer to "which file does this pnpm read overrides from": OverrideSource, for both lock states.

  • formats/pnpm/version.rs gains governing_override_sources: the OverrideSource of each pnpm that governs the project's settings. Those are the release node_modules/.modules.yaml records and the one packageManager pins, the two files the contract reads the major from. Only one exact version names a release.
  • utils/pnpm_workspace.rs: lockfile_off_override_sources returns where each pnpm that installs the project with its lock off reads its overrides. First the named releases. Then, for the settings file that turns the lock off: the workspace file for pnpm 11 and newer; for pnpm 10 and older with no release named, package.json, where every such pnpm reads an override.
  • vex/discover/npm.rs: PnpmLockOff::routes is "every one of those readers reads the override" (OverrideSource::reads, the function the lock-on check calls). "Declares any override" is counted as pnpm counts it: a table with keys.
  • The detail of vex_lock_not_read names the map that has to route the package and what each named pnpm reads.

The unit test has 30 rows, each with what real pnpm installs: the four from the issue, controls that must still attest, the install record against the pin, override tables that are not objects, and no release named.

What the review found

An independent review ran /code-review high on the first cut and checked each finding with real pnpm.

Finding Outcome
A tree pnpm 10.28.0 installed, whose pin then moves to 10.4.1, was still attested from the workspace file: the install record outranked the pin. pnpm switches to the pinned release at the next install and installs the upstream release (ran). main attests it too. Fixed: the record and the pin are both asked. Ran again: omitted before and after that install. A pin moved to pnpm 11.29.0 behaves the same way (ran: upstream with the override in package.json alone, patched with it in both files).
"resolutions": null or [] and "pnpm": {"overrides": null} were read as declaring overrides, so a workspace override beside them stopped attesting. pnpm 10.28.0 reads them as declaring none (ran). Fixed: a table declares when it has keys. "pnpm": {"overrides": "x"} has keys, and pnpm installs the upstream release beside it (ran); it is omitted.
A sentence in docs/ecosystems.md held only when .npmrc is what turns the lock off. Fixed.
A project whose root manifest is package.yaml, with overrides of its own there, is attested from the workspace file (ran; the same on main, in both lock states). Not fixed here. socket-patch vendor refuses a pnpm project with no package.json (ran: "cannot read package.json"), so the tree needs a manifest converted after vendoring. Recorded as a lead in the routine's ledger.

A second, shorter pass on the reworked diff, again with real pnpm:

Finding Outcome
A packageManager that is not one exact version (pnpm@10), beside an install record of 10.28.0, was taken for an unknown pnpm 10 and the tree was omitted. pnpm does not switch to such a pin ("not a valid version") and installs the artifact with the pnpm at hand (ran, also for pnpm@^10.6.0). Fixed: only an exact version names a release. Ran again: attested, as on main.
The lock-on reader lets a reference stand beside "pnpm": {"overrides": "x"} or a non-empty array there, where a frozen install fails and a plain one installs the upstream release (ran; the same on main). Not fixed here. That is #2396's rule for a declaration the reader cannot follow, in the lock-on reader, over a malformed manifest. Recorded as a lead.
The second pre-11 reader the fallback added changed no answer; the detail never said that resolutions counts. Taken.

The fixes for the second pass were not reviewed again.

Deleted

lockfile_off_sources and its (bool, bool, Option<u32>) answer, and PnpmLockOff's needs_workspace, needs_manifest and pnpm10 fields.

Behavior change

vex only. No JSON shape, flag, exit code or file format changes: vex_lock_not_read and its exit code are the ones this state already had for a package no override routes.

  • Now omitted (vex_lock_not_read), where pnpm installs the upstream release:
    • the rows marked UPSTREAM above;
    • a tree whose install record and packageManager pin name pnpm releases that read different files, with the override in only one of them;
    • "pnpm": {"overrides": "<text>"} or a non-empty array there, beside a workspace-only override.
  • Now omitted, where the files do not say which map pnpm reads:
    • a pnpm 10 whose release nothing names ("packageManager": "pnpm@10" and no install record) with the override in the workspace file alone. main attested it;
    • a package.json that cannot be read or is not JSON, beside a workspace-only override on pnpm 10.5.1 and newer. pnpm cannot install such a project either.
  • Still attested: every row marked patched above, and the trees with null or empty override tables.
  • CLI_CONTRACT.md and docs/ecosystems.md state the release rule in the paragraphs that described the old one.

Left out

Risk

A missed attestation in the "files do not say" states above, and in the window between a pin change and the next install. A wrong OverrideSource boundary would show in both lock states at once; its measurements are in version.rs.

No cfg(windows) or cfg(unix) code changed.

Verification

Local, on 85b90a8:

  • cargo clippy --locked --workspace --all-features -- -D warnings: clean.
  • Core: 8,913 unit tests passed, 0 failed.
  • Twelve CLI suites, 789 passed and 0 failed: e2e_vex_vendor, vendor_pnpm_override_e2e, e2e_vex_lockfile, vex, e2e_vex, e2e_vex_redirect, cli, in_process_vendor_pnpm_takeover, in_process_vendor_pnpm_parent_child, in_process_redirect_pnpm, hosted_memory_parity and e2e_vendor_pnpm_build.
  • Real pnpm 9.15.9, 10.4.1, 10.5.0, 10.5.1, 10.28.0 and 11.29.0 for the rows above; the reviewer also ran 10.6.0, 10.13.1, 10.20.0 and 10.34.9 for the 10.5.1-through-10.x rule.

CI on 85b90a8: 58 checks pass and one fails (73 are skipped by path). The failure is main's: install-proof (node 24.11.1), on its pnpm 11.0.0 leg (e2e_vendor_pnpm_build.rs:1263, vendor_unwired after a reinstall, with the lock on). The same job fails the same assertion on the push runs of main at 7d78f2f, 545ea83 and 6280589, and passes on #2434, the open fix for it. Nothing was re-run or changed here for it.

Cursor Bugbot reviewed 85b90a8 and found no issues.

git diff --stat: 7 files, +490 −44. Production +158 −38 (vex/discover/npm.rs, utils/pnpm_workspace.rs, formats/pnpm/version.rs, formats/pnpm/mod.rs). Tests +324 −5. Contract and docs +8 −1.


Generated by Claude Code

Refs #2403.

Assisted-by: Claude Code
@mikolalysenko Mikola Lysenko (mikolalysenko) added arch-refactor PR opened by the scheduled architecture refactor routine refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code labels Dec 2, 2026
With pnpm's lockfile setting off, vex attests a vendored package
only while the override map the governing pnpm reads routes it to
its artifact. That reader went by major and took either map for
pnpm 10. Real pnpm 10 reads one of them: package.json alone before
10.5.1, and from 10.5.1 package.json when it declares any override,
else pnpm-workspace.yaml. With the override in the other file pnpm
installs the registry release, exits 0, and vex said not_affected.

The lock-off reader now asks OverrideSource, the rule the lock-on
reader has had since #2396, for the release of the pnpm that
installed the checkout, else the packageManager pin. When neither
names a release of pnpm 10 or older, the override has to be in
package.json, where every such pnpm reads it. The detail of
vex_lock_not_read names the map that pnpm reads.

Refs #2403.

Assisted-by: Claude Code
A CLI test runs vex over a vendored pnpm project with the lock off
and the override in pnpm-workspace.yaml: attested for pnpm 10.5.1
and 10.28.0, omitted with vex_lock_not_read for 10.4.1 and 10.5.0,
and for 10.28.0 once package.json declares overrides of its own.

An install record that names no version now leaves the
packageManager pin to say which pnpm governs, as it does for the
major. When no release is named the detail says why the workspace
file was not counted.

Refs #2403.

Assisted-by: Claude Code
Review findings on the lock-off reader, each run with real pnpm.

A tree pnpm 10.28.0 installed whose packageManager pin then moves
to 10.4.1 was still attested from the workspace file: the install
record outranked the pin. pnpm switches to the pinned release at
the next install, which reads package.json alone and installs the
registry release. The reader now takes the record and the pin, and
the override has to be where each of them reads it. A pin of pnpm
11 is such a release too: it reads the workspace file alone.

"resolutions": null or [], and "pnpm": {"overrides": null}, were
read as declaring overrides, so a workspace override beside them
was no longer attested. pnpm 10.28.0 reads them as declaring none.
A table now declares when it has keys as pnpm counts them: an
object's entries, a string's characters, an array's items.

The detail names the map that has to route the package and what
each named pnpm reads. The docs sentence about package.json is
scoped to the .npmrc setting.

Refs #2403.

Assisted-by: Claude Code
A second review pass ran a packageManager of "pnpm@10" beside an
install record of 10.28.0. pnpm does not switch to such a pin
("not a valid version") and installs with the pnpm at hand, so the
workspace override is read and the artifact installs. The reader
took the pin for an unknown pnpm 10 and asked for the override in
package.json, where main attested.

Only one exact version names a release now, in the record and in
the pin. With no release of pnpm 10 or older named, the override
still has to be in package.json; the second reader the fallback
added there changed no answer and is gone. The detail says that
package.json's overrides are pnpm.overrides or resolutions.

Refs #2403.

Assisted-by: Claude Code
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review December 2, 2026 06:36
@cursor

cursor Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

PR Summary

Medium Risk
Behavior change is limited to VEX attestation logic for pnpm lock-off vendored pins; wrong boundaries could omit valid patches or briefly disagree before the next install after a pin change.

Overview
Fixes #2403: with lockfile off, vex was attesting vendored pnpm pins when the override lived only in pnpm-workspace.yaml, even though many pnpm 10 releases install from the registry and never read that map.

What changes: VEX discovery now uses the same release-aware override routing as the lock-on path (OverrideSource), instead of treating all pnpm 10 as reading either file. It considers both node_modules/.modules.yaml and package.json packageManager as governing releases (exact versions only), applies the 10.5.1 boundary (manifest alone vs workspace when manifest declares none), and treats empty vs non-empty override tables like real pnpm. Unrouted pins get vex_lock_not_read with clearer detail naming which map must route the package.

Code: governing_override_sources in version.rs, lockfile_off_override_sources replacing lockfile_off_sources, and PnpmLockOff::routes / manifest_may_declare in vex/discover/npm.rs. Contract/docs and regression tests (unit matrix + e2e_vex_vendor) follow.

Reviewed by Cursor Bugbot for commit 85b90a8. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 85b90a8. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] CI on 85b90a8: one check is red, and it is red on main too.

install-proof (node 24.11.1) fails on its pnpm 11.0.0 leg:

thread '<unnamed>' panicked at crates/socket-patch-cli/tests/e2e_vendor_pnpm_build.rs:1263:9:
assertion `left == right` failed: [pnpm@11.0.0 VendorCli] reinstalled: exit Some(1)
      "errorCode": "vendor_unwired"
Failed pnpm versions: 11.0.0

The same job fails with the same assertion on the push runs of main at 7d78f2f (this branch's base), 545ea83 and 6280589. The lock is on in that test, so it never reaches the code this PR changes. #2434 ("Keep a vendored pnpm patch when pnpm 11.0.0 to 11.0.2 rewrite its lock entry without the tarball") is the open fix, and the workflow passes on its branch. Nothing was re-run or changed here for it.

Cursor Bugbot reviewed 85b90a8 and found no issues.


Generated by Claude Code

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does
When a pnpm project has its lock turned off, vex used to accept an override from either file under any pnpm 10. It now goes by the exact pnpm release, the same way the lock-on reader does. Before 10.5.1 pnpm reads package.json only. From 10.5.1 through 10.x it reads package.json when that file declares any override, and the workspace file otherwise. pnpm 11 and later read the workspace file only. The override has to be in the file that both the recorded pnpm (node_modules/.modules.yaml) and the packageManager pin read. The vex_lock_not_read detail now says which file each of them reads.

Risk: low. Only VEX attestation changes, and almost entirely in the fail-closed direction: some rows that were attested before are now left out. Install, vendor and hosted writes are untouched. The reader list can't end up empty, which would make all() attest everything, because every lock-off result adds at least one reader.

Look here

Verified

Changes I made
None.

Open questions

  1. The .modules.yaml record counts as a governing release even when packageManager names no exact version. Take packageManager: "pnpm@10", lockfile=false, and an override only in the workspace file. A machine whose record says 10.28.0 attests the row, but a CI runner on pnpm 10.4.1 would install the registry release. So the same commit can give a different VEX on different machines. Using the record this way is not new (it already set the major before this PR), and the test row (Some("10"), "", ws, Some("10.28.0"), true) pins it deliberately. Is that acceptable, or should an inexact pin fall back to package.json only?
  2. Not blocking: whether the lock counts as off still follows the record's major first, while the readers now include the pin too. With a record of 11.x, a pin of pnpm@10.4.1 and lockfile=false in .npmrc, the project is read as lock-on. Possibly a follow-up.

Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Dec 2, 2026
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] On the review brief's two open questions, what ran. Neither is decided here.

1. "packageManager": "pnpm@10", lockfile=false, the override in the workspace file only. With the binary built from 85b90a8 and real pnpm, each machine's answer matches what its pnpm installed:

fresh clone, nothing installed:   vex exit 1; no statement
pnpm 10.4.1 install: exit 0, installs UPSTREAM, record pnpm@10.4.1
   |  WARN  Cannot switch to pnpm@10: "10" is not a valid version
   vex: vex exit 1; no statement
pnpm 10.28.0 install: exit 0, installs patched, record pnpm@10.28.0
   |  WARN  Cannot switch to pnpm@10: "10" is not a valid version
   vex: vex exit 0; "status": "not_affected"

So the VEX differs between machines because the install does: the commit names no release, and pnpm installs with whichever pnpm runs. The CI runner on 10.4.1 is not attested, before or after its install. Three rows of the unit test pin this (pnpm@10 with no record, with a 10.4.1 record and with a 10.28.0 record). Falling back to package.json for every inexact pin would omit the third tree, which main attests and where the artifact is installed. That was the second review's finding.

2. A record of pnpm 11 beside a pin of pnpm@10.4.1 and lockfile=false in .npmrc is read as lock-on. Yes, and the same on main: which file turns the lock off still follows the contract's major (the record first). This PR changes which map has to hold the override once the lock is off, not that decision.


Generated by Claude Code

@mikolalysenko
Mikola Lysenko (mikolalysenko) added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 4683249 Dec 2, 2026
131 of 132 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the arch-refactor/2403-pnpm-lock-off-override-source branch December 2, 2026 15:02
Mikola Lysenko (mikolalysenko) pushed a commit that referenced this pull request Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-refactor PR opened by the scheduled architecture refactor routine Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review refactor Structural change: duplicated code or logic, missing abstraction, layering, dead code

Projects

None yet

4 participants