Zip Slip is a critical vulnerability that affects how applications extract compressed archive files, allowing attackers to write files outside the intended directory by exploiting path traversal in file names. This can lead to remote code execution, overwriting of critical files, or denial of service, depending on the application’s privileges. The flaw has been found in numerous libraries and tools across multiple programming languages, including Java, .NET, JavaScript, and Python, making it a widespread concern for developers and security teams.
Background: What Is Zip Slip?
Zip Slip is a form of directory traversal attack that exploits the way archive extraction functions handle file names containing path traversal sequences like ../. When an application extracts a ZIP file, it typically creates directories and writes files based on the names stored in the archive. If the extraction code does not validate or sanitize these names, a malicious archive can contain entries like ../../../../tmp/evil.sh, which, when extracted, writes outside the intended extraction directory.
The vulnerability was publicly disclosed in 2018 by Snyk, a security company, after researchers found it in over 100 popular libraries and tools. The term “Zip Slip” was coined to describe this class of vulnerability, which is not limited to ZIP files but can also affect other archive formats like TAR, RAR, and 7z, as long as the extraction logic is vulnerable.
How Zip Slip Works
To understand Zip Slip, you need to know how archive formats store file names. In a ZIP file, each entry has a header that includes the file name, which can contain path separators and directory traversals. For example, an attacker can create a ZIP entry with the name ../../../../bin/evil.sh. When the extraction code does:
- Creates the output path: It concatenates the destination directory with the entry’s file name.
- Writes the file: It writes the file content to that constructed path.
If the code does not check whether the resolved path is still within the destination directory, the file gets written to an arbitrary location on the file system. This is the core of the vulnerability.
For example, consider a web application that allows users to upload a ZIP file and extracts it to /var/www/uploads/. A malicious ZIP entry named ../../../../etc/cron.d/backdoor would cause the extraction to write to /etc/cron.d/backdoor, potentially allowing the attacker to schedule a cron job and gain code execution.
Real-World Impact and Examples
Zip Slip has been found in many widely used libraries, including:
- Java:
commons-compress,zip4j, and the built-injava.util.zip(when used unsafely). - JavaScript:
adm-zip,extract-zip, andunzipper. - Python:
zipfile(when used without proper checks) andtarfile. - .NET:
SharpZipLibandSystem.IO.Compression(in certain versions).
One notable exploit was against the electron-builder tool, which uses adm-zip to extract archives during the build process. An attacker could craft a malicious archive that, when extracted by a developer, overwrites files in the developer’s home directory, leading to code execution on the developer’s machine.
Another example is the tar command in Unix, which has historically had similar path traversal vulnerabilities. Although modern versions of tar have protections, many third-party libraries still lack them.
How to Prevent Zip Slip
Preventing Zip Slip requires careful validation of archive entry names before extraction. Here are the key steps:
- Validate entry names: For each entry, check that the normalized file name does not contain path traversal sequences (e.g.,
../) and that it is not an absolute path. - Use a safe extraction method: Many modern libraries provide built-in safety checks. For example, Java’s
commons-compresshas aZipFileclass that can be used with aZipArchiveEntryand a customFileoutput, but you must still validate the entry name. - Canonicalize the output path: After constructing the full output path, use
getCanonicalPath()(in Java) orrealpath()(in Python) to resolve any symbolic links or relative segments, and then verify that the canonical path is within the intended destination directory. - Use a secure extraction library: Choose libraries that have patched Zip Slip and regularly update them. For instance,
adm-ziphas been patched, andextract-zipnow validates paths.
Here is a simple example in Python using the standard zipfile module safely:
import zipfile
import os
def safe_extract(zip_path, dest_dir):
with zipfile.ZipFile(zip_path, 'r') as zf:
for member in zf.infolist():
# Normalize the path
member_path = os.path.normpath(member.filename)
# Check for traversal
if member_path.startswith('..') or os.path.isabs(member_path):
raise Exception('Illegal filename in archive: ' + member.filename)
# Construct the full path
target = os.path.join(dest_dir, member_path)
# Ensure the target is within dest_dir
if not os.path.realpath(target).startswith(os.path.realpath(dest_dir)):
raise Exception('Illegal path in archive: ' + member.filename)
# Extract
if member.is_dir():
os.makedirs(target, exist_ok=True)
else:
os.makedirs(os.path.dirname(target), exist_ok=True)
with zf.open(member) as src, open(target, 'wb') as dst:
dst.write(src.read())
This code normalizes the file name, checks for traversal, and verifies the canonical path before writing.
Common Misconceptions
One common misconception is that Zip Slip only affects web applications. In reality, any application that extracts archives—desktop software, mobile apps, build tools, or server-side services—can be vulnerable if it uses an unsafe extraction method.
Another misconception is that the vulnerability is only exploitable if the attacker can upload a ZIP file directly. However, Zip Slip can also be triggered by downloading and extracting a malicious archive from a remote source, or even by a user manually extracting a file they received via email.
Some developers believe that checking for ../ in the file name is sufficient. But this is not enough because an attacker can use URL-encoded sequences (%2e%2e%2f) or backslashes on Windows (..\). Always use canonical path checks.
Comparison with Similar Vulnerabilities
Zip Slip is part of a broader family of path traversal vulnerabilities, often referred to as “directory traversal” or “path traversal.” These include:
- Path Traversal in HTTP requests: Like
../../etc/passwdin URL parameters, which can allow reading arbitrary files. - TAR Slip: A similar vulnerability in TAR archive extraction, which has been known for decades.
- Symlink attacks: When an archive contains a symbolic link that points outside the extraction directory, and the extraction follows the link.
Zip Slip is distinct because it specifically targets archive extraction logic, but the underlying principle is the same: insufficient validation of user-controlled file paths.
Costs and Consequences
The consequences of a Zip Slip exploit can be severe:
- Remote Code Execution: If the attacker can write to a location that is later executed (e.g., a web server’s script directory), they can gain full control of the system.
- Data Corruption: Overwriting configuration files, databases, or user data can lead to service disruption or data loss.
- Privilege Escalation: Writing to system directories (like
/etc/cron.d/) can allow an attacker to gain higher privileges. - Supply Chain Attacks: Compromising build tools or package managers can distribute malicious code to many downstream users.
The cost of fixing a Zip Slip vulnerability after deployment includes emergency patches, potential data breach notifications, and reputational damage. The cost of prevention is relatively low: a few lines of validation code in the extraction routine.
Alternatives and Best Practices
Instead of writing your own extraction logic, consider using a well-maintained library that has built-in protection against Zip Slip. For example:
- Java: Use
ZipFilewith a customFileoutput and validate entry names, or use a library liketruezipwhich has path validation. - Python: The standard
zipfilemodule does not validate paths by default, but you can use theextractallmethod with a customfilter(Python 3.6+) that checks for traversal. - JavaScript: Use
extract-zipversion 2.0+ which has path validation, oryauzlwhich does not automatically extract but gives you control.
Always follow the principle of least privilege: run extraction processes with minimal permissions so that even if a Zip Slip occurs, the attacker cannot write to sensitive locations. Additionally, consider using a sandboxed environment for extracting untrusted archives.
Frequently Asked Questions
What is Zip Slip in simple terms?
Zip Slip is a security flaw where a malicious ZIP file can trick a program into writing files outside the folder it was supposed to extract to, potentially overwriting important system files or installing malware.
Is Zip Slip still a problem in 2025?
Yes, while many libraries have been patched, new code is still written with vulnerable extraction logic, and older applications may not be updated. It remains a common finding in security audits.
How can I check if my application is vulnerable to Zip Slip?
Review your code that extracts archives. If you do not validate the file names or use a library that does, you are likely vulnerable. You can also use automated security scanners that test for path traversal.
Can Zip Slip affect ZIP files only?
No, the same vulnerability applies to other archive formats like TAR, RAR, and 7z. The term “Zip Slip” is used generically, but the principle is the same.
What should I do if I find Zip Slip in my application?
Immediately update any vulnerable libraries, add path validation to your extraction code, and review any archives that have already been processed for signs of tampering. Also, consider rotating credentials that might have been exposed.
Related
Formula used
in t | Input Type | - | 1 | 1 | 2 sel s | Severity | Low=1, Medium=2, High=3, Critical=4 | 4 out risk | Risk Score | - | s * t | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Mac Start Up Automatically After Power Failure?
- Expose Self-Hosted Service Securely Without Cloudflare Tunnel
- Nano Delivery for Functional Foods: What It Can and Can’t Do4.00
- Disable Apple Watch Turn-by-Turn Vibration While Driving
- Convert Play FLAC in iTunes: Full Guide
- Soda Foundation Charter: What It Means