← Blog

Claude MCP skill path traversal via archive extraction — unzip, tar, JSZip, symlink — SA-SKL-UPLOAD9

Archive extraction path traversal — the Zip Slip class of vulnerabilities — occurs when an MCP skill extracts uploaded ZIP, TAR, or other archive formats without validating that extracted entry paths remain within the intended target directory. Archive entries carry filenames stored inside the archive, and those filenames can contain ../ sequences, leading slashes, or symlinks that point to files outside the extraction directory. Four SA-SKL-UPLOAD9 patterns cover the most common variants: unzip without path normalization, tar extraction accepting absolute paths, JSZip overwrites of application source files, and symlinks that transparently redirect reads to system files after extraction.

By SkillAudit  |  9 Nov 2026
SA-SKL-UPLOAD9 findings at a glance
CRITICALUPLOAD9-001 — unzip.Extract to target directory using entry.path without path.resolve() normalisation; entry path ../../etc/cron.d/evil escapes target directory on extraction; arbitrary file write achieves RCE
CRITICALUPLOAD9-002 — tar.x() with no filter on entry.path; tarball entry with path starting with / (absolute path) writes directly to absolute filesystem location; overwrites system files or application binaries
CRITICALUPLOAD9-003 — JSZip forEach with zip.file(entryName) writes entryName as relative path; entryName = "../../../app/routes/admin.js" overwrites application source file on disk; next HTTP request executes attacker's code
HIGHUPLOAD9-004 — Symlink in archive extracted without check; symlink target is /etc/passwd; subsequent read of "extracted" file transparently reads /etc/passwd; write of "extracted" file overwrites /etc/passwd

UPLOAD9-001 — unzip.Extract without path.resolve validation

The unzipper npm package's Extract API writes each entry to a path formed by joining the output directory with the entry's stored filename. It does not validate that the resulting path stays within the output directory. An entry named ../../etc/cron.d/evil combined with an output directory of /tmp/extractions/upload-123 resolves to /etc/cron.d/evil — outside the intended extraction directory. Writing a valid cron job line to this path achieves remote code execution within 60 seconds as the cron daemon picks up the new file.

// VULNERABLE — UPLOAD9-001 (CRITICAL)
// unzipper.Extract does not validate entry.path against output directory.
// Entry named "../../etc/cron.d/evil" escapes to /etc/cron.d/evil.
import unzipper from 'unzipper';
import path from 'path';
import { promises as fs } from 'fs';

const OUTPUT_BASE = '/tmp/extractions';

export async function extractUpload(zipBuffer: Buffer, uploadId: string): Promise<void> {
  const outputDir = path.join(OUTPUT_BASE, uploadId);
  await fs.mkdir(outputDir, { recursive: true });

  // VULNERABLE: Extract API uses entry.path verbatim relative to outputDir
  // path.join('/tmp/extractions/upload-123', '../../etc/cron.d/evil')
  // = '/etc/cron.d/evil' on POSIX systems — outside outputDir
  await new Promise<void>((resolve, reject) => {
    unzipper.Open.buffer(zipBuffer).then((zip) => {
      zip.extract({ path: outputDir }).on('close', resolve).on('error', reject);
    });
  });
}
// FIXED — UPLOAD9-001
// path.resolve() collapses all ../ sequences; assertion blocks extraction outside target.
import unzipper from 'unzipper';
import path from 'path';
import { promises as fs } from 'fs';

const OUTPUT_BASE = path.resolve('/tmp/extractions');
const MAX_ENTRIES = 500;
const MAX_TOTAL_BYTES = 50 * 1024 * 1024;  // 50 MB decompressed limit

export async function extractUpload(zipBuffer: Buffer, uploadId: string): Promise<void> {
  const outputDir = path.resolve(OUTPUT_BASE, uploadId);
  await fs.mkdir(outputDir, { recursive: true });

  const zip = await unzipper.Open.buffer(zipBuffer);

  if (zip.files.length > MAX_ENTRIES) {
    throw new Error(`Too many archive entries: ${zip.files.length}`);
  }

  let totalBytes = 0;

  for (const entry of zip.files) {
    // path.resolve collapses ../../ sequences completely in one step
    const resolved = path.resolve(outputDir, entry.path);

    // Assertion: extracted path must be inside outputDir
    if (!resolved.startsWith(outputDir + path.sep) && resolved !== outputDir) {
      throw new Error(`Path traversal in archive entry: ${entry.path}`);
    }

    const content = await entry.buffer();
    totalBytes += content.length;
    if (totalBytes > MAX_TOTAL_BYTES) {
      throw new Error('Archive decompressed size limit exceeded');
    }

    await fs.mkdir(path.dirname(resolved), { recursive: true });
    await fs.writeFile(resolved, content);
  }
}

UPLOAD9-002 — tar.x() accepting absolute paths

TAR archives can contain entries with paths starting with a forward slash (/), representing absolute filesystem paths. The tar npm package's x (extract) function accepts these by default if no filter callback is provided. An entry with path /etc/cron.d/evil writes directly to /etc/cron.d/evil regardless of the cwd option, because the absolute path takes precedence. Similarly, an entry with path /app/index.js overwrites the running application's entry point, achieving code execution on the next request.

// VULNERABLE — UPLOAD9-002 (CRITICAL)
// tar.x() with no filter — absolute path entries write to arbitrary filesystem locations.
import tar from 'tar';
import path from 'path';

const EXTRACT_DIR = '/tmp/tar-extractions';

export async function extractTarball(tarBuffer: Buffer, uploadId: string): Promise<void> {
  const outputDir = path.join(EXTRACT_DIR, uploadId);

  // VULNERABLE: no filter callback — absolute paths like /etc/cron.d/evil
  // are written directly to their absolute location, ignoring cwd
  await tar.x({
    cwd: outputDir,
    // No filter — accepts all entry types including absolute paths and symlinks
  }, [tarBuffer]);  // Note: tar also accepts stream input
}
// FIXED — UPLOAD9-002
// filter callback rejects absolute paths, symlinks, and traversal sequences.
import tar from 'tar';
import path from 'path';
import { promises as fs } from 'fs';

const EXTRACT_DIR = path.resolve('/tmp/tar-extractions');

export async function extractTarball(tarBuffer: Buffer, uploadId: string): Promise<void> {
  const outputDir = path.resolve(EXTRACT_DIR, uploadId);
  await fs.mkdir(outputDir, { recursive: true });

  await tar.x({
    cwd: outputDir,
    filter: (entryPath, entry) => {
      // FIX 1: reject absolute paths
      if (path.isAbsolute(entryPath)) {
        return false;
      }
      // FIX 2: reject symlinks — symlink-based extraction bypass is a separate attack
      if (entry.type === 'SymbolicLink' || entry.type === 'Link') {
        return false;
      }
      // FIX 3: resolve and check stays inside outputDir
      const resolved = path.resolve(outputDir, entryPath);
      if (!resolved.startsWith(outputDir + path.sep)) {
        return false;
      }
      return true;
    },
  });
}

UPLOAD9-003 — JSZip forEach entryName overwrites application source

The JSZip library represents a ZIP archive as a JavaScript object where each key is the entry filename and the value is the entry data. When iterating with forEach and writing entries using the entry name as a relative path, an entry named ../../../app/routes/admin.js resolves relative to the extraction directory and can overwrite application source files outside the extraction directory. If the application uses require() or dynamic imports with module hot-reloading, the overwritten file is loaded on the next request or reload cycle, executing the attacker's code in the application process with full Node.js capabilities.

// VULNERABLE — UPLOAD9-003 (CRITICAL)
// JSZip forEach writes entryName as relative path — no normalisation.
// entryName = "../../../app/routes/admin.js" overwrites application source.
import JSZip from 'jszip';
import path from 'path';
import { promises as fs } from 'fs';

const EXTRACT_DIR = '/var/uploads/extracted';

export async function extractZip(zipBuffer: Buffer, uploadId: string): Promise<void> {
  const zip = await JSZip.loadAsync(zipBuffer);
  const outputDir = path.join(EXTRACT_DIR, uploadId);
  await fs.mkdir(outputDir, { recursive: true });

  const writes: Promise<void>[] = [];

  zip.forEach((relativePath, zipEntry) => {
    if (!zipEntry.dir) {
      // VULNERABLE: relativePath may be "../../../app/routes/admin.js"
      // path.join does NOT prevent traversal — it concatenates literally
      const outputPath = path.join(outputDir, relativePath);
      writes.push(
        zipEntry.async('nodebuffer').then(content => fs.writeFile(outputPath, content))
      );
    }
  });

  await Promise.all(writes);
}
// FIXED — UPLOAD9-003
// path.resolve() normalises all traversal; assert stays within outputDir.
import JSZip from 'jszip';
import path from 'path';
import { promises as fs } from 'fs';

const EXTRACT_DIR = path.resolve('/var/uploads/extracted');

export async function extractZip(zipBuffer: Buffer, uploadId: string): Promise<void> {
  const zip = await JSZip.loadAsync(zipBuffer);
  const outputDir = path.resolve(EXTRACT_DIR, uploadId);
  await fs.mkdir(outputDir, { recursive: true });

  const writes: Promise<void>[] = [];

  zip.forEach((relativePath, zipEntry) => {
    if (!zipEntry.dir) {
      // FIX: path.resolve collapses all ../ traversal sequences
      const outputPath = path.resolve(outputDir, relativePath);

      // Assert: resolved path must be inside outputDir
      if (!outputPath.startsWith(outputDir + path.sep)) {
        // Skip this entry silently or throw — do NOT write it
        return;
      }

      writes.push(
        zipEntry.async('nodebuffer').then(async (content) => {
          await fs.mkdir(path.dirname(outputPath), { recursive: true });
          await fs.writeFile(outputPath, content);
        })
      );
    }
  });

  await Promise.all(writes);
}

UPLOAD9-004 — Symlink in archive extracted without validation

ZIP and TAR archives can contain symbolic link entries. When these are extracted without validation, the symlink is created on the filesystem pointing to whatever target is stored in the archive entry — including /etc/passwd, /var/run/docker.sock, or any other privileged file. After extraction, any subsequent read of the "uploaded file" transparently reads the symlink target. Any write to it transparently overwrites the symlink target. This turns a file upload into an arbitrary file read/write without requiring any path traversal characters in the entry name — the entry name might be preview.jpg and it still escapes the extraction directory because it is a symlink to /etc/passwd.

// VULNERABLE — UPLOAD9-004 (HIGH)
// Symlinks extracted without validation — symlink target /etc/passwd exposed.
// entry.type === 'SymbolicLink' but no check is performed.
import tar from 'tar';
import path from 'path';

export async function extractUserUpload(stream: NodeJS.ReadableStream, outputDir: string) {
  await tar.x({
    cwd: outputDir,
    // VULNERABLE: no filter — symlink entries are extracted as-is
    // A symlink entry named "preview.jpg" pointing to "/etc/passwd"
    // creates /outputDir/preview.jpg -> /etc/passwd on disk.
    // Any subsequent read of preview.jpg reads /etc/passwd.
  }, stream);
}
// FIXED — UPLOAD9-004
// Reject all symlink and hardlink entries before extraction.
// Post-extraction check for symlinks that escaped validation.
import tar from 'tar';
import path from 'path';
import { promises as fs } from 'fs';

export async function extractUserUpload(
  stream: NodeJS.ReadableStream,
  outputDir: string
): Promise<void> {
  const resolvedOutputDir = path.resolve(outputDir);

  await tar.x({
    cwd: resolvedOutputDir,
    filter: (entryPath, entry) => {
      // FIX 1: reject all symlinks and hardlinks before extraction
      if (entry.type === 'SymbolicLink' || entry.type === 'Link') {
        return false;
      }
      // FIX 2: also reject path traversal and absolute paths
      if (path.isAbsolute(entryPath)) return false;
      const resolved = path.resolve(resolvedOutputDir, entryPath);
      if (!resolved.startsWith(resolvedOutputDir + path.sep)) return false;
      return true;
    },
  }, stream);

  // FIX 3: post-extraction symlink verifier — catches any that slipped through
  const files = await fs.readdir(resolvedOutputDir, { recursive: true });
  for (const file of files) {
    const fullPath = path.join(resolvedOutputDir, file as string);
    const stat = await fs.lstat(fullPath);
    if (stat.isSymbolicLink()) {
      // Remove any symlink found after extraction — should not exist if filter worked
      await fs.unlink(fullPath);
    }
  }
}

SkillAudit detection: SA-SKL-UPLOAD9 flags unzipper.Extract, tar.x(), and JSZip.forEach() calls that use archive entry names as output paths without a path.resolve() + startsWith(outputDir) assertion. Symlink extraction vulnerabilities are detected by checking for missing entry.type === 'SymbolicLink' rejection in filter callbacks. Run a free audit at skillaudit.dev.

PatternCVSSImpactFix
UPLOAD9-001 unzip traversal9.8 CriticalArbitrary file write → cron RCEpath.resolve() + startsWith(outputDir) assertion
UPLOAD9-002 tar absolute path9.8 CriticalWrite to absolute filesystem pathfilter callback rejecting path.isAbsolute() entries
UPLOAD9-003 JSZip source overwrite9.8 CriticalApplication source overwrite → code execution on next requestpath.resolve() + startsWith() check in forEach
UPLOAD9-004 symlink extraction7.5 HighArbitrary file read/write via symlink redirectReject SymbolicLink entries in filter; post-extraction symlink scan