GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fix npm store copies missed by agent apply and vex (#601, #603) by mikolalysenko · Pull Request #605 · SocketDev/socket-patch

Fix npm store copies missed by agent apply and vex (#601, #603) #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Mikola Lysenko (mikolalysenko) merged 8 commits into main from agent/fix-npm-store-copy-enumeration
Oct 5, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Fix npm store copies missed by agent apply and vex (#601, #603) #605

Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit Hold shift + click to select a range
72a4510
Start fix for #601, #603
claude Oct 2, 2026
1e73ecc
Add tests for store copies apply and vex miss
claude Oct 2, 2026
7b4ba77
Patch and verify every npm store copy
claude Oct 2, 2026
767f047
Drop the now-unused store entry filter helper
claude Oct 2, 2026
a513449
Document store copies in the vex every-copy rule
claude Oct 2, 2026
b92456b
Fix npm store traversal cycles and repeated variant scans
mikolalysenko Oct 2, 2026
912874c
Drop CHANGELOG entry from this PR
mikolalysenko Oct 5, 2026
62534c5
Merge main into agent/fix-npm-store-copy-enumeration
claude Oct 5, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Merge main into agent/fix-npm-store-copy-enumeration
Resolves conflicts with main's npm alias (#738), first-party link
(#634) and pnpm store (#698) changes:

- CLI_CONTRACT.md: keep main's hosted row and this PR's agent row.
- vex_consumed.rs: drop aliases the installed lookup already found
  (main), then store-expand only the new ones (this PR), so already
  expanded copies are not scanned again.
- Tests: keep both sides' new multicopy and e2e_vex regressions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0174mrknEY9ge42c94RNRRBx
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@claude
claude committed Oct 5, 2026
commit 62534c562724cc54e827edc0d4f5d69415a081f2

There are no files selected for viewing

2 changes: 1 addition & 1 deletion 2 crates/socket-patch-cli/CLI_CONTRACT.md
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ Recognition rules that hold for every ecosystem:
| Wiring | Evidence (verify mode) | Marker |
|---|---|---|
| Vendored: a lockfile/config wires a `.socket/vendor` artifact, or a live vendor ledger entry | The **committed artifact** is hashed against the record's `afterHash`. The ledger entry is used when it names the wired artifact (it carries the dir-artifact inventory); otherwise an entry is synthesized from the reference. A present installed tree with different bytes only warns `vendored_tree_out_of_sync`. | `(vendored)` |
| Hosted: a discovered patch-host reference (or a live pre-v5 redirect-ledger record) | The installed copies the build **consumes** through the hosted wiring are hash-verified when any exist: the Go replacement module, never the pristine `M@v` in the module cache; the Socket-registry cargo source dir; maven's suffixed version. Installed evidence wins: `hash_mismatch` / `not_applied` are omitted. With **nothing installed**, a discovered reference whose lock pins the artifact (or whose format's rewriter never writes a pin) attests from that pin, which is the same evidence as in-run `scan --mode hosted --vex`. A pre-v5 ledger-only record, or a reference whose required pin is missing, stays `package_not_found`. So do purls that `--ecosystems` kept out of the crawl, because "not installed" has to mean the crawler looked. | `(redirected)` |
| Hosted: a discovered patch-host reference (or a live pre-v5 redirect-ledger record) | The installed copies the build **consumes** through the hosted wiring are hash-verified when any exist: the Go replacement module, never the pristine `M@v` in the module cache; the Socket-registry cargo source dir; maven's suffixed version. Installed evidence wins: `hash_mismatch` / `not_applied` are omitted. With **nothing installed**, a discovered reference whose lock pins the artifact (or whose format's rewriter never writes a pin) attests from that pin, which is the same evidence as in-run `scan --mode hosted --vex`. A pre-v5 ledger-only record, or a reference whose required pin is missing, stays `package_not_found`. So do purls that `--ecosystems` kept out of the crawl, because "not installed" has to mean the crawler looked. The same goes for npm purls when an installed pnpm tree records its virtual store outside the project (`enableGlobalVirtualStore`, or a `virtualStoreDir` that climbs out): transitive deps there are invisible to the crawler. A pnpm `modulesDir` inside the project is crawled. | `(redirected)` |
| Agent: a manifest record with no live hosted/vendored wiring | The installed tree, unchanged. **Every** installed copy the crawler finds for the purl (npm nests duplicates of one `name@version`; pnpm, vlt, Bun and Deno stores add peer-variant copies and copies bundled inside other packages) must hash to the patched bytes, as `apply` patches every copy. One unpatched copy omits the purl with that copy's tag (`not_applied` / `hash_mismatch`). | none |

**Liveness gates.** These gates run before hashing, and `--no-verify` / `--vex-no-verify` skips only the hashing, never the gates:
Expand Down
9 changes: 8 additions & 1 deletion 9 crates/socket-patch-cli/src/commands/vex_consumed.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ pub(crate) async fn hosted_consumed_copies(
let npm: Vec<&String> = shared.get(&Ecosystem::Npm).into_iter().flatten().collect();
for purl in shared.values().flatten() {
let mut paths = all.remove(purl).unwrap_or_default();
let extra = aliases.remove(purl).unwrap_or_default();
// The installed-tree lookup already resolves importer-tree
// aliases, so most of the walk's finds are in `paths` already.
let extra: Vec<PathBuf> = aliases
.remove(purl)
.unwrap_or_default()
.into_iter()
.filter(|alias| !paths.contains(alias))
.collect();
if npm.contains(&purl) && installed.get(purl).is_some_and(|p| !p.is_empty()) {
// The installed lookup already expanded these copies.
// Expanding its N variants again scans the store N times.
Expand Down
93 changes: 93 additions & 0 deletions 93 crates/socket-patch-cli/tests/apply/in_process_npm_multicopy.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -477,3 +477,96 @@ fn apply_and_rollback_reach_a_bundled_copy_beside_a_normal_install() {
);
}
}

/// #626: a `node_modules/<name>` link to first-party source (an npm
/// workspace member, which a `file:` directory dependency lays out the
/// same way) that shares a patched package's `name@version` is the user's
/// own code, not an installed copy. Agent-mode apply (dry run included)
/// and rollback refuse it with a diagnostic and never overwrite the fork,
/// even though the default mismatch policy would otherwise replace it.
#[cfg(unix)]
#[test]
fn apply_and_rollback_refuse_a_node_modules_link_to_first_party_source() {
let tmp = tempfile::tempdir().unwrap();
let root = tmp.path();
let name = "dupvuln";
let original = b"module.exports = function(){ return 'VULNERABLE'; };\n";
let mut patched = original.to_vec();
patched.extend_from_slice(b"// SOCKET-PATCHED-MULTICOPY\n");
std::fs::write(
root.join("package.json"),
r#"{ "name": "ws-root", "version": "0.0.0", "private": true, "workspaces": ["packages/*"] }"#,
)
.unwrap();
let fork = b"module.exports = 'first-party fork';\n";
let fork_index = write_copy(&root.join("packages").join(name), name, "1.0.0", fork);
std::fs::create_dir_all(root.join("node_modules")).unwrap();
std::os::unix::fs::symlink(
format!("../packages/{name}"),
root.join("node_modules").join(name),
)
.unwrap();
stage_manifest_and_blob(
root,
"pkg:npm/[email protected]",
&git_sha256(original),
&git_sha256(&patched),
&patched,
);
std::fs::write(
root.join(".socket")
.join("blobs")
.join(git_sha256(original)),
original,
)
.unwrap();

let assert_refused = |code: i32, v: &serde_json::Value, stage: &str| {
assert_ne!(code, 0, "{stage}: must fail closed; envelope={v}");
assert!(
v.to_string().contains("outside every node_modules tree"),
"{stage}: the refusal must name the cause; envelope={v}"
);
assert_eq!(
std::fs::read(&fork_index).unwrap(),
fork,
"{stage}: the first-party fork was overwritten"
);
};

let out = Command::new(binary())
.args([
"apply",
"--json",
"--offline",
"--dry-run",
"--ecosystems",
"npm",
"--cwd",
])
.arg(root)
.output()
.expect("run apply --dry-run");
let stdout = String::from_utf8_lossy(&out.stdout).to_string();
let v: serde_json::Value = serde_json::from_str(stdout.trim())
.unwrap_or_else(|e| panic!("apply must emit JSON: {e}; stdout={stdout}"));
assert_refused(out.status.code().unwrap_or(-1), &v, "apply --dry-run");

let (code, v) = run_apply(root);
assert_refused(code, &v, "apply");

// A fork left patched by an apply from before the guard: rollback must
// not write the upstream original over it either.
std::fs::write(&fork_index, &patched).unwrap();
let (code, v) = run_rollback(root);
assert_ne!(code, 0, "rollback must fail closed; envelope={v}");
assert!(
v.to_string().contains("outside every node_modules tree"),
"rollback: envelope={v}"
);
assert_eq!(
std::fs::read(&fork_index).unwrap(),
patched,
"rollback wrote through the link"
);
}
84 changes: 84 additions & 0 deletions 84 crates/socket-patch-cli/tests/e2e_vex.rs
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1113,6 +1113,90 @@ fn verify_mode_requires_every_store_copy_patched() {
}
}

/// Regression (#356): an npm alias install (`node_modules/lp` holding the
/// real `[email protected]`) is an installed copy of `pkg:npm/[email protected]`.
/// `vex` used to verify only `node_modules/dup-pkg`, so it attested the
/// purl while the alias copy that `require('lp')` loads was unpatched.
#[test]
fn verify_mode_requires_npm_alias_copies_patched() {
let patched: &[u8] = b"patched dup index";
let pristine: &[u8] = b"pristine dup index";
let after_hash = compute_git_sha256_from_bytes(patched);
let before_hash = compute_git_sha256_from_bytes(pristine);

let run = |copies: &[(&str, &[u8])]| {
let tmp = tempfile::tempdir().unwrap();
let cwd = tmp.path();
for (dir, content) in copies {
let copy = cwd.join("node_modules").join(dir);
std::fs::create_dir_all(&copy).unwrap();
std::fs::write(
copy.join("package.json"),
r#"{"name":"dup-pkg","version":"1.0.0"}"#,
)
.unwrap();
std::fs::write(copy.join("index.js"), content).unwrap();
}
let mut manifest = PatchManifest::new();
manifest.patches.insert(
"pkg:npm/[email protected]".to_string(),
make_record(
"44444444-4444-4444-8444-444444444444",
"package/index.js",
before_hash.as_str(),
after_hash.as_str(),
"GHSA-dup",
&["CVE-DUP"],
),
);
write_manifest(cwd, &manifest);
let out = cli()
.args([
"vex",
"--cwd",
cwd.to_str().unwrap(),
"--product",
"pkg:npm/[email protected]",
])
.output()
.expect("invoke vex");
(
out.status.success(),
String::from_utf8_lossy(&out.stdout).into_owned(),
String::from_utf8_lossy(&out.stderr).into_owned(),
)
};

// The plain copy is patched, an alias copy (plain or scoped) is not.
for alias in ["lp", "@x/dp"] {
let (ok, stdout, stderr) = run(&[("dup-pkg", patched), (alias, pristine)]);
assert!(
!ok && !stdout.contains("GHSA-dup"),
"an unpatched alias copy ({alias}) must keep the purl out of the \
VEX doc.\nstdout:\n{stdout}\nstderr:\n{stderr}"
);
assert!(
stderr.contains("Warning: omitting pkg:npm/[email protected] from VEX")
&& stderr.contains("(not_applied)"),
"the omission must name the unpatched alias copy. got: {stderr}"
);
}

// Control: alias-only and plain + alias, every copy patched → attested.
for copies in [
vec![("lp", patched)],
vec![("dup-pkg", patched), ("lp", patched)],
] {
let (ok, stdout, stderr) = run(&copies);
assert!(ok, "all copies patched must attest. stderr:\n{stderr}");
let doc: Value = serde_json::from_str(&stdout).unwrap();
let stmts = doc["statements"].as_array().unwrap();
assert_eq!(stmts.len(), 1, "doc:\n{stdout}");
assert_eq!(stmts[0]["vulnerability"]["name"], "GHSA-dup");
assert_eq!(stmts[0]["status"], "not_affected");
}
}

#[test]
fn verify_mode_all_failed_exits_non_zero() {
let tmp = tempfile::tempdir().unwrap();
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

You are viewing a condensed version of this merge commit. You can view the full changes here.
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.