Skip to content

Vendored pnpm writes a name@version override that pnpm does not apply to a dependency declared by dist-tag (every pnpm), or by a range (pnpm 7.0.0 to 8.6.11): the scan reports success, a frozen install fails, and pnpm install puts the registry copy back #2526

Backlog

Description

[agent] Filed by the scheduled architecture refactor routine. Found by running vendored mode over projects locked by the real tools (pnpm 7.33.7, 8.5.1, 8.6.12, 8.15.9, 9.15.9 and 10.28.0) against a stand-in patch service. main at cd7c5c5.

Problem

Vendored pnpm wires a patched package with an override keyed name@version (pnpm.overrides in package.json, and pnpm-workspace.yaml beside a 9.0 lock) and rewrites pnpm-lock.yaml as if pnpm had applied it: the importer's specifier and version, the packages entry and every reference. Whether pnpm applies that override depends on how the dependent declares the package, and the backends never look:

pnpm Its rule (read in the bundles of 7.0.0, 7.33.7, 8.0.0, 8.5.1, 8.6.0, 8.6.3, 8.6.6, 8.6.9 to 8.6.12, 8.7.0, 8.15.9, 9.15.9 and 10.28.0) Applies left-pad@1.3.0 to a dependency declared as
7.0.0 to 8.6.11 isSubRange: semver.subset(declared, "1.3.0") 1.3.0 only
8.6.12 and newer isIntersectingRange: semver.intersects(declared, "1.3.0") any range that admits 1.3.0; never a dist-tag (latest), which is no range

When pnpm does not apply the override, the lock socket-patch wrote names a file: specifier for a dependency that package.json declares otherwise, and:

  • the scan says Vendored 1 package and Patched 1 package, fixing 1 vulnerability, exit 0, and vendor --check says committed artifact and wiring verified;
  • CI breaks: pnpm install --frozen-lockfile (pnpm's default under CI) fails with ERR_PNPM_OUTDATED_LOCKFILE;
  • the printed next step, pnpm install, exits 0, takes the package from the registry and rewrites the lock to the registry entry. The package is unpatched and nothing says so;
  • vendor --check then says "wiring missing … re-run socket-patch vendor to rewire it". Doing that writes the same lock again. There is no state in which the package is patched;
  • on a 5.4 or 6.0 lock the warning vendor_pnpm_legacy_absolute_specifier says a frozen install "only passes in a checkout at exactly" the project's path. It does not pass there either.

Who meets it:

  • pnpm 7.0.0 to 8.6.11, any range. pnpm add writes a caret range, so this is every direct dependency nobody pinned by hand.
  • Every pnpm, a dist-tag ("next": "latest", "typescript": "next"): measured on 7.33.7, 8.15.9, 9.15.9 and 10.28.0, the Supported tier included.

The same rule one level down, on pnpm 7.0.0 to 8.6.11. A dependent's declared range for a transitive package is not in the lock, so the scan and both installs hold. The next command that resolves again drops the patched copy for the registry one, exit 0: pnpm add <anything>, pnpm update, pnpm install --fix-lockfile. vendor --check and vex then report it truthfully.

The rule is already in the codebase, for the hosted registry route (#2167): [override_applies, formats/pnpm/version.rs lines 564 to 590](https://github.com/SocketDev/socket-patch/blob/cd7c5c56e3e0049a5c06260c354a597b8f07658b/crates/socket-patch-core/src/formats/pnpm/version.rs#L564-L590), which registry_alias.rs uses to refuse a pin it "locks … through the specifier …, which pnpm would not override". It knows the intersecting rule only. The vendored backends rewrite the specifier whatever it is:

  • [edit_importers, vendor/pnpm_lock.rs lines 2781 to 2828](https://github.com/SocketDev/socket-patch/blob/cd7c5c56e3e0049a5c06260c354a597b8f07658b/crates/socket-patch-core/src/vendor/pnpm_lock.rs#L2781-L2828);
  • [edit_specifier_v54 and edit_root_deps_v60, vendor/pnpm_lock_legacy.rs lines 516 to 607](https://github.com/SocketDev/socket-patch/blob/cd7c5c56e3e0049a5c06260c354a597b8f07658b/crates/socket-patch-core/src/vendor/pnpm_lock_legacy.rs#L516-L607): "whatever range the user wrote moves to the machine-absolute file: spelling pnpm itself records".

#754 and #956 fixed the same symptom in this backend (a frozen install that fails after a scan that reports success) for two spellings. The captured fixtures and the real-pnpm legs declare the patched dependency as an exact version ("dependencies": { dep: version }), so the pinned matrix passes on pnpm 7.0.0, 7.33.7 and 8.0.0.

Evidence on main

The stand-in patch service has a patch for left-pad 1.3.0 that appends a marker line to index.js.

pnpm 10.28.0, a dist-tag (9.15.9 is the same):

$ cat package.json
{"name":"app","version":"1.0.0","dependencies":{"left-pad":"latest"}}
$ pnpm install && socket-patch scan --mode vendored --yes && cp pnpm-lock.yaml lock.after-scan
Found 1 package (1 npm)
Vendored 1 package.
  HIGH  left-pad@1.3.0  CVE-2024-10000
Next steps:
  1. Commit .socket/vendor/, package.json, pnpm-lock.yaml, and pnpm-workspace.yaml to make the patches portable (pnpm >=11 reads the vendored override only from pnpm-workspace.yaml).
  2. Run `pnpm install` to update the installed tree, then run `socket-patch vex` to verify the installed patches.
Patched 1 package, fixing 1 vulnerability (1 high).                                    # exit 0
$ socket-patch vendor --check
pkg:npm/left-pad@1.3.0: committed artifact and wiring verified                         # exit 0
$ socket-patch vex --output vex.json
Warning: pkg:npm/left-pad@1.3.0: the installed tree does not match its vendored artifact; the attestation is based on the committed .socket/vendor artifact (…) — re-run your package manager's install to resync it.
Wrote OpenVEX document with 1 statement to vex.json                                    # exit 0, not_affected

$ rm -rf node_modules && pnpm install --frozen-lockfile                                # what CI runs
 ERR_PNPM_OUTDATED_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is not up to date with <ROOT>/package.json
  Failure reason:
  specifiers in the lockfile don't match specifiers in package.json:
* 1 dependencies are mismatched:
  - left-pad (lockfile: file:.socket/vendor/npm/3283a603-27e7-5603-ab2a-71360d2574bf/left-pad-1.3.0.tgz, manifest: latest)      # exit 1

$ pnpm install                                                                         # the printed next step
 WARN  deprecated left-pad@1.3.0: use String.prototype.padStart()
+ left-pad 1.3.0 deprecated                                                            # exit 0
$ grep -c SOCKET_PATCHED node_modules/left-pad/index.js
0
$ diff lock.after-scan pnpm-lock.yaml                                                  # integrity values left out here
<         specifier: file:.socket/vendor/npm/3283a603-27e7-5603-ab2a-71360d2574bf/left-pad-1.3.0.tgz
<         version: file:.socket/vendor/npm/3283a603-27e7-5603-ab2a-71360d2574bf/left-pad-1.3.0.tgz
>         specifier: latest
>         version: 1.3.0
<   left-pad@file:.socket/vendor/npm/3283a603-27e7-5603-ab2a-71360d2574bf/left-pad-1.3.0.tgz:
>   left-pad@1.3.0:

$ socket-patch vex --output vex.json
Warning: omitting pkg:npm/left-pad@1.3.0 from VEX: … (vendor_unwired)
Error: No applied patches with vulnerability metadata to attest.                       # exit 1, true
$ socket-patch vendor --check
pkg:npm/left-pad@1.3.0: wiring missing: no lockfile or config references .socket/vendor/npm/3283a603-27e7-5603-ab2a-71360d2574bf any more, so a fresh install gets the unpatched package; re-run `socket-patch vendor` to rewire it      # exit 1
$ socket-patch scan --mode vendored --yes
  [skip] pkg:npm/left-pad@1.3.0 (already vendored)
Vendored 1 package.                                                                    # exit 0
$ cmp lock.after-scan pnpm-lock.yaml                                                   # equal: the lock pnpm rejects, again

pnpm 7.33.7, the range pnpm add writes ("left-pad": "^1.3.0", lock 5.4). The same seven steps give the same results; the frozen install:

$ rm -rf node_modules && pnpm install --frozen-lockfile
Lockfile is up to date, resolution step is skipped
 ERR_PNPM_OUTDATED_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is not up to date with package.json      # exit 1

The matrix. Each cell: scan --mode vendored --yes, then rm -rf node_modules, the frozen install, a plain install, and whether the installed file holds the marker. Every scan said Vendored 1 package and exited 0.

pnpm (lock) 1.3.0 ^1.3.0 latest
7.33.7 (5.4) patched frozen fails; plain install unpatches (~2.0.0 on ms too) the same
8.5.1 (6.0) patched the same not run
8.6.12 (6.0) patched patched not run
8.15.9 (6.0) patched patched frozen fails; plain install unpatches
9.15.9 (9.0) not run patched the same
10.28.0 (9.0) not run patched the same

Hosted mode on the 7.33.7 and 8.5.1 projects (1.3.0, ^1.3.0 and the transitive one) installs the patched bytes frozen and plain, and its undo is byte for byte: it writes no override.

One level down. chalk 2.4.2 declares escape-string-regexp as ^1.0.5; the patch is for escape-string-regexp 1.0.5. After the vendored scan and an install that holds the patched copy:

pnpm pnpm add is-number@7.0.0 The patched copy
7.33.7 exit 0 gone: the lock is back on /escape-string-regexp/1.0.5 (also after pnpm update and pnpm install --fix-lockfile)
8.5.1 exit 0 gone
8.6.12, 8.15.9 exit 0 kept
7.33.7, a dependent that declares the exact version (debug 2.6.9, ms 2.0.0) exit 0 kept

The suite's own real-pnpm leg, one line changed. pnpm7_real_lifecycle_same_path_frozen_and_moved_checkout_offline in crates/socket-patch-cli/tests/e2e_vendor_pnpm_build.rs passes on main with SOCKET_PATCH_PNPM_E2E_BIN set to pnpm 7.33.7. With line 2370 changed to declare the range:

-        "dependencies": { dep: version },
+        "dependencies": { dep: format!("^{version}") },
$ SOCKET_PATCH_PNPM_E2E_BIN=<pnpm 7.33.7> cargo test -p socket-patch-cli --test e2e_vendor_pnpm_build pnpm7_real_lifecycle_same_path
same-path `install --frozen-lockfile --offline` must succeed from the vendored tarball (pnpm@7.33.5).
 ERR_PNPM_OUTDATED_LOCKFILE  Cannot install with "frozen-lockfile" because pnpm-lock.yaml is not up to date with package.json
test result: FAILED. 0 passed; 1 failed

The pnpm8_real_… twin with the same line fails the same way under pnpm 8.5.1 and passes under 8.15.9.

Unit tests, in the tests modules of vendor/pnpm_lock_legacy.rs and vendor/pnpm_lock.rs:

/// pnpm 7.0.0 to 8.6.11 apply a `name@version` override only to a
/// dependency declared as a subset of that version, and no pnpm applies
/// one to a dist-tag.
#[tokio::test]
async fn a_specifier_pnpm_would_not_override_is_refused() {
    // v5.4 (always pnpm 7): a caret range, what `pnpm add` writes.
    let pkg = T_BEFORE_PKG.replace(r#""left-pad": "1.3.0""#, r#""left-pad": "^1.3.0""#);
    let lock = T7_BEFORE_LOCK.replace(
        "  left-pad: 1.3.0\n  left-pad-old: npm",
        "  left-pad: ^1.3.0\n  left-pad-old: npm",
    );
    assert_ne!(lock, T7_BEFORE_LOCK);
    let fx = fixture_with(&pkg, &lock).await;
    expect_refused(fx.vendor(false).await, "vendor_lock_entry_unsupported");
    assert_eq!(fx.read(PNPM_LOCK).await, lock, "refusal writes nothing");

    // v6.0 (any pnpm 8): a dist-tag.
    let pkg = T_BEFORE_PKG.replace(r#""left-pad": "1.3.0""#, r#""left-pad": "latest""#);
    let lock = T8_BEFORE_LOCK.replace(
        "  left-pad:\n    specifier: 1.3.0",
        "  left-pad:\n    specifier: latest",
    );
    assert_ne!(lock, T8_BEFORE_LOCK);
    let fx = fixture_with(&pkg, &lock).await;
    expect_refused(fx.vendor(false).await, "vendor_lock_entry_unsupported");
    assert_eq!(fx.read(PNPM_LOCK).await, lock, "refusal writes nothing");
}
/// No pnpm applies a `name@version` override to a dependency declared
/// by dist-tag (it intersects the two as semver ranges).
#[tokio::test]
async fn a_dist_tag_specifier_is_refused() {
    let pkg = P1_BEFORE_PKG.replace(r#""left-pad": "1.3.0""#, r#""left-pad": "latest""#);
    let lock = P1_BEFORE_LOCK.replace(
        "      left-pad:\n        specifier: 1.3.0",
        "      left-pad:\n        specifier: latest",
    );
    assert_ne!(lock, P1_BEFORE_LOCK);
    let fx = fixture_with(&pkg, &lock).await;
    expect_refused(fx.vendor(false).await, "vendor_lock_entry_unsupported");
    assert_eq!(fx.read(PNPM_LOCK).await, lock, "refusal writes nothing");
}
$ cargo test -p socket-patch-core --lib -- a_specifier_pnpm_would_not_override_is_refused a_dist_tag_specifier_is_refused
expected Refused vendor_lock_entry_unsupported, got Done (success=true)
expected Refused vendor_lock_entry_unsupported, got Done (success=true)
test result: FAILED. 0 passed; 2 failed

Planned fix

Refuse before anything is written when pnpm would not apply the override to an importer's specifier for the release, in the preflight both dialects share:

  • Every lock: ask override_applies for each importer (or root) entry that locks the release. A dist-tag, or any specifier it answers Some(false) for, refuses with the existing vendor_lock_entry_unsupported. The message names the specifier and the ways out: declare a version or a range, or use hosted mode.
  • A 5.4 lock (always pnpm 7), and a 6.0 lock whose pnpm is 8.0.0 to 8.6.11 by the install record or the pins formats/pnpm/version.rs already reads: the subset rule, so a specifier that is not the exact version refuses, with pinning the version or pnpm 8.6.12 and newer as further ways out. A 6.0 lock with no evidence of its pnpm is wired as today.
  • The real-pnpm legs gain a range and a tag, so the matrix sees what a project declares.

No lock or project file is written differently for a project that works today. A scan that exits 0 over a lock pnpm rejects exits 1 with the reason.

For a maintainer, if such projects should be patched instead of refused. Measured by hand on pnpm 7.33.7:

  • an override keyed by the declared specifier ("left-pad@^1.3.0": "file:…") is applied, and pnpm writes the very lock socket-patch writes but for that key; the frozen install passes;
  • an override keyed by the dependent ("chalk@2.4.2>escape-string-regexp": "file:…") is applied whatever range chalk declares, and survives pnpm add.

Either changes what is written to package.json and the lock, and what the undo and the checks key on, so it is not planned here.

Not part of this issue


Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Dec 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-auditbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions