← Blog

Zip Slip and Archive Extraction Security in Claude Skills

Claude skills that accept uploaded ZIP, tar, or tar.gz archives face a class of vulnerabilities that have no equivalent in skills that handle only JSON or plain text. Zip slip writes files outside the extraction sandbox. Symlink entries redirect writes to arbitrary filesystem locations. Decompression bombs exhaust disk space. Absolute-path tar entries overwrite system files. All four can be triggered by a single malicious archive that an LLM agent passes to an extraction tool.

By SkillAudit  |  6 Nov 2026

Why archive extraction is a distinct concern for MCP skills

An MCP skill that extracts archives often runs with elevated filesystem permissions — it needs to write to a working directory, create nested subdirectories, and potentially execute extracted scripts. The LLM agent calling the skill cannot inspect the archive contents before passing the path to the tool. If a user uploads a malicious archive and the LLM is instructed to extract it, every entry in that archive becomes an attack vector. The skill developer must validate every entry path, every symlink target, every uncompressed size, and every entry type before writing a single byte to disk.

SA-SKL-ZIPSLIP in scope: ZIPSLIP-001 path traversal via ../.. sequences in ZIP entry names, ZIPSLIP-002 symlink entries in archive followed silently to overwrite arbitrary files, ZIPSLIP-003 decompression bomb exhausts disk or memory without size check, ZIPSLIP-004 absolute-path tar entries extracted to filesystem root.

ZIPSLIP-001 — Classic zip slip path traversal

Zip slip is an archive path traversal vulnerability disclosed by Snyk in 2018 and still found in production code. An attacker crafts a ZIP archive containing one or more entries with names that include directory traversal sequences: ../../etc/cron.d/backdoor, ../../../root/.ssh/authorized_keys. When a skill calls zip.extractAllTo(outputDir) or iterates entries and writes them with the entry's name, those sequences are resolved relative to the output directory, escaping the sandbox. If the process runs as root or a privileged user, the attacker gains arbitrary file write anywhere on the filesystem.

// VULNERABLE — entry names used directly; no path traversal check before extraction
import AdmZip from 'adm-zip';
import path from 'node:path';

server.tool(
  'extract_archive',
  { archivePath: z.string(), outputDir: z.string() },
  async ({ archivePath, outputDir }) => {
    const zip = new AdmZip(archivePath);

    // extractAllTo uses entry.entryName verbatim relative to outputDir
    // Entry "../../etc/cron.d/backdoor" extracts to /etc/cron.d/backdoor
    // Entry "../.ssh/authorized_keys"   extracts to ~/.ssh/authorized_keys
    zip.extractAllTo(outputDir, /* overwrite */ true);

    return { extracted: zip.getEntries().length };
  }
);
// FIXED — resolve each entry path and verify it stays inside outputDir
import AdmZip from 'adm-zip';
import path from 'node:path';
import fs from 'node:fs/promises';

const SAFE_OUTPUT_ROOT = '/tmp/skill-extractions';

server.tool(
  'extract_archive',
  { archivePath: z.string() },
  async ({ archivePath }) => {
    // Resolve the extraction root — always use a fixed safe base, not caller-supplied outputDir
    const outputDir = path.resolve(SAFE_OUTPUT_ROOT, path.basename(archivePath, '.zip'));
    await fs.mkdir(outputDir, { recursive: true });

    const zip = new AdmZip(archivePath);
    const entries = zip.getEntries();
    let extracted = 0;

    for (const entry of entries) {
      if (entry.isDirectory) continue;

      // Resolve the final path and assert it is inside outputDir
      const entryPath = path.resolve(outputDir, entry.entryName);
      const safeRoot = path.resolve(outputDir) + path.sep;

      if (!entryPath.startsWith(safeRoot)) {
        throw new Error(
          `ZIP_SLIP: entry "${entry.entryName}" resolves outside extraction directory`
        );
      }

      // Create parent dirs safely (they may also include traversal in deeply nested entries)
      await fs.mkdir(path.dirname(entryPath), { recursive: true });
      await fs.writeFile(entryPath, entry.getData());
      extracted++;
    }

    return { extracted, outputDir };
  }
);
CRITICAL
SA-SKL-ZIPSLIP-001 — ZIP entries extracted using raw entry.entryName without path traversal validation; entries containing ../../ sequences write files outside the intended extraction directory, enabling arbitrary file write on the host filesystem.

ZIPSLIP-002 — Symlink entries inside archive followed silently

Beyond path traversal in names, ZIP and tar archives can contain entries of type symlink. When a skill extracts a symlink entry and then extracts a subsequent data entry whose name matches the symlink, the data is written to the symlink's target — not the symlink itself. An attacker crafts an archive with two entries: a symlink output/results.json pointing to /etc/passwd, followed by a regular file also named output/results.json containing malicious content. Many extraction libraries follow the symlink transparently and overwrite the target file. The check must happen after writing: use fs.lstat() to detect whether the final path is a symlink and reject entries that resolve outside the sandbox via a symlink chain.

// VULNERABLE — symlink entries created verbatim; subsequent data entry follows symlink to target
import yauzl from 'yauzl';
import fs from 'node:fs';
import path from 'node:path';

server.tool(
  'extract_zip_stream',
  { archivePath: z.string() },
  async ({ archivePath }) => {
    const outputDir = '/tmp/extracted';

    return new Promise((resolve, reject) => {
      yauzl.open(archivePath, { lazyEntries: true }, (err, zipfile) => {
        if (err) return reject(err);
        zipfile.readEntry();
        zipfile.on('entry', (entry) => {
          const destPath = path.join(outputDir, entry.fileName);

          if (/\/$/.test(entry.fileName)) {
            fs.mkdirSync(destPath, { recursive: true });
            zipfile.readEntry();
          } else {
            // No symlink check — if entry is a symlink, fs.createWriteStream follows it
            zipfile.openReadStream(entry, (err2, readStream) => {
              if (err2) return reject(err2);
              const writeStream = fs.createWriteStream(destPath);
              readStream.pipe(writeStream);
              writeStream.on('finish', () => zipfile.readEntry());
              writeStream.on('error', reject);
            });
          }
        });
        zipfile.on('end', () => resolve({ done: true }));
        zipfile.on('error', reject);
      });
    });
  }
);
// FIXED — detect and reject symlink entries; verify final path is not a symlink after write
import yauzl from 'yauzl';
import fs from 'node:fs';
import fsp from 'node:fs/promises';
import path from 'node:path';

const OUTPUT_ROOT = '/tmp/extracted';

// ZIP external file attributes: Unix mode in high 16 bits; symlink = 0xa000
function isSymlinkEntry(entry: yauzl.Entry): boolean {
  const unixMode = (entry.externalFileAttributes >> 16) & 0xffff;
  return (unixMode & 0xf000) === 0xa000;
}

server.tool(
  'extract_zip_stream',
  { archivePath: z.string() },
  async ({ archivePath }) => {
    const safeRoot = path.resolve(OUTPUT_ROOT) + path.sep;
    await fsp.mkdir(OUTPUT_ROOT, { recursive: true });

    return new Promise((resolve, reject) => {
      yauzl.open(archivePath, { lazyEntries: true }, (err, zipfile) => {
        if (err) return reject(err);
        zipfile.readEntry();

        zipfile.on('entry', async (entry) => {
          try {
            // Reject symlink entries unconditionally
            if (isSymlinkEntry(entry)) {
              return reject(new Error(`SYMLINK_REJECTED: entry "${entry.fileName}" is a symlink`));
            }

            const destPath = path.resolve(OUTPUT_ROOT, entry.fileName);

            // Zip slip check — entry name must resolve inside extraction root
            if (!destPath.startsWith(safeRoot)) {
              return reject(new Error(`ZIP_SLIP: entry "${entry.fileName}" escapes output dir`));
            }

            if (/\/$/.test(entry.fileName)) {
              await fsp.mkdir(destPath, { recursive: true });
              return zipfile.readEntry();
            }

            await fsp.mkdir(path.dirname(destPath), { recursive: true });

            zipfile.openReadStream(entry, async (err2, readStream) => {
              if (err2) return reject(err2);
              const writeStream = fs.createWriteStream(destPath);
              readStream.pipe(writeStream);
              writeStream.on('finish', async () => {
                // Post-write lstat: reject if symlink was created by a race or library quirk
                const stat = await fsp.lstat(destPath);
                if (stat.isSymbolicLink()) {
                  await fsp.unlink(destPath);
                  return reject(new Error(`SYMLINK_POST_WRITE: "${entry.fileName}" is a symlink`));
                }
                zipfile.readEntry();
              });
              writeStream.on('error', reject);
            });
          } catch (e) {
            reject(e);
          }
        });

        zipfile.on('end', () => resolve({ done: true }));
        zipfile.on('error', reject);
      });
    });
  }
);
HIGH
SA-SKL-ZIPSLIP-002 — Archive extraction does not check entry external file attributes for symlink type; a symlink entry pointing to an arbitrary filesystem path followed by a data entry with the same name silently overwrites the symlink target outside the extraction sandbox.

ZIPSLIP-003 — Decompression bomb exhausts disk space or memory

A decompression bomb is an archive that compresses with an extreme ratio. The classic flat bomb is a single ZIP entry containing several gigabytes of repeating null bytes (which DEFLATE compresses to a few kilobytes). When a skill extracts it without checking the uncompressed size first, the extraction process writes gigabytes to disk, filling the filesystem and causing the entire server to fail. The ZIP format stores each entry's uncompressed size in the central directory, so it is possible to check the total uncompressed volume before writing any bytes. For tar.gz, gzip does not reliably store uncompressed size, so a streaming byte counter is required instead.

// VULNERABLE — extracts without any uncompressed size check; decompression bomb detonates
import AdmZip from 'adm-zip';

server.tool(
  'process_submission',
  { archivePath: z.string() },
  async ({ archivePath }) => {
    const zip = new AdmZip(archivePath);

    // A 42 KB zip containing a 10 GB all-zeros entry fills the disk here
    // No size check, no entry count limit, no compression ratio guard
    zip.extractAllTo('/tmp/submissions/', true);

    return { status: 'extracted' };
  }
);
// FIXED — check uncompressed size and compression ratio before extracting any entry
import AdmZip from 'adm-zip';
import path from 'node:path';
import fs from 'node:fs/promises';

const MAX_UNCOMPRESSED_BYTES = 100 * 1_048_576;  // 100 MB total
const MAX_ENTRY_COUNT        = 1_000;             // cap number of files
const MAX_COMPRESSION_RATIO  = 100;              // flag >100:1 as suspicious
const SAFE_EXTRACT_ROOT      = '/tmp/submissions';

server.tool(
  'process_submission',
  { archivePath: z.string() },
  async ({ archivePath }) => {
    const zip = new AdmZip(archivePath);
    const entries = zip.getEntries();

    if (entries.length > MAX_ENTRY_COUNT) {
      throw new Error(
        `ZIP_ENTRY_LIMIT: ${entries.length} entries exceeds maximum of ${MAX_ENTRY_COUNT}`
      );
    }

    let totalUncompressed = 0;

    for (const entry of entries) {
      const uncompressed = entry.header.size;
      const compressed   = entry.header.compressedSize;

      // Decompression bomb check: flag implausibly high compression ratios
      if (compressed > 0 && uncompressed / compressed > MAX_COMPRESSION_RATIO) {
        throw new Error(
          `ZIP_BOMB_SUSPECTED: entry "${entry.entryName}" has ` +
          `${Math.round(uncompressed / compressed)}:1 compression ratio`
        );
      }

      totalUncompressed += uncompressed;

      if (totalUncompressed > MAX_UNCOMPRESSED_BYTES) {
        throw new Error(
          `ZIP_SIZE_LIMIT: cumulative uncompressed size ` +
          `${Math.round(totalUncompressed / 1_048_576)} MB exceeds 100 MB limit`
        );
      }
    }

    // All entries passed size checks — now extract with zip slip protection
    const outputDir = path.join(SAFE_EXTRACT_ROOT, path.basename(archivePath, '.zip'));
    await fs.mkdir(outputDir, { recursive: true });
    const safeRoot = path.resolve(outputDir) + path.sep;

    for (const entry of entries) {
      if (entry.isDirectory) continue;
      const destPath = path.resolve(outputDir, entry.entryName);
      if (!destPath.startsWith(safeRoot)) {
        throw new Error(`ZIP_SLIP: entry "${entry.entryName}" escapes extraction directory`);
      }
      await fs.mkdir(path.dirname(destPath), { recursive: true });
      await fs.writeFile(destPath, entry.getData());
    }

    return { extracted: entries.length, outputDir };
  }
);

tar.gz streaming guard: For gzip-compressed tar archives, pipe through a counting Transform stream that throws when cumulative decompressed bytes exceed the limit. See the decompression bomb reference for a complete streaming implementation using Node.js zlib.createGunzip() and a passthrough byte counter.

HIGH
SA-SKL-ZIPSLIP-003 — Archive extracted without reading entry uncompressed sizes from the ZIP central directory first; a decompression bomb with 100:1+ compression ratio exhausts available disk space and may crash the server or fill the filesystem for other tenants.

ZIPSLIP-004 — Absolute path entries in tar archives

Unlike ZIP, the tar format allows entry names to begin with a leading slash, making them absolute paths: /etc/sudoers, /root/.bashrc, or on Windows C:\Windows\System32\drivers\etc\hosts. Node.js's built-in tar module historically stripped leading slashes by default, but the behavior is version-dependent and can be overridden. The tar-fs package does not strip leading slashes at all unless configured to do so via the map option. A skill that pipes a tar stream through tar.extract() without explicit path normalization will write absolute-path entries to their literal filesystem locations when the extraction process has sufficient privilege.

// VULNERABLE — tar-fs extracts absolute-path entries to their literal filesystem locations
import tarFs from 'tar-fs';
import fs from 'node:fs';

server.tool(
  'extract_tar',
  { archivePath: z.string() },
  async ({ archivePath }) => {
    const outputDir = '/tmp/tar-output';

    return new Promise((resolve, reject) => {
      // tar-fs default: does NOT strip leading slashes
      // Entry "/etc/sudoers" extracts to /etc/sudoers if process is root
      fs.createReadStream(archivePath)
        .pipe(tarFs.extract(outputDir))
        .on('finish', () => resolve({ done: true }))
        .on('error', reject);
    });
  }
);
// FIXED — use map option to strip leading slashes; filter to reject remaining absolute paths
import tarFs from 'tar-fs';
import fs from 'node:fs';
import path from 'node:path';

const SAFE_TAR_ROOT = '/tmp/tar-output';

server.tool(
  'extract_tar',
  { archivePath: z.string() },
  async ({ archivePath }) => {
    const safeRoot = path.resolve(SAFE_TAR_ROOT) + path.sep;
    await fs.promises.mkdir(SAFE_TAR_ROOT, { recursive: true });

    return new Promise((resolve, reject) => {
      fs.createReadStream(archivePath)
        .pipe(
          tarFs.extract(SAFE_TAR_ROOT, {
            // map: normalize entry headers before extraction
            map(header) {
              // Strip leading slashes and Windows drive letters
              header.name = header.name
                .replace(/^([A-Za-z]:)?[/\\]+/, '')  // remove C:\ or /
                .replace(/\.\.(\/|\\|$)/g, '');       // remove ../ traversal

              return header;
            },
            // filter: reject any entry whose resolved path still escapes safeRoot
            filter(filePath) {
              const resolved = path.resolve(SAFE_TAR_ROOT, filePath);
              if (!resolved.startsWith(safeRoot)) {
                // Emit warning but do not throw — just skip the dangerous entry
                console.warn(`TAR_PATH_REJECTED: "${filePath}" resolves outside output dir`);
                return false;
              }
              return true;
            },
            // Reject symlink entries in the tar archive (same risk as ZIP symlinks)
            dmode: 0o755,
            fmode: 0o644,
          })
        )
        .on('finish', () => resolve({ done: true, outputDir: SAFE_TAR_ROOT }))
        .on('error', reject);
    });
  }
);

Node.js tar module note: The npm tar package (not tar-fs) strips leading slashes by default since v4, but this behavior can be disabled via the preservePaths: true option. Never pass preservePaths: true in production code. Always combine path normalization with a filter callback that verifies the resolved output path remains inside the extraction root, as a defense-in-depth measure against future option changes or library upgrades.

MEDIUM
SA-SKL-ZIPSLIP-004 — tar archive extracted via tar-fs without map or filter options; entries with absolute path names (e.g., /etc/sudoers) or Windows drive-letter prefixes (C:\...) are written to their literal filesystem locations rather than relative to the extraction output directory.