Skip to content

Hosted rollback and remove restore a package-lock.json or yarn classic entry from the public registry though the project names its own: yarn 1 then installs around the mirror and a firewalled CI fails, and the undo is refused where only the mirror answers #2367

Backlog

Description

[agent] Found by the architecture refactor routine on main at cfc870f, with real yarn 1.22.22, real npm 10.9.9 and the binary built from main.

The problem

Hosted mode keeps no record of a lock entry's original. rollback and remove rebuild it from a registry's version document. Which registry they ask differs by lock:

  • pnpm-lock.yaml, bun.lock, bun.lockb, a yarn berry yarn.lock and vlt-lock.json ask the registry the project resolves the package against (its .npmrc, .yarnrc.yml, bunfig.toml, the vlt node's registry), and fall back to the default one with an upstream_registry_fallback warning.
  • package-lock.json / npm-shrinkwrap.json and a yarn classic yarn.lock ask the default registry only (registry.npmjs.org, or SOCKET_NPM_REGISTRY). The project's .npmrc or .yarnrc is not read.

So in a project that installs through a mirror (Artifactory, Nexus, Verdaccio, a cloud artifact registry), the last two give a lock back that the project never had:

  • yarn classic: the entry comes back as https://registry.yarnpkg.com/…. yarn 1 fetches a lock's URL as written, so the next cold install goes around the mirror. Where only the mirror is reachable (an allow-listed or air-gapped CI), yarn install --frozen-lockfile fails. rollback exits 0 and warns of nothing.
  • npm: the entry comes back as https://registry.npmjs.org/…. npm swaps that host for the configured registry by default, so npm ci still works; with replace-registry-host=never it fails. The committed lock differs from the one before the scan either way.
  • both: on a machine that cannot reach the public registry the undo is refused, although the project's own mirror answers. The message names the public URL and git checkout -- <lock>; it does not name SOCKET_NPM_REGISTRY, which is the one way out and appears in CLI_CONTRACT.md only (one table row).

This is the class of #908 and #521 (yarn berry and vlt), #919 (pnpm) and #992 (bun), fixed one lock at a time. These two locks were left.

Evidence

Five locks, the same project shape

The bench's hosted fixtures (60 packages, one patched), each turned into a mirror project: the registry setting names http://127.0.0.1:18081/, and the lock's URLs are that mirror's. Then a real scan in hosted mode against the bench's patch API, then rollback --yes. Two stand-in registries log what they are asked: the mirror on 18081, and the default one (SOCKET_NPM_REGISTRY), whose documents carry registry.npmjs.org tarball URLs as npmjs's do.

Lock Asked for the version document Both registries up The default registry unreachable
package-lock.json the default registry; the mirror gets no request exit 0, no warning about it; resolved is https://registry.npmjs.org/… exit 1, hosted_restore_refused; the lock stays hosted
yarn.lock (classic) the default registry; the mirror gets no request exit 0, no warning about it; resolved is the default registry's URL exit 1, hosted_restore_refused; the lock stays hosted
pnpm-lock.yaml the mirror exit 0; the lock is byte for byte the one before the scan exit 0; the same
bun.lock the mirror exit 0; the registry slot is the mirror's tarball URL exit 0; the same
yarn.lock (berry) the mirror not comparable here: the bench's patch server has no upstream-checksum document, so the run stops after the lookup

The npm row, as a diff of the lock before the scan against the lock after the rollback:

<       "resolved": "http://127.0.0.1:18081/fefiba30/-/fefiba30-25.24.3.tgz",
---
>       "resolved": "https://registry.npmjs.org/fefiba30/-/fefiba30-25.24.3.tgz",

The refusal, with no SOCKET_NPM_REGISTRY and the public registry unreachable:

$ socket-patch rollback --yes
Error: Cannot restore pkg:npm/fefiba30@25.24.3 to its upstream registry entry: fefiba30@25.24.3: GET https://registry.npmjs.org/fefiba30/25.24.3: error sending request for url (https://registry.npmjs.org/fefiba30/25.24.3): client error (Connect): tunnel error: failed to create underlying connection: tcp connect error: Connection refused (os error 111); restore it from version control instead (`git checkout -- package-lock.json`)
                                                                        # exit 1

The pnpm project in the same network:

$ socket-patch rollback --yes
Restored pkg:npm/dehino30@24.21.11 to its upstream registry entry        # exit 0; the mirror's log: GET /dehino30/24.21.11

Real yarn 1.22.22

A real left-pad 1.3.0 served by a stand-in mirror on loopback. "Behind the firewall" is a shell in which only loopback answers.

$ cat .yarnrc
registry "http://127.0.0.1:18083/"
$ yarn install                                  # behind the firewall: exit 0, through the mirror
$ grep resolved yarn.lock
  resolved "http://127.0.0.1:18083/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e"

# the entry pinned to the patch server, as a hosted scan writes it; then, on a machine that reaches the public registry:
$ socket-patch rollback --yes --patch-server-url https://patch.test
Restored pkg:npm/left-pad@1.3.0 to its upstream registry entry

Note: 1 unwired package keeps its patched bytes in installed trees until the next package-manager install.
                                                # exit 0; the mirror's log is empty
$ grep resolved yarn.lock
  resolved "https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz#5b8a3a7765dfe001261dde915589e782f8c94d1e"

# CI behind the firewall: a fresh checkout and a cold cache
$ yarn install --frozen-lockfile
info There appears to be trouble with your network connection. Retrying...
error Error: https://registry.yarnpkg.com/left-pad/-/left-pad-1.3.0.tgz: tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:9
                                                # exit 1; the mirror's log is empty

# the same checkout with the lock from before the scan
$ yarn install --frozen-lockfile                # exit 0; the mirror's log: GET /left-pad/-/left-pad-1.3.0.tgz

remove pkg:npm/left-pad@1.3.0 --yes writes the same entry. With SOCKET_NPM_REGISTRY=http://127.0.0.1:18083 the rollback asks the mirror and the lock comes back byte for byte.

The host changes for a project on the public registry too. With registry "https://registry.npmjs.org/" in .yarnrc, yarn writes registry.npmjs.org URLs, and after a scan and a rollback the entry reads registry.yarnpkg.com: a second host for an allow-list, and a changed line in a lock the user meant to put back.

Real npm 10.9.9

The same mirror, registry=http://127.0.0.1:18083/ in .npmrc:

$ socket-patch rollback --yes --patch-server-url https://patch.test       # exit 0; the mirror's log is empty
<       "resolved": "http://127.0.0.1:18083/left-pad/-/left-pad-1.3.0.tgz",
---
>       "resolved": "https://registry.npmjs.org/left-pad/-/left-pad-1.3.0.tgz",

$ npm ci                                         # behind the firewall, cold cache: exit 0 (npm asks the mirror for /left-pad/-/left-pad-1.3.0.tgz)
$ npm ci --replace-registry-host=never           # exit 1: npm asks registry.npmjs.org

Where

Core patch/redirect/upstream/npm.rs. fetch_dists (lines 22 to 33) reads the default registry and has two callers: restore_npm_locks (line 235) and restore_classic (line 399). The other five restores call fetch_dists_on with the project's registry: berry (line 916), pnpm (line 2049), bun.lock (line 2868), bun.lockb (upstream/bun_lockb.rs, line 110) and vlt (upstream/vlt.rs, line 247).

The earlier fixes, from git log -S'fetch_dists_on':

vendor/registry_fetch.rs (lines 16 to 18) still calls SOCKET_NPM_REGISTRY "the enterprise-mirror / test escape hatch" and says .npmrc parsing is out of scope. Four of the six lock families have parsed the project's settings since.

CLI_CONTRACT.md describes today's split: line 2064 names berry, pnpm and bun as reading the project's registry, and the rows of SOCKET_NPM_REGISTRY (line 2320) and upstream_registry_fallback (line 2506) list the same locks. Nothing there says npm and yarn classic are meant to differ.

Planned fix

restore_npm_locks and restore_classic call fetch_dists_on with the registry the package manager resolves the package against, as their five siblings do, with the same fallback to the default registry and the same upstream_registry_fallback warning:

  • npm: the .npmrc registry and @scope:registry of the project and the user, and npm_config_registry. The readers the pnpm and bun restores use for .npmrc are in the same file.
  • yarn classic: registry from yarn 1's settings layers (.yarnrc, .npmrc, YARN_* and npm_config_*). The hosted rewriter already reads those layers for yarn-offline-mirror and global-folder (core patch/redirect/yarnrc.rs).
  • yarn classic keeps the document's dist.tarball when it came from the project's registry, and maps npmjs to registry.yarnpkg.com only when the project names no registry.

fetch_dists then has no caller and goes. The three contract passages gain the two locks. Tests: one in-process rollback per lock with two mock registries, asserting which one was asked and the restored entry; they fail on main.

The refusal can name SOCKET_NPM_REGISTRY in the same change.

Related


Generated by Claude Code

Activity

  1. added
    bug
    arch-audit
    on Nov 29, 2026
  2. added a commit that references this issue on Nov 29, 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