Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pnpm-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ jobs:
- node: '16.20.2'
pnpm: 4.0.0 4.14.4 5.0.0 5.18.11 6.0.0 6.35.1 7.0.0 7.33.7 8.0.0 8.15.9
- node: '24.11.1'
pnpm: 9.0.0 9.15.9 10.0.0 10.33.0 10.34.5 11.0.0 11.27.0 12.0.0 12.4.2
pnpm: 9.0.0 9.15.9 10.0.0 10.33.0 10.34.5 11.0.0 11.0.3 11.27.0 11.29.0 12.0.0 12.4.2 12.25.1
steps:
- uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 # v7.0.0
with:
Expand Down
6 changes: 5 additions & 1 deletion crates/socket-patch-cli/CLI_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -3520,7 +3520,11 @@ entry; re-vendoring cannot reach it, #1511), or, for npm and PyPI, a dependency
resolves any more (`dependency removed`; `scan --mode vendored --prune` reverts
the entry), or, for PyPI, a project file that still names the artifact while
nothing installs from it (`wiring incomplete`, naming the file; re-lock, then
re-vendor or revert, #1374). For a package-lock entry, drift also includes a
re-vendor or revert, #1374), or a `pnpm-lock.yaml` that still names the
artifact in an entry pnpm does not install from (`wiring incomplete`, naming
the lock: pnpm 11.0.0 to 11.0.2 rewrite the entry of a `file:` tarball
without its `tarball`, and a frozen install of that lock fails; re-run
`scan --mode vendored` or `vendor`). For a package-lock entry, drift also includes a
`package-lock.json` / `npm-shrinkwrap.json` entry for the vendored `name@version`
that `vendor` would rewire but that does not resolve to the vendored artifact
(#588); the reason names that entry. It also includes any entry for that
Expand Down
11 changes: 11 additions & 0 deletions crates/socket-patch-cli/src/commands/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,11 @@ pub(crate) async fn dispatch_revert_one_opts(
/// * a pnpm lock wires the artifact through an override the project's
/// settings do not declare, so pnpm does not install that lock (#2382):
/// the extractor's own diagnostic, which names the file and the remedy;
/// * a pnpm lock still names the artifact in an entry that records no
/// tarball (pnpm 11.0.0 to 11.0.2 rewrite the entry of a `file:` tarball
/// so): the extractor's own diagnostic again, since "no lockfile
/// references it, a fresh install gets the unpatched package" would be
/// false twice over;
/// * otherwise a relock dropped the reference while the package stayed.
async fn unwired_check_failure(
discovery: &socket_patch_core::vex::discover::Discovery,
Expand Down Expand Up @@ -650,6 +655,12 @@ async fn unwired_check_failure(
if let Some(diag) = discovery.pnpm_override_undeclared(&entry.uuid) {
return format!("wiring incomplete: {}", diag.detail);
}
// A pnpm lock still names the artifact in an entry that records no
// tarball (pnpm 11.0.0 to 11.0.2 rewrite it so): the lock is not gone,
// and an install of it fails instead of getting the unpatched package.
if let Some(diag) = discovery.pnpm_tarball_dropped(&entry.uuid) {
return format!("wiring incomplete: {}", diag.detail);
}
// Only the npm-family and Python extractors record every lock entry
// (`resolved_elsewhere`), so only there does "no lock resolves it"
// prove the dependency is gone rather than unreadable.
Expand Down
88 changes: 81 additions & 7 deletions crates/socket-patch-cli/tests/e2e_vendor_pnpm_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ fn keeps_relative_file_overrides(pm: &str) -> bool {
matches!(parts.as_slice(), [7, minor, _] if *minor <= 17)
}

/// pnpm 11.0.0-11.0.2 write the lock entry of a `file:` tarball without its
/// `tarball` when they resolve it themselves (measured 2026-12-01: 11.0.2
/// drops it, 11.0.3 keeps it, as do 9.0.0-10.34.9 and 12.0.0 on). The lock
/// then names the artifact in its key, importer and override, but a frozen
/// install of it from an empty store asks the registry for the release and
/// fails on the vendored integrity (`ERR_PNPM_TARBALL_INTEGRITY`).
fn drops_file_tarball_on_relock(pm: &str) -> bool {
let Some(v) = pm.strip_prefix("pnpm@") else {
return false;
};
let parts: Vec<u32> = v.split('.').filter_map(|p| p.parse().ok()).collect();
matches!(parts.as_slice(), [11, 0, patch] if *patch <= 2)
}

/// pnpm 9.0.0-9.0.4: the last releases that absolutize a `file:` override's
/// importer specifier (measured 2026-09-22: 9.0.4 refuses the relative
/// spelling under `--frozen-lockfile`, 9.0.5 accepts it).
Expand Down Expand Up @@ -1258,13 +1272,73 @@ fn assert_manifestless_vendored_vex(
patched,
"[{tag}] a plain install must re-apply the overrides (vendored bytes)"
);
// The lock pnpm just rewrote wires the artifact again.
let out = run_vex(&bin, fresh, &VexRun::online(&api));
assert_eq!(out.code, Some(0), "[{tag}] reinstalled: {out}");
assert_attested(out.doc(), purl, UUID, Marker::Vendored, VENDOR_VULNS);
eprintln!(
"VEX-CELL vendored [{tag}] lock-only-revert(overrides kept): attested once reinstalled"
);
let relocked = std::fs::read_to_string(&lock).unwrap();
if drops_file_tarball_on_relock(pm) {
// This pnpm wrote the entry without its tarball. The installed
// tree holds the vendored bytes, but the lock no longer says
// where the package comes from: a frozen install of it from an
// empty store fails (offline it has no tarball to take, online
// the registry's fails the vendored integrity). So the lock
// wires nothing an install is sure to consume, and nothing is
// attested until the entry is written again.
assert!(
!relocked.contains("tarball: file:"),
"[{tag}] this pnpm is listed as dropping the tarball when it writes the lock:\n\
{relocked}"
);
// With the patched tree still installed, and without it.
let not_attested = |state: &str| {
let out = run_vex(&bin, fresh, &VexRun::online(&api));
assert_ne!(out.code, Some(0), "[{tag}] relocked, {state}: {out}");
assert_absent(out.doc.as_ref(), purl);
assert_not_attested(&out.envelope, purl, "vendor_unwired");
};
not_attested("the patched tree installed");
let empty = fresh.with_file_name("store-relocked");
std::fs::remove_dir_all(fresh.join("node_modules")).unwrap();
let frozen = corepack(
fresh,
pm,
&[
"install",
"--frozen-lockfile",
"--offline",
"--store-dir",
empty.to_str().unwrap(),
],
);
let said = format!(
"{}{}",
String::from_utf8_lossy(&frozen.stdout),
String::from_utf8_lossy(&frozen.stderr)
);
// Offline pnpm has no tarball to take; online it is the
// registry's, which fails the vendored integrity.
assert!(
!frozen.status.success() && said.contains("TARBALL"),
"[{tag}] a frozen install of the lock pnpm rewrote must fail for want of the \
tarball, from an empty store: {said}"
);
not_attested("no tree installed");
eprintln!(
"VEX-CELL vendored [{tag}] lock-only-revert(overrides kept): not attested, pnpm \
rewrote the lock without the tarball"
);
} else {
// The lock pnpm just rewrote wires the artifact again (pnpm
// 9 and later write the tarball beside the integrity).
assert!(
pnpm_major(pm).is_none_or(|major| major < 9) || relocked.contains("tarball: file:"),
"[{tag}] the lock pnpm rewrote must record the tarball:\n{relocked}"
);
let out = run_vex(&bin, fresh, &VexRun::online(&api));
assert_eq!(out.code, Some(0), "[{tag}] reinstalled: {out}");
assert_attested(out.doc(), purl, UUID, Marker::Vendored, VENDOR_VULNS);
eprintln!(
"VEX-CELL vendored [{tag}] lock-only-revert(overrides kept): attested once \
reinstalled"
);
}
std::fs::write(&lock, &lock_wired).unwrap();
});
eprintln!("MANIFEST-LESS VENDORED VEX OK ({tag})");
Expand Down
111 changes: 111 additions & 0 deletions crates/socket-patch-cli/tests/e2e_vex_vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3181,6 +3181,117 @@ fn vendored_pnpm_pin_with_the_lock_off_needs_its_override() {
assert_vendored_attested(cwd, purl, "the override routes it without a lock");
}

/// pnpm 11.0.0 to 11.0.2 write the lock entry of a `file:` tarball without
/// its `tarball` when they rewrite the lock (measured 2026-12-01 against
/// real pnpm: 11.0.2 drops it, 11.0.3 keeps it). The lock still names the
/// artifact in its key, its importer and its override, but a frozen install
/// of it from an empty store asks the registry for the release and fails on
/// the vendored integrity. So the lock wires nothing an install is sure to
/// consume: `vex` does not attest the patch, and `vendor --check` fails the
/// entry, naming the lock that still names the artifact instead of saying
/// that no lockfile does. The same lock with the tarball attests and
/// verifies (the control).
#[test]
fn pnpm_lock_entry_rewritten_without_its_tarball_is_not_attested() {
let tmp = tempfile::tempdir().unwrap();
let cwd = tmp.path();
let uuid = "55555555-5555-4555-8555-555555555555";
let purl = "pkg:npm/foo@1.0.0";
let rel = write_foo_ledger(
cwd,
uuid,
b"patched foo\n",
&[("package.json", "override"), ("pnpm-lock.yaml", "lock")],
);
std::fs::write(
cwd.join("package.json"),
format!(
r#"{{"name":"app","version":"0.1.0","dependencies":{{"foo":"1.0.0"}},"pnpm":{{"overrides":{{"foo@1.0.0":"file:{rel}"}}}}}}"#
),
)
.unwrap();
std::fs::write(
cwd.join("pnpm-workspace.yaml"),
format!("packages:\n - '.'\noverrides:\n foo@1.0.0: file:{rel}\n"),
)
.unwrap();
// The lock as pnpm writes it for the override, with and without the
// tarball of the entry.
let lock = |tarball: &str| {
format!(
"lockfileVersion: '9.0'\n\nsettings:\n autoInstallPeers: true\n \
excludeLinksFromLockfile: false\n\noverrides:\n foo@1.0.0: file:{rel}\n\n\
importers:\n\n .:\n dependencies:\n foo:\n \
specifier: file:{rel}\n version: file:{rel}\n\npackages:\n\n \
foo@file:{rel}:\n \
resolution: {{integrity: sha512-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=={tarball}}}\n \
version: 1.0.0\n\nsnapshots:\n\n foo@file:{rel}: {{}}\n"
)
};
let check = || {
let out = cli()
.args(["vendor", "--check", "--cwd", cwd.to_str().unwrap()])
.output()
.expect("invoke vendor --check");
let said = format!(
"{}{}",
String::from_utf8_lossy(&out.stdout),
String::from_utf8_lossy(&out.stderr)
);
(out.status.code(), said)
};

std::fs::write(
cwd.join("pnpm-lock.yaml"),
lock(&format!(", tarball: file:{rel}")),
)
.unwrap();
assert_vendored_attested(cwd, purl, "the entry records its tarball");
let (code, said) = check();
assert_eq!(code, Some(0), "the wiring is intact: {said}");

std::fs::write(cwd.join("pnpm-lock.yaml"), lock("")).unwrap();
assert_never_attested(cwd, purl);
let (code, said) = check();
assert_eq!(code, Some(1), "{said}");
for part in [
"wiring incomplete: pnpm-lock.yaml: packages entry",
uuid,
"records no tarball for it",
"pnpm 11.0.3 and later keep the tarball",
"ERR_PNPM_TARBALL_INTEGRITY",
"socket-patch scan --mode vendored",
] {
assert!(said.contains(part), "{part:?} is missing: {said}");
}
assert!(
!said.contains("wiring missing") && !said.contains("gets the unpatched package"),
"{said}"
);

// A lock that pnpm resolved from the registry again and that keeps only
// the override line is another state: no pnpm release is to blame, and
// the message must not name one.
std::fs::write(
cwd.join("pnpm-lock.yaml"),
format!(
"lockfileVersion: '9.0'\n\nsettings:\n autoInstallPeers: true\n \
excludeLinksFromLockfile: false\n\noverrides:\n foo@1.0.0: file:{rel}\n\n\
importers:\n\n .:\n dependencies:\n foo:\n specifier: 1.0.0\n \
version: 1.0.0\n\npackages:\n\n foo@1.0.0:\n \
resolution: {{integrity: sha512-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==}}\n\n\
snapshots:\n\n foo@1.0.0: {{}}\n"
),
)
.unwrap();
let (code, said) = check();
assert_eq!(code, Some(1), "{said}");
assert!(
!said.contains("11.0."),
"no pnpm release caused this: {said}"
);
}

/// REVIEW (#1033, audit B04): a pnpm lock that also holds a package with
/// `bundledDependencies` naming the vendored package (or `true`, bundling
/// every dependency) ships a copy pnpm unpacks from that package's own
Expand Down
18 changes: 18 additions & 0 deletions crates/socket-patch-core/src/vex/discover/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,24 @@ impl Discovery {
})
}

/// The diagnostic of a vendored pnpm lock entry of patch `uuid` that
/// was withheld because it records no tarball
/// (`npm::PNPM_TARBALL_DROPPED`: pnpm 11.0.0 to 11.0.2 write it so):
/// it names the lock, what an install of it does, and the remedy.
pub fn pnpm_tarball_dropped(&self, uuid: &str) -> Option<&Diag> {
self.withheld
.iter()
.filter(|w| w.uuid == uuid && w.mode == WiringMode::Vendored)
.find_map(|w| {
self.diagnostics.iter().find(|d| {
d.code == DIAG_REF_INVALID
&& d.file == w.file
&& d.detail.contains(npm::PNPM_TARBALL_DROPPED)
&& d.detail.contains(uuid)
})
})
}

/// Whether any lock discovery read resolves `purl` (any spelling) at
/// all: wired to a Socket patch, contested, or from elsewhere
/// ([`Discovery::resolved_elsewhere`]).
Expand Down
Loading
Loading