Skip to content

[BUG] npm install strips #<commit> from git resolved URLs in yarn.lock, installing HEAD instead of the locked commit #10347

In progress

Description

@trackoor

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

This is not just a request to bump a dependency for a CVE

  • This is not solely a request to bump a dependency for a CVE

Current Behavior

When package-lock.json is absent and a Yarn v1 yarn.lock is present, npm install uses yarn.lock to seed the tree (Shrinkwrap#checkYarnLock), but strips #<commit> from git+... resolved entries.

For example, with "abbrev": "git+https://github.com/isaacs/abbrev-js.git#semver:^1.1.0" in package.json and a yarn.lock generated by yarn@1.22.22 locking abbrev@1.1.1 at commit a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb:

  1. npm install --allow-git=root fails with EALLOWGIT because npm fetches default-branch HEAD (abbrev@5.0.0), which makes the root edge invalid (edge.valid === false) and causes #extractOrLink to treat the root dependency as a non-root git dependency:
npm error code EALLOWGIT
npm error Fetching non-root packages of type "git" have been disabled
npm error Refusing to fetch "abbrev@git+https://github.com/isaacs/abbrev-js.git"
  1. npm install --allow-git=all (and default npm install on npm 11) ignores both the commit in yarn.lock and #semver:^1.1.0 in package.json, installs abbrev@5.0.0 from HEAD, writes "resolved": "git+https://github.com/isaacs/abbrev-js.git" without a commit hash to package-lock.json and yarn.lock, and leaves npm ls failing with ELSPROBLEMS:
npm warn skipping integrity check for git dependency https://github.com/isaacs/abbrev-js.git

added 1 package in 992ms
repro@1.0.0 /tmp/repro
└── abbrev@5.0.0 invalid: "git+https://github.com/isaacs/abbrev-js.git#semver:^1.1.0" from the root project (git+https://github.com/isaacs/abbrev-js.git)

npm error code ELSPROBLEMS
npm error invalid: abbrev@5.0.0 /tmp/repro/node_modules/abbrev

Removing yarn.lock and running npm install --allow-git=root installs abbrev@1.1.1 (git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb) cleanly. The same stripping also occurs when package.json pins an exact commit hash (git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb) alongside yarn.lock.

Root cause: in workspaces/arborist/lib/yarn-lock.js, YarnLock#parse runs metadata[1] = metadata[1].replace(/#.*/, '') on every resolved value to remove legacy tarball #<sha1> shasums, which also strips the #<commit> fragment from git+... URLs (even though YarnLock.fromTree emits resolved "git+...#<commit>").

Expected Behavior

YarnLock#parse preserves #<commit> fragments on git resolved URLs so npm install --allow-git=root installs the locked commit (abbrev@1.1.1 at a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb), records the commit hash in package-lock.json, and npm ls exits 0.

Steps To Reproduce

WORK=$(mktemp -d)
cd "$WORK"

cat > package.json << 'EOF'
{
  "name": "repro",
  "version": "1.0.0",
  "dependencies": {
    "abbrev": "git+https://github.com/isaacs/abbrev-js.git#semver:^1.1.0"
  }
}
EOF

# Generated by yarn@1.22.22 for the package.json above
cat > yarn.lock << 'EOF'
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"abbrev@git+https://github.com/isaacs/abbrev-js.git#semver:^1.1.0":
  version "1.1.1"
  resolved "git+https://github.com/isaacs/abbrev-js.git#a9ee72ebc8fe3975f1b0c7aeb3a8f2a806a432eb"
EOF

# 1. Fails with EALLOWGIT on npm 12 under --allow-git=root
npm install --allow-git=root --no-audit --no-fund

# 2. Installs HEAD (abbrev@5.0.0) instead of locked 1.1.1 under --allow-git=all
npm install --allow-git=all --no-audit --no-fund
npm ls

Environment

  • npm: 12.2.3 (bundles @npmcli/arborist 10.0.5; also reproduces on npm/cli latest at 787f1520fa and npm 11.21.3)
  • Node.js: v24.22.2
  • OS Name: Debian GNU/Linux 12 (bookworm), Linux 6.1 x86_64
  • npm config:
; defaults (empty .npmrc)

Credit: https://ucsbplse.github.io/

Activity

  1. cryptostrapon commented on Nov 26, 2026

    @cryptostrapon

    Reproduced on Linux with npm 12.2.3 (latest) and 11.21.3, Node 22.23.4, same abbrev setup (#semver:^1.1.0, yarn.lock from yarn 1.22.22 pinning 1.1.1 at a9ee72e).

    • npm 12 with --allow-git=root fails with EALLOWGIT; with --allow-git=all (and plain npm install on npm 11) it installs abbrev@5.0.0 and exits 0, with only the "skipping integrity check" warning.
    • It also rewrites yarn.lock: the entry becomes version "5.0.0", resolved "git+ssh://git@github.com/isaacs/abbrev-js.git", so the commit pin is gone from both lockfiles and the URL switched from https to ssh.
    • A later npm ci refuses (lock file's abbrev@5.0.0 does not satisfy abbrev@1.1.1), so pipelines on npm ci catch it, but anything that runs npm install gets the default branch HEAD silently.
    • Control: without yarn.lock, the same command installs 1.1.1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions