Course contentsShow
← Security
Lesson 974 of 3,05220. Web Security - File Upload and ProcessingFree lesson

ZIP Slip and Archive Extraction Attacks

Learn about directory traversal during archive extraction and how to prevent path manipulation.

ZIP Slip and Archive Extraction Attacks

You'll learn how attackers can escape extraction directories by hiding malicious paths inside archive files, and how to prevent this dangerous vulnerability.

What is ZIP Slip?

ZIP Slip is a directory traversal vulnerability that occurs during the extraction of archive files (ZIP, TAR, etc.). When an application extracts an archive without validating the file paths inside, attackers can craft malicious archives containing filenames with path traversal sequences like ../../ that escape the intended extraction directory.

Think of it like this: You ask someone to unpack boxes only in your garage, but they've labeled items with addresses that lead them to place things throughout your entire house—including sensitive areas like your bedroom or safe.

How the Attack Works

An attacker creates an archive containing entries with paths like:

  • ../../etc/passwd
  • ../../../../var/www/html/shell.php
  • ..\..\..\Windows\System32\malicious.dll

When extracted without validation, these files are written to locations outside the intended directory. This can lead to:

  • Arbitrary file overwrite (replacing system files, configuration files)
  • Remote code execution (placing web shells in web roots)
  • Privilege escalation (modifying startup scripts or binaries)

Prevention Essentials

Before writing each extracted file:

  1. Canonicalize the full target path (resolve all . and .. components)
  2. Verify it starts with your intended extraction directory
  3. Reject any file that would write outside that boundary
  4. Check for symbolic links that might redirect extraction elsewhere

Never trust archive filenames directly—always validate and sanitize the final destination path.

Key Takeaway: ZIP Slip exploits unchecked file paths during extraction to write files anywhere on the system; always canonicalize and validate that extracted file paths remain within your intended directory before writing them.