Skip to content

Vendored npm: a dependency declared by dist-tag ("left-pad": "latest") is reported vendored, but npm ci installs the registry copy and vex attests not_affected #2525

Backlog

Description

[agent] Filed by the scheduled architecture refactor routine. Found by running vendored mode over projects locked by the real tools (npm 8.19.4, 9.9.4, 10.9.9 and 11.6.2) against a stand-in patch service. main at cd7c5c5.

Problem

Vendored mode wires a patched package into package-lock.json by rewriting the entry's resolved to file:.socket/vendor/npm/<uuid>/<name>-<version>.tgz. npm installs that file only when the dependent's spec accepts it. For a dependency declared by dist-tag ("left-pad": "latest", or an alias of one, "lp": "npm:left-pad@latest"), npm accepts a remote tarball and nothing else:

// @npmcli/arborist lib/dep-valid.js, the same in npm 8 to 11
case 'tag':
  // if it's a tag, we just verify that it has a tarball resolution
  // presumably, it came from the registry and was tagged at some point
  return child.resolved && npa(child.resolved).type === 'remote'

So npm ci finds the vendored entry invalid for its edge, takes the release from the registry, installs the original bytes, exits 0 and leaves the lock as it was. Nothing fails anywhere:

  • the scan says Vendored 1 package and Patched 1 package, fixing 1 vulnerability, exit 0;
  • vendor --check says committed artifact and wiring verified, before and after the install;
  • vex attests not_affected after the npm ci that installed the unpatched package. Its warning says to run the install again, which installs the same registry bytes again.

The next npm install then writes the registry resolved back into the lock.

This is the class that #326 fixed for git, URL and file: specs ("a rewrite here would report the patch applied while the original bytes install"), #753 for shrinkwrapped copies and #1965 for an edge that overrides send to a URL. The dist-tag edge is the member of that class nobody has met yet. The classifier those fixes share counts a dist-tag as a registry spec:

That answer is right for hosted mode, whose resolved is a remote URL (the control below installs the patched bytes). It is wrong for vendored mode, whose resolved is a file:.

Who meets it. A root project or a workspace member that declares a dependency by tag: "next": "latest" and "react": "latest" in starter templates, "typescript": "next", an internal package tracked by "latest". The patched release has to be the one the tag resolved to when the lock was written, which is the usual state of such a project.

Evidence on main

A project with one dependency, locked by npm 10.9.9. The stand-in patch service has a patch for left-pad 1.3.0 that appends a marker line to index.js.

$ cat package.json
{"name":"app","version":"1.0.0","dependencies":{"left-pad":"latest"}}
$ npm install && socket-patch scan --mode vendored --yes && cp package-lock.json 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/ and the updated lockfiles to make the patches portable.
  2. Run `npm 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

$ rm -rf node_modules && npm ci                                                        # what CI runs
npm warn deprecated left-pad@1.3.0: use String.prototype.padStart()
added 1 package in 223ms                                                               # exit 0
$ grep -c SOCKET_PATCHED node_modules/left-pad/index.js
0                                                                                      # the registry bytes
$ cmp package-lock.json lock.after-scan                                                # equal: npm ci left the vendored lock alone

$ 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 (the project's lockfile or package-manager config wires it in), but the live tree carries different bytes — re-run your package manager's install to resync it.
Wrote OpenVEX document with 1 statement to vex.json                                    # exit 0
$ jq -c '.statements[] | [.status, .impact_statement]' vex.json
["not_affected","Patched via Socket patch 3283a603-27e7-5603-ab2a-71360d2574bf (vendored)"]
$ socket-patch vendor --check
pkg:npm/left-pad@1.3.0: committed artifact and wiring verified                         # exit 0

$ npm install                                                                          # the printed next step
up to date in 183ms
$ diff lock.after-scan package-lock.json                                               # integrity values shortened here
<       "resolved": "file:.socket/vendor/npm/3283a603-27e7-5603-ab2a-71360d2574bf/left-pad-1.3.0.tgz",
<       "integrity": "sha512-jYVCzrAK…",
---
>       "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz",
>       "integrity": "sha512-XI5MPzVN…",

After that last install vex and vendor --check are true again (vendor_unwired; "vendored wiring drifted … that copy installs unpatched; re-run socket-patch vendor to rewire every copy", exit 1). Following that remedy writes the same lock again, which npm does not install: the scan, the install and the check go round with no state in which the package is patched.

Offline, from an empty cache, npm asks the registry for the vendored package itself. docs/usage.md says of the committed result that "a checkout can install the committed patched packages without Socket API access or a Socket Patch binary"; here it installs, but not the patched package:

$ npm ci --offline          # "left-pad": "latest", the scan's lock, empty cache
npm error code ENOTCACHED
npm error request to https://registry.npmjs.org/left-pad failed: cache mode is 'only-if-cached' but no cached response is available.
$ npm ci --offline          # "left-pad": "^1.3.0", the same scan, empty cache
added 1 package in 218ms    # exit 0, the marker is there

The matrix. "patched" is whether the installed index.js holds the marker after rm -rf node_modules and the frozen install of the scan's lock.

Declared as Tool Vendored scan Frozen install Patched
latest npm 8.19.4, 9.9.4, 10.9.9, 11.6.2 Vendored 1 package, exit 0 exit 0 no
npm:left-pad@latest (as lp) npm 10.9.9 Vendored 1 package, exit 0 exit 0 no
^1.3.0, 1.3.0 npm 10.9.9 the same exit 0 yes
the tarball's URL npm 10.9.9 refused, vendor_lock_entry_not_rewritable (#326) exit 0 no, and said so
latest, hosted mode npm 10.9.9 exit 0 exit 0 yes
latest Yarn 1.22.22, Bun 1.4.4 (text lock) Vendored 1 package, exit 0 exit 0 yes

A unit test, beside issue_1965_a_registry_edge_overridden_to_a_url_is_refused in crates/socket-patch-core/src/vendor/npm_lock.rs:

/// A dist-tag edge. npm accepts only a remote tarball for it (arborist
/// `dep-valid.js`, `case 'tag'`), so `npm ci` installs the registry copy
/// over a `file:` `resolved`.
#[tokio::test]
async fn a_dist_tag_edge_is_not_rewired() {
    for spec in ["latest", "npm:left-pad@latest"] {
        let dep = if spec.starts_with("npm:") { "lp" } else { "left-pad" };
        let lock = json!({
            "name": "fixture",
            "version": "1.0.0",
            "lockfileVersion": 3,
            "packages": {
                "": { "name": "fixture", "version": "1.0.0",
                      "dependencies": { dep: spec } },
                (format!("node_modules/{dep}")): {
                    "name": "left-pad",
                    "version": "1.3.0",
                    "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz",
                    "integrity": "sha512-orig=="
                }
            }
        });
        let fx = fixture_with("left-pad", "1.3.0", lock.clone()).await;
        expect_refused(fx.vendor(false).await, "vendor_lock_entry_not_rewritable");
        assert_eq!(fx.read_lock().await, lock, "{spec}: nothing is written");
    }
}
$ cargo test -p socket-patch-core --lib -- a_dist_tag_edge_is_not_rewired
expected Refused vendor_lock_entry_not_rewritable, got Done (success=true)
test result: FAILED.

Planned fix

Give the vendored reader of npm_non_registry_entries the rule npm applies: an entry reached through a dist-tag edge (an alias of one included) cannot be wired to a file:. It then takes the #326 path that is already there:

No JSON shape, flag or default changes. An existing refusal code gains a reason, and a scan that exits 0 over an unpatched install exits 1 with that reason.

Not part of this issue

  • pnpm has the same class through another mechanism (its name@version override is not applied to a tag, nor to a range on pnpm 7.0.0 to 8.6.11). Filed on its own.
  • A published package that declares one of its own dependencies by tag is the same edge by reading (dep-valid runs per edge). Not run.
  • Yarn berry and vlt with a tag. Not run.

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