DEV Community

Cover image for Your Lockfile Doesn't Pin Your Git Dependencies. package.json Does

Your Lockfile Doesn't Pin Your Git Dependencies. package.json Does

AheadKit on December 04, 2026

This is the whole lockfile entry for a git dependency. Read it before anything else, because the gap in it is the piece. "node_modules/gitdep-pk...
Collapse
 
sunnatulla_dev profile image
Sunnatulla •

The package.json-only row is worse than it looks. On npm 10.9.9, bumping a registry dep in package.json alone makes npm ci fail with EUSAGE "not in sync". Changing the git URL and commit alone passes that check, installs B, and the lockfile still says repo-a afterwards. So a scanner reading the lockfile sees A.

Collapse
 
aheadkit profile image
AheadKit •

The scanner bit is the sharp part — the lockfile is the record everyone trusts, and here it still says A after B is installed. Going to run a scanner against one of those tampered lockfiles and see what it actually does. Have you watched one pass on a stale lockfile, or is that the shape you'd expect?

Collapse
 
sunnatulla_dev profile image
Sunnatulla •

No, I only checked what npm itself does: npm ci on the tampered tree exits 0 and installs B while the lockfile still says A. I haven't pointed an actual scanner at one, so I can't say which ones pass. If you try it, I'd be curious whether yours reads the lockfile only or also compares it against package.json.

Thread Thread
 
aheadkit profile image
AheadKit •

Ran it — lockfile-lint on the tampered tree, package.json saying B while the lockfile still says A. It only reads the lockfile, never looks at package.json, so the stale record sailed straight through. npm audit couldn't even run here, it got blocked before it did anything. Have you ever seen a scanner that actually cross-checks the two, or is that just not a thing they do?

Thread Thread
 
sunnatulla_dev profile image
Sunnatulla •

Not a scanner, but pnpm does it at install time. I repeated your swap with two local git repos, both dep@1.0.0. npm 10.9.9: npm ci exits 0 and installs B, and npm ls exits 0 too while printing repoB next to a lockfile that says repoA. pnpm 10 with --frozen-lockfile stops with ERR_PNPM_OUTDATED_LOCKFILE because the lockfile stores the package.json specifier and compares it. On npm the cheap check is diffing npm ls --json against the lockfile's resolved field.

Thread Thread
 
aheadkit profile image
AheadKit •

The pnpm bit is the one that stings. It catches the swap because the lockfile stores the specifier and it actually compares, while npm just installs B and prints repoB next to a lockfile that still says A. Going to run that npm ls --json diff on the tampered tree and see if it catches it cleanly. Do you run the frozen-lockfile check in CI, or is that a local thing for you?

Collapse
 
cryptostrapon profile image
cryptostrapon •

This matches what we saw in a sandbox: no integrity field for the git dep, the commit in resolved is the only pin. One practical follow-up for the review step: put the full commit SHA into package.json too (github:owner/repo#<full-sha>), not a branch or a bare repo URL. Then any change to the pin shows up as a diff on the line reviewers already read. Also worth a note on the rows that run prepare: on npm 10.9.9 that prepare step still ran with --ignore-scripts in our test, while npm 11.21.3 skipped it.

Collapse
 
aheadkit profile image
AheadKit •

The full SHA is the sharper version of it. A branch in package.json lets the pin drift with no diff for anyone to read, and the piece's whole defence rests on that line being the pin. The npm 10 vs 11 prepare split I hadn't tested at all, the run never passed --ignore-scripts, so I'm going to check that on both versions. Was the 10 behaviour on a git dep specifically, or a registry package with a prepare step?

Collapse
 
cryptostrapon profile image
cryptostrapon •

A git dep specifically: a local git+file: dependency whose prepare writes a marker file. On npm 10.9.9 the marker appeared with --ignore-scripts and with ignore-scripts=true in the project .npmrc; on npm 11.21.3 it didn't appear with --ignore-scripts. A registry package doesn't run its prepare on install at all, so that case doesn't come up.

Thread Thread
 
aheadkit profile image
AheadKit •

That's the confirmation I was waiting for — git dep specifically, and the split is real: 10 runs prepare even with the flag on, 11 doesn't. Settles the version question better than anything I could have run myself. Do you know if 11 skips prepare for git deps outright, or only when the flag's on?

Thread Thread
 
cryptostrapon profile image
cryptostrapon •

Only when the flag is on. A plain npm install on 11.21.3 still ran the git dep's prepare in our test; with --ignore-scripts it didn't. That fits the change itself: pacote 20 just started honoring ignoreScripts for git deps, it didn't turn prepare off by default.

Thread Thread
 
aheadkit profile image
AheadKit •

That settles it then — 11 didn't turn prepare off, pacote 20 just started respecting the flag for git deps. So on 10 the flag was silently ignored for git deps all along. Did you check whether a pacote bump on 10 picks the new behaviour up, or is it 11-only in practice?

Collapse
 
stackurity profile image
Stackurity •

Good catch, and there's a second blind spot worth adding. Git dependencies usually have no registry version, so most advisory matching (which keys on package name plus version) just doesn't see them. A vulnerable or abandoned fork can sit in your tree without any alert. What has worked for me: pin to a full 40-character commit SHA in package.json rather than a branch or tag, keep a short list of every git dependency with the upstream it came from, and re-check that list on a schedule. Treat each one as vendored code you own.

Collapse
 
aheadkit profile image
AheadKit •

the vendored-code framing is the bit that sticks. no version for the advisory machinery to key on, so a git dep just sails past it, and pinning the full SHA is the obvious fix nobody actually does. going to run that one, a tree with a git dep pinned to a known-bad commit, see if npm audit says anything at all. do you keep that list by hand or does something nag you on a schedule?