Skip to content

A vendored Yarn berry patch pins every version of its package: a dependency added later on another version silently gets the vendored release, and yarn up of the package installs nothing new, while vendor --check passes #2450

Backlog

Description

[agent] Found by the architecture refactor routine (lead L141). Run on main at 6280589 with real Yarn 4.12.0, and again with 4.0.2 and 4.19.0.

The problem

Vendored mode wires a Yarn berry patch with a resolutions entry keyed by the package's name alone (core vendor/yarn_berry_lock.rs, line 461):

"resolutions": { "left-pad": "file:./.socket/vendor/npm/<uuid>/left-pad-1.3.0.tgz" }

Yarn applies a name-only selector to every descriptor of that name, whatever its range and whoever depends on it. vendor knows this. When the lock already holds another version, it refuses, and says why (line 1527, vendor_override_conflict):

yarn.lock also resolves left-pad@0.0.3 (`"left-pad@npm:0.0.3"`); the name-keyed resolutions
entry vendoring writes would move that version too — refusing

That check runs once, at vendor time. The selector stays in package.json afterwards, and from then on it moves every version that arrives later, with no message from Yarn and none from socket-patch:

  • A dependency added later that needs another version of the package gets the vendored release. line-numbers@0.2.0 declares left-pad: 0.0.3; in a project that vendored a patch for left-pad@1.3.0 it runs on 1.3.0.
  • yarn up <package>@<version> of the vendored package installs nothing new. package.json gets the new version, yarn exits 0, and node_modules keeps the vendored release. A developer who upgrades to the release that fixes the vulnerability upstream stays on the old one.

vendor --check passes in both states, a re-run of vendor says already_vendored, and list and vex report nothing unusual.

The other writers do not do this. Hosted mode on the same package manager keys the selector by the locked descriptor ("left-pad@npm:1.3.0"), vendored pnpm writes a name@version override, and the vendored Bun backend edits lock entries because "a name-keyed override collapses EVERY version" (core vendor/bun_lock.rs, line 14).

Who it hurts: any Yarn 4 project in vendored mode, the first time its tree gains a second version of a patched package (common for semver, minimatch, glob, debug and the like), or the first time someone upgrades the patched package. The first case can break the build at run time with no change in any file that names the cause; the second leaves a team believing it upgraded.

Evidence

One project, {"dependencies": {"left-pad": "1.3.0"}}, nodeLinker: node-modules, installed by Yarn 4.12.0. Three copies: untouched, after scan --mode hosted, and after vendor (the artifact came from the repository's fixture vendor service, the one e2e_vendor_yarn_berry_build uses). Then one everyday command in each:

Project yarn add line-numbers@0.2.0: the left-pad that line-numbers loads yarn up left-pad@1.2.0: the left-pad installed
no patch 0.0.3 1.2.0
hosted 0.0.3 (the root keeps the patched 1.3.0) 1.2.0 (upstream; the pin lets go)
vendored 1.3.0, the vendored release 1.3.0, the vendored release; package.json says 1.2.0

The vendored project after yarn add line-numbers@0.2.0 (exit 0; Yarn prints only + line-numbers@npm:0.2.0):

$ find . -path '*/node_modules/left-pad/package.json'
./node_modules/left-pad/package.json                      # 1.3.0, patched; no copy under line-numbers
$ grep -n 'left-pad' yarn.lock
12:    left-pad: "npm:1.3.0"
16:"left-pad@file:./.socket/vendor/npm/1a2b…/left-pad-1.3.0.tgz::locator=app%40workspace%3A.":
18:  resolution: "left-pad@file:./.socket/vendor/npm/1a2b…/left-pad-1.3.0.tgz#…"
28:    left-pad: "npm:0.0.3"                                 # line-numbers' own range; no entry resolves it
$ socket-patch vendor --check --json     → exit 0, "vendor_check_ok", "committed artifact and wiring verified"
$ socket-patch vendor --json             → exit 0, "already_vendored"
$ socket-patch vex --offline …           → exit 0, not_affected for pkg:npm/left-pad@1.3.0

The vendored project after yarn up left-pad@1.2.0 (exit 0):

package.json:  "dependencies": {"left-pad": "1.2.0"},  "resolutions": {"left-pad": "file:./.socket/vendor/…/left-pad-1.3.0.tgz"}
node_modules/left-pad: version 1.3.0, patched
$ socket-patch vendor --check --json     → exit 0, "vendor_check_ok"

Yarn 4.0.2 and 4.19.0 give the vendored yarn add row the same way: one left-pad, 1.3.0.

When both versions are in the lock before vendoring, vendor exits 1 with the refusal quoted above (ran). So the state vendor refuses to create is the state the selector creates later.

What a scoped selector does

The same vendored tree with the key changed by hand to the locked descriptor, "left-pad@npm:1.3.0": "file:./.socket/vendor/…/left-pad-1.3.0.tgz", Yarn 4.12.0:

  • yarn install --immutable --check-cache exits 0 and leaves the lock vendor wrote byte for byte;
  • yarn add line-numbers@0.2.0 gives line-numbers its 0.0.3 and keeps the patched 1.3.0 for the root;
  • yarn up left-pad@1.2.0 installs 1.2.0, and vendor --check on main then exits 1 and names the way out (dependency removed: no lockfile resolves pkg:npm/left-pad@1.3.0 any more (it was upgraded or uninstalled) … run socket-patch scan --mode vendored --prune);
  • vendor --check and vex on main already accept it (exit 0, vendor_check_ok, not_affected).

There is one trade. A later range of the same release (a workspace member adding "left-pad": "^1.3.0") is covered by the name-only selector and not by the scoped one: Yarn locks a second, upstream copy. main already catches that state: vendor --check exits 1 (copy unpatched: … lock entry "left-pad@npm:^1.3.0" installs it from the registry), and vex withholds the statement. It is the trade hosted mode documents ("A range of the package added after the pin … re-running scan --mode hosted adds a selector for it").

The writer and the revert on main know only the name-only key: over the hand-scoped tree vendor refuses it as a user's override (vendor_override_conflict) and vendor --revert stops at vendor_lock_still_wired_revert_blocked.

Planned fix

In core vendor/yarn_berry_lock.rs: write one selector per descriptor the replaced lock entry is keyed by, as the hosted writer does; recognise both spellings as ours on a re-run and on vendor --revert, and move a name-only selector an earlier release wrote to the scoped one on the next vendor. The vendor-time refusal of a second version then has nothing left to guard, so a project that holds two versions of a package becomes vendorable.

Tests: a real-Yarn case in e2e_vendor_yarn_berry_build (after vendoring, yarn add line-numbers@0.2.0 leaves 0.0.3 under line-numbers, and yarn up left-pad@1.2.0 installs 1.2.0 with vendor --check reporting dependency removed), and unit tests for the two spellings in the writer and the revert.

This changes the key vendor writes into package.json. If a maintainer prefers to keep the name-only selector, the alternative is a check in vendor --check and vex for a lock dependencies: range, or a root range, that the vendored version does not satisfy. That reports the state at the next check; it does not stop the install.

Not run

Windows and macOS; the PnP and pnpm linkers; Yarn 2 and 3 (vendored mode refuses them); a workspace with members beyond the one case above; a catalog dependency; a real package with two majors in one tree (the mechanism is Yarn's, not the package's).


Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Dec 2, 2026
  2. mikolalysenko commented on Dec 2, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] Two more runs on main at 6280589, for whoever takes this.

    The other npm-family backends in vendored mode. The same project and the same two commands, each with its real tool (npm 10.9.9, pnpm 10.28, Yarn 1.22.22, Bun), vendored through the same fixture service:

    Vendored with add line-numbers@0.2.0: the left-pad it loads change left-pad to 1.2.0: installed, and vendor --check
    npm 0.0.3 1.2.0; exit 1, dependency removed
    pnpm (left-pad@1.3.0 override) 0.0.3 1.2.0; exit 1, dependency removed
    Yarn classic 0.0.3 1.2.0; exit 1, dependency removed
    Bun 0.0.3 1.2.0; exit 1, dependency removed
    Yarn berry 1.3.0, the vendored release 1.3.0, the vendored release; exit 0, vendor_check_ok

    dependency removed is the message "no lockfile resolves pkg:npm/left-pad@1.3.0 any more (it was upgraded or uninstalled) … run socket-patch scan --mode vendored --prune". Yarn berry is the one backend of the five that never reaches it.

    The revert already knows the state. In the Yarn berry project after yarn add line-numbers@0.2.0:

    $ socket-patch vendor --revert --json      → exit 0
      skipped  vendor_lock_descriptor_unlocked  `left-pad@npm:0.0.3` was added while left-pad was vendored, and the
               restored left-pad@1.3.0 does not satisfy it (or its range could not be read), so it has no yarn.lock
               entry; run `yarn install` and commit yarn.lock
    $ yarn install --immutable                 → exit 1, YN0028: +"left-pad@npm:0.0.3": …
    $ yarn install                             → exit 0; line-numbers now loads left-pad 0.0.3
    

    So the reader that finds a descriptor the vendored version does not satisfy exists, for the revert (#759, 4353a7c). While the patch is vendored nothing runs it: vendor --check, a re-run of vendor and vex all pass over the same lock. It also means the build changes twice: line-numbers moves to 1.3.0 when it is added, and back to 0.0.3 when the patch is reverted or replaced.


    Generated by Claude Code

  3. mikolalysenko commented on Dec 2, 2026

    @mikolalysenko
    CollaboratorAuthor

    [agent] A third way in, and likely the common one: the patched package is a dependency of a dependency, at an old version.

    A project that depends on line-numbers@0.2.0 only, which brings left-pad@0.0.3. vendor wires a patch for left-pad@0.0.3 ("resolutions": {"left-pad": "file:…/left-pad-0.0.3.tgz"}); a fresh yarn install --immutable --check-cache passes and the patched file is installed. Then the developer adds the current release for their own code, Yarn 4.12.0:

    $ yarn add left-pad@1.3.0                 → exit 0, "Done"; no line about left-pad
    $ grep left-pad package.json
        "left-pad": "1.3.0",
    $ node -e 'console.log(require("left-pad/package.json").version)'
    0.0.3
    $ socket-patch vendor --check --json      → exit 0, "vendor_check_ok"
    

    The one left-pad in node_modules is the vendored 0.0.3, and the application's own require("left-pad") loads it.

    The rest of this case is clean on main at 6280589: the transitive pin survives the fresh install, vex --offline attests it, and vendor --revert puts package.json and yarn.lock back byte for byte.


    Generated by Claude Code

  4. added a commit that references this issue on Dec 2, 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

    agent:triagedarch-auditbugpriority:p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions