Claude MCP skill archive extraction security — ZIP slip, symlink attacks, ZIP bombs, TOCTOU — SA-SKL-UPLOAD16
MCP skill packages are commonly distributed as ZIP or TAR archives containing multiple files: the skill source code, configuration, README, icons, and dependency manifests. When a MCP skill registry extracts these archives server-side — to index the contents, run static analysis, or display the README — it must do so safely. Archive extraction without proper path normalization, symlink resolution, decompression size limits, and directory isolation opens the registry to path traversal, filesystem escape, denial of service, and race conditions. SA-SKL-UPLOAD16 covers the four most dangerous archive extraction vulnerabilities in MCP skill package upload pipelines.
../../etc/passwd as a ZIP entry name; path.join(extractDir, entry.name) resolves outside the extraction directory; file written to /etc/passwd../../etc/shadow; subsequent read of the extracted "file" follows the symlink outside the extraction directory boundary/tmp/extract/ directory; TOCTOU race allows one skill's extraction to overwrite another skill's files between extraction and static analysis readUPLOAD16-001 — ZIP slip path traversal
ZIP slip is a path traversal vulnerability in ZIP archive extraction. ZIP archives store file entries with arbitrary path strings, including relative components like ../../. When a backend extracts a ZIP using path.join(extractionDirectory, entry.name) without first verifying that the resolved path remains within the extraction directory, an entry named ../../server/routes/auth.js will be written to /tmp/extract/../../server/routes/auth.js, which resolves to the application source directory. The attacker can overwrite any file the extraction process has write permission to — including application source, SSH authorized_keys, or cron jobs.
// UPLOAD16-001 — VULNERABLE
// ZIP extraction uses path.join without boundary check — ZIP slip attack.
import AdmZip from 'adm-zip';
import path from 'node:path';
import fs from 'node:fs/promises';
async function extractSkillPackage(zipBuffer, skillId) {
const extractDir = `/tmp/extract/${skillId}`;
await fs.mkdir(extractDir, { recursive: true });
const zip = new AdmZip(zipBuffer);
const entries = zip.getEntries();
for (const entry of entries) {
// VULNERABLE: entry.entryName may contain ../../ path traversal
// path.join('/tmp/extract/skill123', '../../etc/passwd') = '/etc/passwd'
const outputPath = path.join(extractDir, entry.entryName);
if (entry.isDirectory) {
await fs.mkdir(outputPath, { recursive: true });
} else {
await fs.writeFile(outputPath, entry.getData());
// Attacker's entry '../../server/config.js' overwrites application code
}
}
}
// UPLOAD16-001 — FIXED
// Resolve each entry path and verify it stays within extractDir.
// Use path.resolve (absolute) + startsWith check for boundary enforcement.
import AdmZip from 'adm-zip';
import path from 'node:path';
import fs from 'node:fs/promises';
async function extractSkillPackage(zipBuffer, skillId) {
const extractDir = path.resolve(`/tmp/extract/${skillId}`);
await fs.mkdir(extractDir, { recursive: true });
const zip = new AdmZip(zipBuffer);
const entries = zip.getEntries();
for (const entry of entries) {
// Fix 1: use path.resolve to get the absolute path after joining
const outputPath = path.resolve(extractDir, entry.entryName);
// Fix 2: verify the resolved path starts with extractDir
// path.resolve normalizes .. components — boundary check catches traversal
if (!outputPath.startsWith(extractDir + path.sep) &&
outputPath !== extractDir) {
throw new Error(`ZIP slip detected: entry '${entry.entryName}' escapes extraction dir`);
}
if (entry.isDirectory) {
await fs.mkdir(outputPath, { recursive: true });
} else {
// Fix 3: ensure parent directory exists within boundary
await fs.mkdir(path.dirname(outputPath), { recursive: true });
await fs.writeFile(outputPath, entry.getData());
}
}
}
ZIP slip affects many popular extraction libraries: AdmZip, JSZip, node-tar, and Python's zipfile and tarfile modules all require manual boundary checking — they do not throw errors when entry paths contain ../. The fix is always the same: path.resolve(extractDir, entry.name) + startsWith(extractDir + separator). The trailing separator is critical: startsWith('/tmp/extract/skill123') would pass for /tmp/extract/skill123-evil/. Always append the separator before the check.
UPLOAD16-002 — TAR archive symlink escape
TAR archives support multiple entry types: regular files, directories, and symbolic links (symlinks). A symlink entry contains a link target path — the path that the symlink points to. When a MCP skill registry extracts a TAR archive without filtering symlink entries, an attacker can include a symlink that points outside the extraction directory: link_target = ../../etc/shadow, link_name = skilldata/shadow. The symlink is created within the extraction directory pointing to /etc/shadow. If the registry then reads files from the extraction directory to index contents or run analysis, following the symlink reads /etc/shadow rather than a file in the archive. For registries that serve extracted files via HTTP, following a symlink serves the target file's contents to the requester.
// UPLOAD16-002 — VULNERABLE
// TAR extraction with follow-symlinks — symlink points outside extraction dir.
import tar from 'tar';
async function extractTarPackage(tarBuffer, skillId) {
const extractDir = `/tmp/extract/${skillId}`;
await tar.extract({
cwd: extractDir,
// VULNERABLE: no symlink filtering — attacker's TAR contains:
// type: 'SymbolicLink', name: 'docs/shadow', linkpath: '../../../../etc/shadow'
// After extraction, reading extractDir/docs/shadow reads /etc/shadow
}, tarBuffer);
// UPLOAD16-002 — FIXED
// Validate each TAR entry before extraction — reject symlinks and hard links.
// Use tar.list() to inspect entries before tar.extract().
import tar from 'tar';
import path from 'node:path';
async function validateTarEntries(tarBuffer, extractDir) {
const absExtractDir = path.resolve(extractDir);
return new Promise((resolve, reject) => {
const parser = new tar.Parse();
parser.on('entry', (entry) => {
// Fix 1: reject symlinks and hard links entirely
if (entry.type === 'SymbolicLink' || entry.type === 'Link') {
entry.resume(); // drain the entry
return reject(new Error(`TAR symlink rejected: ${entry.path} -> ${entry.linkpath}`));
}
// Fix 2: ZIP-slip equivalent check for TAR entry paths
const resolved = path.resolve(absExtractDir, entry.path);
if (!resolved.startsWith(absExtractDir + path.sep)) {
entry.resume();
return reject(new Error(`TAR path traversal: ${entry.path}`));
}
entry.resume();
});
parser.on('end', resolve);
parser.on('error', reject);
parser.write(tarBuffer);
parser.end();
});
}
async function extractTarPackage(tarBuffer, skillId) {
const extractDir = path.resolve(`/tmp/extract/${skillId}`);
await fs.mkdir(extractDir, { recursive: true });
// Validate ALL entries before extracting any
await validateTarEntries(tarBuffer, extractDir);
// Safe to extract — no symlinks, no path traversal
await tar.extract({ cwd: extractDir, strip: 0 }, tarBuffer);
}
UPLOAD16-003 — ZIP bomb detection absent
A ZIP bomb is an archive where a small compressed file expands to an enormous uncompressed size. The classic 42.zip is 42KB compressed and expands to 4.5 petabytes. Practical ZIP bombs used in attacks are typically 1KB to 10MB compressed and expand to 1-100GB — enough to fill a server's disk and trigger out-of-memory conditions in a few seconds. The ZIP format stores the uncompressed size of each entry in the central directory at the end of the archive. This metadata can be read without decompressing any data. A safe extraction pipeline checks the total declared uncompressed size before beginning extraction. Note that the declared uncompressed size can itself be forged — the implementation should also enforce a live decompression budget that aborts when the actual bytes written exceed the limit.
// UPLOAD16-003 — VULNERABLE
// No ZIP bomb detection — 1KB compressed archive expands to fill the disk.
import AdmZip from 'adm-zip';
async function extractSkillPackage(zipBuffer, skillId) {
const zip = new AdmZip(zipBuffer);
const entries = zip.getEntries();
// VULNERABLE: no size check before extraction
// 1KB zip with entries declaring 10GB uncompressed fills the server disk
for (const entry of entries) {
if (!entry.isDirectory) {
const data = entry.getData(); // Decompresses entire entry into memory
await fs.writeFile(path.join(extractDir, entry.entryName), data);
}
}
}
// UPLOAD16-003 — FIXED
// Check declared uncompressed size before extraction.
// Enforce live byte budget during extraction — abort on overrun.
import AdmZip from 'adm-zip';
const MAX_UNCOMPRESSED_BYTES = 100 * 1024 * 1024; // 100MB limit
const MAX_ENTRY_COUNT = 1000;
async function extractSkillPackage(zipBuffer, skillId) {
const extractDir = path.resolve(`/tmp/extract/${skillId}`);
await fs.mkdir(extractDir, { recursive: true });
const zip = new AdmZip(zipBuffer);
const entries = zip.getEntries();
// Fix 1: reject archives with too many entries (directory bomb)
if (entries.length > MAX_ENTRY_COUNT) {
throw new Error(`ZIP entry count ${entries.length} exceeds limit ${MAX_ENTRY_COUNT}`);
}
// Fix 2: check declared uncompressed sizes from ZIP central directory
// (fast — does not decompress anything)
const declaredTotal = entries.reduce((sum, e) => sum + e.header.size, 0);
if (declaredTotal > MAX_UNCOMPRESSED_BYTES) {
throw new Error(`ZIP declared uncompressed size ${declaredTotal} exceeds limit`);
}
let bytesWritten = 0;
for (const entry of entries) {
if (entry.isDirectory) {
const dirPath = safeResolvePath(extractDir, entry.entryName);
await fs.mkdir(dirPath, { recursive: true });
continue;
}
const outputPath = safeResolvePath(extractDir, entry.entryName);
const data = entry.getData();
// Fix 3: live byte budget — catches forged declared sizes
bytesWritten += data.byteLength;
if (bytesWritten > MAX_UNCOMPRESSED_BYTES) {
await fs.rm(extractDir, { recursive: true, force: true }); // cleanup
throw new Error(`ZIP extraction exceeded ${MAX_UNCOMPRESSED_BYTES} byte budget`);
}
await fs.mkdir(path.dirname(outputPath), { recursive: true });
await fs.writeFile(outputPath, data);
}
}
Declared sizes in ZIP central directory can be forged: An attacker can craft a ZIP where every entry declares an uncompressed size of 1 byte but actually decompresses to 100MB. The declared-size pre-check is fast but not authoritative. The live byte budget enforced during actual decompression is the authoritative limit. Both checks are needed: the pre-check eliminates obvious bombs early (before any CPU is spent decompressing), and the live budget catches adversarially crafted archives that pass the pre-check. For file type validation bypass patterns in uploaded skill assets, see SA-SKL-UPLOAD15.
UPLOAD16-004 — Shared extraction directory TOCTOU race
When multiple skill package uploads are processed concurrently — a common scenario in a web application handling parallel requests — and all extractions share the same base directory (e.g., /tmp/extract/), a time-of-check-to-time-of-use (TOCTOU) race condition can allow one extraction to interfere with another. If two skills are extracted to /tmp/extract/skill-a/ and /tmp/extract/skill-b/ and one overwrites a file in the other's directory (via a ZIP slip or simply because two extractions race to write the same path), the static analysis engine may read a file from one skill's package and incorrectly attribute it to the other. In audit contexts, this means a malicious skill's code could appear in another skill's audit report, manipulating the audit outcome.
// UPLOAD16-004 — VULNERABLE
// Shared base extraction directory — concurrent extractions can interfere.
async function extractSkillPackage(zipBuffer, skillId) {
// VULNERABLE: skillId is user-supplied or guessable — attacker can predict path
// Two concurrent requests with skillId='../skill-a' and skillId='skill-a' collide
const extractDir = `/tmp/extract/${skillId}`;
await fs.mkdir(extractDir, { recursive: true });
// If two concurrent extractions run with overlapping paths, files interleave
// Static analysis then reads mixed contents from two different skill packages
await extractZip(zipBuffer, extractDir);
return extractDir; // Path is predictable — attacker can stage files here in advance
}
// UPLOAD16-004 — FIXED
// UUID-namespaced extraction directory per upload — not predictable, never shared.
// Cleanup after analysis completes — no persistent /tmp residue.
import { randomUUID } from 'node:crypto';
import { tmpdir } from 'node:os';
async function extractSkillPackage(zipBuffer, skillId) {
// Fix 1: UUID-namespaced extraction directory — unpredictable, isolated per upload
const extractionId = randomUUID();
const extractDir = path.resolve(tmpdir(), 'skillaudit-extract', extractionId);
await fs.mkdir(extractDir, { recursive: true });
try {
await extractZipSafely(zipBuffer, extractDir); // Uses boundary checks from UPLOAD16-001
return extractDir;
} catch (err) {
// Fix 2: clean up on extraction failure — no partial extraction left on disk
await fs.rm(extractDir, { recursive: true, force: true });
throw err;
}
}
// In the caller — always clean up after analysis:
async function analyzeSkillPackage(zipBuffer, skillId) {
const extractDir = await extractSkillPackage(zipBuffer, skillId);
try {
const results = await runStaticAnalysis(extractDir); // Reads only from this UUID dir
return results;
} finally {
// Fix 3: always clean up — even on analysis error — using finally block
await fs.rm(extractDir, { recursive: true, force: true });
}
}
Use os.tmpdir() + UUID for all temporary extraction directories: os.tmpdir() returns the system temporary directory (/tmp on Linux, %TEMP% on Windows). Combining it with a random UUID ensures each extraction is isolated, non-predictable, and cannot be pre-staged by an attacker. Always use a try...finally block to clean up the extraction directory after use — even if the extraction or analysis throws. Leaving temporary directories around leaks skill source code to other processes that can read /tmp and fills the disk over time. For ZIP and TAR extraction in MCP skill CI webhooks, see also the tarball extraction patterns in SA-SKL-SSRF23.
How SkillAudit detects SA-SKL-UPLOAD16
SkillAudit's archive security scanner applies four checks for the SA-SKL-UPLOAD16 family:
- UPLOAD16-001: Finds
path.join(extractDir, entry.name)calls in ZIP extraction loops that are not followed by astartsWith(extractDir + path.sep)boundary check; flags CRITICAL. - UPLOAD16-002: Finds TAR extraction code (
tar.extract(calls) that do not checkentry.type === 'SymbolicLink'before writing; also flags TAR extraction without a pre-pass validation loop; flags HIGH. - UPLOAD16-003: Finds ZIP extraction loops that call
entry.getData()without a preceding check ofentries.reduce((s,e) => s + e.header.size, 0)against a maximum; also flags missing live byte counters; flags HIGH. - UPLOAD16-004: Finds extraction directory construction that uses
skillId,req.params, or any database-derived identifier (rather thanrandomUUID()) as the directory suffix; flags HIGH.
| Pattern | Root cause | Fix | Severity |
|---|---|---|---|
| UPLOAD16-001 | path.join without boundary check — ../../ in ZIP entry name writes outside extractDir | path.resolve + startsWith(extractDir + sep) check; throw on boundary violation | CRITICAL |
| UPLOAD16-002 | TAR symlink entry not filtered — symlink points outside extraction directory | Validate all entries before extracting; reject SymbolicLink and Link types entirely | HIGH |
| UPLOAD16-003 | ZIP central directory size not checked before decompression — ZIP bomb fills disk | Check declared total size; enforce live byte budget; abort and clean up on overrun | HIGH |
| UPLOAD16-004 | Shared /tmp/extract/ directory — TOCTOU race mixes files from concurrent extractions | UUID-namespaced extraction dirs; try/finally cleanup; never use user-supplied paths | HIGH |