Skip to content

npm 12 never reads npm-shrinkwrap.json, so on a shrinkwrap-only project hosted and vendored scans rewrite a lock npm 12 ignores: scan succeeds with no warning, lockfile-only VEX attests not_affected, and npm install installs the unpatched package #899

Closed

Description

[agent] Found by the scheduled npm bug-hunt routine (ledger #302).

Summary

npm 12 no longer reads a root npm-shrinkwrap.json. Its own docs (docs/content/configuring-npm/package-lock-json.md in npm 12.2.0) say: "As of npm v12, npm-shrinkwrap.json is no longer read or written by npm. Projects that previously committed npm-shrinkwrap.json should rename it to package-lock.json." On a project whose only lock is npm-shrinkwrap.json, npm install on npm 12.0.0, 12.1.0 and 12.2.0 ignores the shrinkwrap's pins, resolves the tree fresh from the registry and writes a new package-lock.json. npm ci refuses with EUSAGE.

socket-patch assumes otherwise. docs/ecosystems.md:42 says "npm 12 installs from the package-lock.json twin it keeps beside a committed shrinkwrap", and docs/testing/npm-compatibility.md:49 says "npm install copies it to package-lock.json and installs from the copy". On a shrinkwrap-only project:

  • scan (hosted or --mode vendored) rewrites only npm-shrinkwrap.json and exits 0 with no warning about it. Hosted also writes allow-remote=all to .npmrc and warns redirect_npm_allow_remote "for npm >= 12", although npm 12 will never read the rewritten lock.
  • A lockfile-only vex on a fresh checkout attests not_affected.
  • npm 12 npm install then installs the unpatched registry bytes.

After that install, vex correctly refuses, because the new package-lock.json twin contests the pin (the #799 rule). The gap is the scan result and the VEX attestation before any npm 12 install.

Impact

Repro (Linux, main 9c43dfc; Node 22.22 for npm 8 / 10, Node 24.21 for npm 12)

A local mock patch API serves a free patch for pkg:npm/left-pad@1.3.0 (granted tarball for hosted and vendored).

mkdir app && cd app
echo '{"name":"app","version":"1.0.0","dependencies":{"left-pad":"1.3.0"}}' > package.json
npm@10 install && npm@10 shrinkwrap          # only npm-shrinkwrap.json (lockfileVersion 3)
git init -q && echo node_modules > .gitignore && git add -A && git commit -qm init
socket-patch scan --json --yes --api-url $MOCK --org o --api-token x --patch-server-url $MOCK
#   exit 0, success, redirected 1, warnings [redirect_npm_allow_remote]   (or --mode vendored: success, no warning)

# fresh checkout: package.json, npm-shrinkwrap.json, .npmrc (and .socket/ for vendored)
socket-patch vex -O v.json --product pkg:npm/app@1.0.0 ...   # exit 0, 1 statement, not_affected
npm@12 ci        # exit 1, EUSAGE (needs package-lock.json)
npm@12 install   # exit 0; node_modules/left-pad/index.js is the UPSTREAM file; new package-lock.json resolves registry.npmjs.org
socket-patch vex ...   # now refuses: "npm-shrinkwrap.json … wired … but package-lock.json resolves it elsewhere"
npm@10 install   # control on the same checkout: patched

To show npm 12 ignores the shrinkwrap without socket-patch: with package.json "left-pad":"^1.2.0" and a shrinkwrap pinning 1.2.0, npm 12.0.0 / 12.1.0 / 12.2.0 npm install installs 1.3.0.

Expected vs actual

  • Expected: the docs' own model of npm 12. Either socket-patch makes npm 12 install the patch (for example by also writing the package-lock.json twin npm tells users to create), or it says clearly that npm ≥ 12 ignores the shrinkwrap, through a scan warning plus a lockfile-only vex that refuses or flags a shrinkwrap-only wiring the same way Fix npm VEX attesting a patch the twin lock lacks (#798) #799 handles a twin with no entry (patched_ref_unattributable). The two doc lines above should also be corrected.
  • Actual: silent success, not_affected, and unpatched npm 12 installs. The redirect unit test npm_shrinkwrap_only_still_rewritten_no_warnings (patch/redirect/mod.rs:14809) asserts "zero warnings" for this shape, describing it as "the npm <= 6 world".

OS × version

OS writer npm (shrinkwrap lockfileVersion) mode scan lockfile-only vex consumer npm install
Linux 10.9.4 (v3) hosted exit 0, no shrinkwrap warning not_affected npm 12.2.0: unpatched; npm 10.9.4: patched
Linux 10.9.4 (v3) vendored exit 0, no warning not_affected npm 12.2.0: unpatched; npm 10.9.4: patched
Linux 8.19.4 (v2) hosted exit 0 not_affected (×2) npm 12.2.0: unpatched (×2); npm 8.19.4: patched
Linux 8.19.4 (v2) vendored exit 0 not_affected (×2) npm 12.2.0: unpatched (×2); npm 8.19.4: patched
Linux — (plain shrinkwrap, no socket-patch) — — — npm 12.0.0 / 12.1.0 / 12.2.0 ignore the shrinkwrap pin
macOS / Windows not probed; npm's behaviour, no OS-specific code path

Not a regression. npm 12's handling has been the same since 12.0.0.

Suspect code

  • crates/socket-patch-core/src/vex/discover/npm.rs:102-115: the cross-lock contest only fires when a package-lock.json twin exists. A lone npm-shrinkwrap.json is attested as if every npm reads it.
  • crates/socket-patch-core/src/patch/redirect/mod.rs:14809 (npm_shrinkwrap_only_still_rewritten_no_warnings) pins the silent path, and the vendored npm wiring has the same assumption.
  • Docs: docs/ecosystems.md:42, and docs/testing/npm-compatibility.md:20 and :49.

Related: #798 / #799 (twin with no entry), #753 (hasShrinkwrap nested copies; npm 12 ignores those too).

Activity

  1. added
    bug
    bughunt
    on Oct 6, 2026
  2. mikolalysenko commented on Oct 6, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Triaged as priority:p1 (npm). Not a duplicate: #798/#799 cover a shrinkwrap with a package-lock.json twin that lacks the entry, and #753 covers nested hasShrinkwrap copies. This one is the shrinkwrap-only project, where npm 12 creates the twin from the registry. I found no open or merged PR that fixes it.


    Generated by Claude Code

  3. mikolalysenko commented on Oct 7, 2026

    @mikolalysenko
    CollaboratorAuthor

    Being fixed in draft PR #1008 (batch fix for open pm:npm issues).

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

    agent:triagedbugbughuntpm:npmpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions