Claude MCP skill command injection — static analysis and linting tool execution — SA-SKL-INJECTION17
Static analysis tool execution pipelines in MCP skill registries invoke external security scanners — ESLint, semgrep, bandit, trufflehog — against user-submitted skill packages. When tool arguments are constructed by string interpolation with values from the uploaded archive, command injection and argument injection vulnerabilities allow attackers to manipulate tool behavior, disable security rules, scan unintended filesystem locations, or exfiltrate system files. SA-SKL-INJECTION17 covers four patterns: an ESLint exec with the filePath argument derived from an archive entry name that allows rule-set weakening via injected ESLint options; a semgrep scan where the repository directory name from the package name injects a --no-git-ignore flag disabling traversal restrictions; a bandit Python scan where a null byte in the repoPath truncates the path to the parent directory; and a trufflehog secrets scan where a space in the repoPath allows appending --include-paths=/etc/passwd to scan and return the contents of system files.
exec(`eslint --format json ${filePath} 2>&1`) with filePath from extracted archive entry name — entry name containing space and --env flag injects ESLint options; --env browser,node relaxes security rule set producing fewer findingsexec(`semgrep --config=auto ${repoDir}`) with repoDir from temp directory named after skill package — package name with hyphen prefix parsed as semgrep flag; --no-git-ignore disables .gitignore traversal restriction and scans system .config dirssubprocess.run(['bandit', '-r', repoPath, '-f', 'json']) with repoPath from user upload — path with null byte truncates at OS level; actual scanned path is parent directory; fix: validate path starts within sandbox using os.path.realpath()exec(`trufflehog filesystem ${repoPath} --json`) with repoPath from ZIP extraction — path with space and --include-paths=/etc/passwd argument appended; trufflehog scans /etc/passwd and returns its content as "secret findings" in reportBackground: command injection in static analysis tool execution
MCP skill registry security scanners run third-party CLI tools — ESLint, semgrep, bandit, trufflehog — against user-submitted code. These tools accept a rich set of command-line options that modify their behavior: disabling rule sets, ignoring traversal restrictions, scanning additional files, or changing output formats. When the directory path or filename passed to these tools is derived from attacker-controlled archive contents (entry names, package names, or extracted path segments), two injection classes arise: shell command injection (via exec() with shell:true or unquoted interpolation) and argument injection (via path values that parse as valid tool options). Argument injection is particularly dangerous because it does not require shell metacharacter bypass — a hyphen-prefixed directory name is a valid argument to the tool's argument parser, and no shell quoting prevents its interpretation.
INJECTION17-001 and INJECTION17-004 exploit shell command injection via string interpolation in exec(). INJECTION17-002 exploits argument injection: semgrep processes a directory name starting with --no-git-ignore as a flag, not a path argument. INJECTION17-003 exploits null byte injection: the OS-level open() syscall terminates the path string at the null byte, causing bandit to scan a different directory than intended. The fix for all four is to use execFile() or subprocess.run() with an argument array (never exec() with shell:true for user-controlled values) and to validate the extracted path as an absolute path starting within the sandbox directory using os.path.realpath() / path.resolve().
Related patterns: SA-SKL-INJECTION16 (command injection in package build and test execution pipeline), SA-SKL-INJECTION15 (code injection in CI/CD audit pipeline), SA-SKL-SSRF29 (SSRF in webhook delivery retry and error reporting pipeline).
INJECTION17-001 — HIGH — ESLint exec with filePath from archive entry name injects rule set options
The ESLint static analysis step extracts the skill ZIP archive and runs ESLint against each JavaScript file using exec(`eslint --format json ${filePath} 2>&1`, { shell: true }) where filePath is the entry name from the archive. An attacker crafts a ZIP archive with an entry named src/index.js --env browser,node --rule '{"no-eval":0}'. The shell interprets the entry name as three separate arguments: the file path src/index.js, the --env browser,node flag which enables browser and Node.js global environments (relaxing some security rules), and the --rule '{"no-eval":0}' flag which disables the no-eval security rule.
The ESLint scan runs with the attacker-specified options and produces fewer security findings — the audit report shows a falsely clean result with the eval() pattern omitted. Because the security gate depends on the ESLint output, a skill with injected eval() calls, dangerous innerHTML assignments, or other patterns that ESLint would normally flag is published to the registry as "audited" and clean. The same technique works with --rule '{"no-new-func":0}' to disable the no-new-func rule, --ignore-pattern '**' to skip all files, or --resolve-plugins-relative-to /tmp/attacker-plugin to load attacker-controlled ESLint plugins.
// VULNERABLE — INJECTION17-001
// workers/staticAnalysisWorker.js
const { exec } = require('child_process');
const util = require('util');
const execAsync = util.promisify(exec);
const AdmZip = require('adm-zip');
// BUG: filePath from archive entry name interpolated into shell exec string
// Entry name "src/index.js --env browser,node --rule {\"no-eval\":0}" injects ESLint flags
async function runEslint(zipPath, outputDir) {
const zip = new AdmZip(zipPath);
const results = [];
for (const entry of zip.getEntries()) {
if (!entry.name.endsWith('.js')) continue;
const filePath = path.join(outputDir, entry.entryName); // <- contains attacker-controlled name
zip.extractEntryTo(entry, outputDir, true, true);
// BUG: shell:true + string interpolation with attacker-controlled filePath
const { stdout } = await execAsync(
`eslint --format json ${filePath} 2>&1`, // <- INJECTION HERE
{ shell: true }
);
results.push(JSON.parse(stdout));
}
return results;
}
// FIXED — INJECTION17-001
// workers/staticAnalysisWorker.js
const { execFile } = require('child_process');
const util = require('util');
const execFileAsync = util.promisify(execFile);
const path = require('path');
const AdmZip = require('adm-zip');
// Validate extracted path is within sandbox — prevents path traversal and arg injection
function validateExtractedPath(extractedPath, sandboxDir) {
const resolved = path.resolve(extractedPath);
const sandboxResolved = path.resolve(sandboxDir);
if (!resolved.startsWith(sandboxResolved + path.sep)) {
throw new Error(`Path traversal blocked: ${extractedPath} — INJECTION17-001`);
}
return resolved;
}
async function runEslint(zipPath, outputDir) {
const zip = new AdmZip(zipPath);
const results = [];
for (const entry of zip.getEntries()) {
// Sanitize entry name before constructing output path
const safeName = entry.entryName.replace(/[^a-zA-Z0-9._\-\/]/g, '_');
if (!safeName.endsWith('.js') && !safeName.endsWith('.ts')) continue;
const extractedPath = path.join(outputDir, safeName);
// Validate path stays within sandbox before extraction
const validatedPath = validateExtractedPath(extractedPath, outputDir);
zip.extractEntryTo(entry, outputDir, true, true);
// execFile with arg array — no shell interpolation, no option injection possible
const { stdout } = await execFileAsync(
'eslint',
['--format', 'json', '--no-eslintrc', '--rule', '{"no-eval":"error"}', '--', validatedPath],
{ timeout: 30000 }
);
results.push(JSON.parse(stdout));
}
return results;
}
INJECTION17-001 impact: ESLint security rules disabled by attacker-controlled archive entry names — the audit report shows a falsely clean result with critical patterns (eval(), innerHTML, dangerouslySetInnerHTML) reported as compliant. MCP skills with injected eval() patterns pass the security gate and are published to the registry as "audited". SkillAudit detects this by identifying exec() calls with shell:true where a path argument is derived from archive entry names or user-uploaded file paths.
INJECTION17-002 — HIGH — semgrep scan with package-name-derived repoDir injects --no-git-ignore flag
The semgrep scan step creates a temporary directory named after the skill package for isolation, then runs exec(`semgrep --config=auto ${repoDir}`) where repoDir is the temp directory path. The temp directory is named path.join('/tmp/scans', packageName, uuidv4()). The packageName is taken from the uploaded package.json. An attacker submits a package with the name --no-git-ignore. The temp directory path becomes /tmp/scans/--no-git-ignore/<uuid>. When semgrep processes its arguments, it parses /tmp/scans/--no-git-ignore/<uuid> as the flags --no-git-ignore followed by <uuid>.
The --no-git-ignore flag disables semgrep's .gitignore traversal restriction, causing it to scan directories that the .gitignore would normally exclude — including .git/, .env, node_modules/.cache/, and system configuration directories visible through symlinks. In a shared scan sandbox where multiple skill packages are processed concurrently, disabling .gitignore restriction can expose files from other concurrent scans if sandbox isolation relies on .gitignore entries. The correct fix is to derive the sandbox directory path exclusively from a randomly generated UUID, never incorporating any user-supplied value such as the package name.
// VULNERABLE — INJECTION17-002
// workers/semgrepWorker.js
const { exec } = require('child_process');
const util = require('util');
const execAsync = util.promisify(exec);
const path = require('path');
const { v4: uuidv4 } = require('uuid');
// BUG: package name used directly in temp directory path fed to semgrep exec
// Package name "--no-git-ignore" creates path /tmp/scans/--no-git-ignore/<uuid>
// semgrep parses --no-git-ignore as a flag disabling .gitignore traversal
async function runSemgrep(packageJson, codeDir) {
const packageName = packageJson.name; // <- attacker-controlled
const repoDir = path.join('/tmp/scans', packageName, uuidv4());
await fs.mkdir(repoDir, { recursive: true });
await copyFiles(codeDir, repoDir);
// BUG: repoDir may contain --flags parseable by semgrep
const { stdout } = await execAsync(
`semgrep --config=auto ${repoDir}`, // <- INJECTION HERE
{ timeout: 120000 }
);
return parseSemgrepOutput(stdout);
}
// FIXED — INJECTION17-002
// workers/semgrepWorker.js
const { execFile } = require('child_process');
const util = require('util');
const execFileAsync = util.promisify(execFile);
const path = require('path');
const crypto = require('crypto');
const { v4: uuidv4 } = require('uuid');
// Use cryptographically random directory name — never derive from package name
async function runSemgrep(codeDir) {
// Sandbox directory is a UUID only — no user data in the path
const sandboxId = `${uuidv4()}-${crypto.randomBytes(4).toString('hex')}`;
const repoDir = path.join('/tmp/scans', sandboxId);
await fs.mkdir(repoDir, { recursive: true });
await copyFiles(codeDir, repoDir);
try {
// execFile with arg array — semgrep never sees a path that starts with '--'
// '--' end-of-options marker ensures repoDir is interpreted as a path, not a flag
const { stdout } = await execFileAsync(
'semgrep',
[
'--config=auto',
'--json',
'--metrics=off', // disable telemetry in sandboxed scan
'--max-target-bytes=5000000', // limit file size to prevent OOM
'--', // end-of-options: everything after is a path
repoDir,
],
{ timeout: 120000 }
);
return parseSemgrepOutput(stdout);
} finally {
// Always clean up sandbox directory
await fs.rm(repoDir, { recursive: true, force: true });
}
}
INJECTION17-002 impact: semgrep scans with .gitignore traversal restrictions disabled — the scanner reads directories excluded from normal scanning (.git/, .env, hidden config dirs) and may include their contents in the findings output. More critically, disabling .gitignore restriction in a shared scan sandbox can expose files from other concurrent scans if sandbox isolation relies on .gitignore entries. SkillAudit detects this by identifying exec() calls to semgrep or other CLI security scanners where the directory path argument is derived from a package name or archive root directory name rather than a randomly generated sandbox ID.
INJECTION17-003 — MEDIUM — bandit Python scan with null byte in repoPath scans parent directory
The bandit Python security scanner is invoked with subprocess.run(['bandit', '-r', repoPath, '-f', 'json']) where repoPath is the extracted archive directory. The repoPath is derived from the ZIP archive's root directory name. An attacker crafts a ZIP archive whose root directory name contains a null byte: skillpackage\x00../../etc. When this string is passed to subprocess.run(), Python's subprocess module passes it as-is to the OS execve() syscall. At the OS level, execve() passes the argument as a C string — which is null-terminated. The effective argument received by bandit is skillpackage (truncated at the null byte).
bandit then scans skillpackage as a relative path from the current working directory /tmp/scans/ — which may point to a directory shared with other scan jobs or containing system Python packages. The resulting bandit output includes findings from files outside the intended sandbox. In a shared scan environment this may scan another concurrent user's extracted skill package, including their source code and configuration files. The fix requires rejecting null bytes in entry names at extraction time and validating the scan target path using os.path.realpath() before passing it to bandit.
# VULNERABLE — INJECTION17-003
# workers/bandit_worker.py
import subprocess
import os
import zipfile
import json
def run_bandit(zip_path: str, output_dir: str) -> dict:
with zipfile.ZipFile(zip_path) as zf:
# BUG: root directory name from ZIP used directly as scan target
# ZIP with root dir "skillpackage\x00../../etc" — bandit scans "skillpackage"
# from cwd which may resolve to unintended path
root_dir = zf.namelist()[0].split('/')[0]
repo_path = os.path.join(output_dir, root_dir) # <- contains null byte
zf.extractall(output_dir)
# BUG: subprocess.run with null byte in path — OS truncates at null
# bandit scans wrong directory
result = subprocess.run(
['bandit', '-r', repo_path, '-f', 'json'],
capture_output=True,
text=True,
timeout=60
)
return json.loads(result.stdout)
# FIXED — INJECTION17-003
# workers/bandit_worker.py
import subprocess
import os
import zipfile
import json
import uuid
def run_bandit(zip_path: str, base_output_dir: str) -> dict:
# Use a UUID-named sandbox directory — never derive from archive contents
sandbox_dir = os.path.join(base_output_dir, str(uuid.uuid4()))
os.makedirs(sandbox_dir, exist_ok=True)
try:
with zipfile.ZipFile(zip_path) as zf:
# Validate all entry names before extraction
for entry in zf.namelist():
if '\x00' in entry:
raise ValueError(f'Null byte in ZIP entry name: {repr(entry)} — INJECTION17-003')
# Normalize and validate path stays within sandbox
safe_path = os.path.realpath(os.path.join(sandbox_dir, entry))
if not safe_path.startswith(os.path.realpath(sandbox_dir) + os.sep):
raise ValueError(f'Path traversal in ZIP entry: {entry}')
zf.extractall(sandbox_dir)
# Validate scan target using realpath — resolves symlinks and normalizes
scan_target = os.path.realpath(sandbox_dir)
sandbox_real = os.path.realpath(base_output_dir)
if not scan_target.startswith(sandbox_real + os.sep):
raise ValueError(f'Sandbox escape: {scan_target} — INJECTION17-003')
result = subprocess.run(
['bandit', '-r', scan_target, '-f', 'json', '-ll'],
capture_output=True,
text=True,
timeout=60,
cwd='/' # neutral cwd — no relative path resolution from /tmp
)
return json.loads(result.stdout) if result.stdout else {'results': [], 'errors': []}
finally:
import shutil
shutil.rmtree(sandbox_dir, ignore_errors=True)
INJECTION17-003 impact: bandit scans a directory outside the intended sandbox — in a shared scan environment this may scan another concurrent user's extracted skill package, including their source code and configuration files. The resulting findings report includes vulnerabilities from the wrong package, producing misleading audit results. Null byte injection in file paths is a classic but frequently overlooked vulnerability in polyglot code paths where Python's string handling meets OS syscall boundaries. SkillAudit detects this by scanning subprocess.run() calls where path arguments are derived from archive entry names or zip member names without a null-byte check and os.path.realpath() validation.
INJECTION17-004 — HIGH — trufflehog exec with repoPath from ZIP extraction injects --include-paths=/etc/passwd
The trufflehog secrets scanner is invoked with exec(`trufflehog filesystem ${repoPath} --json`) where repoPath is the extracted skill package directory. The repoPath is constructed as path.join('/tmp/scans', uuidv4(), sanitizedName) where sanitizedName is the archive's root directory name with only leading dot stripping applied. An attacker crafts a ZIP archive whose root directory name is skillpkg --include-paths=/etc/passwd. After the dot stripping, sanitizedName becomes skillpkg --include-paths=/etc/passwd.
The shell exec string becomes trufflehog filesystem /tmp/scans/<uuid>/skillpkg --include-paths=/etc/passwd --json. trufflehog parses --include-paths=/etc/passwd as an include paths file, opens /etc/passwd, and scans each line as a file path to examine for secrets. The /etc/passwd contents (or any file trufflehog can read) are included in the JSON output as "secret findings" and surfaced in the audit report. An attacker who submits a package can trigger a read of arbitrary files readable by the scan worker process — including application configuration files and cloud credential files. Using execFile() with the -- end-of-options separator and a UUID-only sandbox path eliminates the injection surface entirely.
// VULNERABLE — INJECTION17-004
// workers/trufflehogWorker.js
const { exec } = require('child_process');
const util = require('util');
const execAsync = util.promisify(exec);
const path = require('path');
const { v4: uuidv4 } = require('uuid');
const AdmZip = require('adm-zip');
// BUG: archive root dir name with space injects trufflehog arguments
// "skillpkg --include-paths=/etc/passwd" → trufflehog scans /etc/passwd entries
async function runTrufflehog(zipPath) {
const zip = new AdmZip(zipPath);
const entries = zip.getEntries();
// Minimal sanitization — only strips leading dots
const rootName = entries[0]?.entryName.split('/')[0].replace(/^\.+/, '');
const scanDir = path.join('/tmp/scans', uuidv4(), rootName); // <- rootName injected here
await fs.mkdir(scanDir, { recursive: true });
zip.extractAllTo(path.join('/tmp/scans', uuidv4()), true);
// BUG: shell:true exec with injected trufflehog flags
const { stdout } = await execAsync(
`trufflehog filesystem ${scanDir} --json`, // <- INJECTION HERE
{ timeout: 60000, shell: true }
);
return JSON.parse(stdout);
}
// FIXED — INJECTION17-004
// workers/trufflehogWorker.js
const { execFile } = require('child_process');
const util = require('util');
const execFileAsync = util.promisify(execFile);
const path = require('path');
const crypto = require('crypto');
const { v4: uuidv4 } = require('uuid');
async function runTrufflehog(zipPath) {
// Sandbox directory derived only from random UUIDs — never from archive content
const sandboxId = `${uuidv4()}-${crypto.randomBytes(4).toString('hex')}`;
const sandboxDir = path.join('/tmp/scans', sandboxId);
await fs.mkdir(sandboxDir, { recursive: true });
try {
// Extract archive and validate all paths before passing to trufflehog
const zip = new AdmZip(zipPath);
for (const entry of zip.getEntries()) {
const entryPath = path.resolve(sandboxDir, entry.entryName);
if (!entryPath.startsWith(path.resolve(sandboxDir) + path.sep)) {
throw new Error(`ZIP path traversal blocked: ${entry.entryName}`);
}
}
zip.extractAllTo(sandboxDir, true);
// execFile with arg array — '--' end-of-options prevents any directory name
// being parsed as a trufflehog flag
const { stdout } = await execFileAsync(
'trufflehog',
[
'filesystem',
'--json',
'--no-update', // disable auto-update in sandboxed environment
'--', // end-of-options marker
sandboxDir, // only the UUID sandbox dir is scanned
],
{ timeout: 60000 }
);
return JSON.parse(stdout);
} finally {
await fs.rm(sandboxDir, { recursive: true, force: true });
}
}
INJECTION17-004 impact: trufflehog scans /etc/passwd or other system files specified via the injected --include-paths argument, returning their contents as "secret findings" in the audit report. An attacker who submits a package can trigger a read of arbitrary files readable by the scan worker process — including application configuration files, cloud credential files, and other packages in the sandbox. SkillAudit detects this by identifying exec() calls to trufflehog, gitleaks, or other secrets scanners where the scan path argument is derived from ZIP archive entry names without execFile argument array isolation.
Detection with SkillAudit
SkillAudit's static analysis scans static analysis and linting tool execution pipelines for all four SA-SKL-INJECTION17 patterns. For INJECTION17-001 it identifies exec() calls to ESLint with file path arguments derived from archive entry names, flagging the absence of execFile() with an argument array. For INJECTION17-002 it identifies semgrep or similar scanner invocations where the scan directory path is derived from a package name or archive root directory name rather than a randomly generated sandbox ID. For INJECTION17-003 it identifies Python subprocess.run() calls with bandit or similar tools where the path argument is derived from archive contents without a null-byte check and os.path.realpath() confinement validation. For INJECTION17-004 it identifies exec() calls to trufflehog or gitleaks where the scan path argument is constructed from archive entry names and execFile() with the -- end-of-options separator is not used.
| Finding | Severity | Root cause | Fix |
|---|---|---|---|
| INJECTION17-001 | HIGH | ESLint exec() with archive entry name as filePath — --env browser,node --rule {"no-eval":0} injected as flags; security rules disabled; audit shows false-clean result | execFile() with arg array + -- end-of-options; sanitize entry names; randomize extracted file paths |
| INJECTION17-002 | HIGH | semgrep exec() with repoDir from package name — --no-git-ignore package name parsed as flag; .gitignore traversal restriction disabled; system .config dirs scanned | execFile() + -- end-of-options; sandbox UUID only in directory path, never package name |
| INJECTION17-003 | MEDIUM | bandit subprocess.run() with null byte in repoPath — OS truncates path at null byte; bandit scans parent or cwd directory instead of sandbox | Reject null bytes in entry names; os.path.realpath() validation; UUID sandbox directory; neutral cwd='/' |
| INJECTION17-004 | HIGH | trufflehog exec() with archive root name as scan path — space-injected --include-paths=/etc/passwd causes trufflehog to return /etc/passwd contents as findings | execFile() + -- end-of-options; UUID-only sandbox directory; never derive scan path from archive content |
Related findings: SA-SKL-INJECTION16 (command injection in package build and test execution pipeline), SA-SKL-INJECTION15 (code injection in CI/CD audit pipeline), SA-SKL-SSRF29 (SSRF in webhook delivery retry and error reporting pipeline).
SkillAudit scans your MCP skill registry for all SA-SKL-INJECTION17 patterns — ESLint option injection via archive entry names, semgrep flag injection via package names, bandit null byte path truncation, and trufflehog include-paths injection — and delivers a prioritized fix report in minutes.
Join the waitlist →