# Zip Slip and Archive Extraction
> Archive entry names and link targets are attacker-controlled paths; extracting them without per-entry containment writes files outside the destination, a [[Path Traversal]] variant usually escalating to RCE.
## How it works
- **Entry names.** Zip, tar and similar formats store each member's path as data. An extractor that joins the destination with the entry name and writes, without checking the resolved result, writes wherever the name points. Python's `tarfile.extractall()` did this for 15+ years (CVE-2007-4559); zip has the same class ("zip slip"). [[raw/aikido.dev/python-security-vulnerabilities-top-issues-aikido-2859|Python Security Vulnerabilities - Top Issues - Aikido]]
- **Links inside the archive.** A member can be a symlink or hardlink; a later member written "through" it lands outside the destination even if its own name looks contained. Tools that extract a symlink then write through it are an old pattern (`tar` CVE-2021-32803). [[raw/snyk.io/symlinks-are-still-scary-and-yes-you-can-commit-them-to-git-10268|Symlinks Are Still Scary (And Yes, You Can Commit Them to Git)]]
- **Destination built from user input.** Sometimes the archive is benign and the *directory* is not: Frappe LMS used an unsanitized SCORM chapter title as the extraction path. [[raw/rhinosecuritylabs.com/multiple-vulnerabilities-in-frappe-lms-leading-to-remote-code-executio-12026|Multiple Vulnerabilities in Frappe LMS Leading to Remote Code Execution]]
- **Producer races.** When the archive is generated from a filesystem the attacker controls (a running container), the attacker can change it mid-walk so the archive describes two filesystems; the consumer then follows a planted symlink. [[raw/imperva.com/copyescape-container-to-host-arbitrary-file-write-via-docker-cp-cve-20-11286|CopyEscape: Container-to-host arbitrary file write via docker cp (CVE-2026-17106)]]
- **Filters get bypassed.** Python's `data`/`tar` extraction filters (the post-CVE-2007-4559 fix) have had multiple bypasses: hardlink-to-deeper-symlink (CVE-2026-11940), crafted link entries with empty or directory-like names (CVE-2026-7774), intermediate directories created from the unresolved name (CVE-2026-19672), and a `tar_filter` bypass (CVE-2026-114583). `shutil.unpack_archive()` also mishandled Windows absolute paths. [[raw/stack.watch/python-security-vulnerabilities-in-2026-3395|Python Security Vulnerabilities in 2026]] [[raw/secalerts.co/python-security-vulnerabilities-risk-score-3392|Python Security Vulnerabilities & Risk Score]]
- **Extraction into a code path.** Python's `tarfile`/`zipfile` CLI extracts into the current directory, which `python -m` puts on `sys.path`, so an extracted file can shadow a stdlib module and run on a later error (CVE-2026-115791). [[raw/stack.watch/python-security-vulnerabilities-in-2026-3395|Python Security Vulnerabilities in 2026]]
- **Signed-package assumptions.** Apple PCC's `darwin-init` passed tar entry names straight to libarchive with only metadata-preserving flags and none of libarchive's security flags; the config validator was an empty function and the per-cryptex digest was optional. [[raw/blog.sentry.security/beyond-prompt-injection-hacking-apple-s-private-cloud-compute-11210|Beyond Prompt Injection: Hacking Apple's Private Cloud Compute]]
## What to check
- [ ] Every extraction call: `tarfile.extract*`, `zipfile.extract*`, `shutil.unpack_archive`, libarchive (`archive_write_disk` flags), language-specific unzip helpers, plugin/theme/SCORM/model/package importers, `docker cp`-style copy-out.
- [ ] Is the resolved destination of each member checked against the resolved root, component-wise?
- [ ] Are symlink and hardlink members rejected, or validated by their *final* target and location?
- [ ] Is the destination directory itself derived from user input (titles, names, IDs)?
- [ ] Is the archive produced from an attacker-controlled live filesystem (container, VM, shared mount)?
- [ ] Is the runtime patched for the filter bypasses above, and is extraction running as root or in a code-loading directory?
- [ ] Are archive signatures or digests mandatory, or can the attacker omit them?
## Notable cases
- Apple PCC — CVE-2026-20685 — cryptex tar entries wrote as root during boot, $150,000. [[raw/blog.sentry.security/beyond-prompt-injection-hacking-apple-s-private-cloud-compute-11210|Hacking Apple's PCC]]
- Docker `docker cp` / Docker Sandboxes `sbx cp` — CVE-2026-17106 — container-to-host write; fixed in moby/go-archive v0.3.0, Engine/CLI 29.7.2, Desktop 4.86.0. [[raw/imperva.com/copyescape-container-to-host-arbitrary-file-write-via-docker-cp-cve-20-11286|CopyEscape]]
- Frappe LMS — CVE-2026-39405 — SCORM zip extracted to a title-derived path, overwriting `api.py` for RCE; fixed in v2.50.1. [[raw/rhinosecuritylabs.com/multiple-vulnerabilities-in-frappe-lms-leading-to-remote-code-executio-12026|Frappe LMS]]
- CPython `tarfile` — CVE-2007-4559 plus 2026 filter bypasses. [[raw/aikido.dev/python-security-vulnerabilities-top-issues-aikido-2859|Aikido]] [[raw/stack.watch/python-security-vulnerabilities-in-2026-3395|stack.watch]]
- HTB Bruno — ZipSlip in a .NET scanning service chained with DLL hijack for a shell. [[raw/0xdf.gitlab.io/0xdf-hacks-stuff-ctf-solutions-malware-analysis-home-lab-development-115|0xdf hacks stuff]]
- "The return of Zip Slip!" was nominated for PortSwigger's top web hacking techniques of 2025. [[raw/portswigger.net/top-10-web-hacking-techniques-of-2025-call-for-nominations-4820|Top 10 Web Hacking Techniques of 2025: Call for Nominations]]
## Defenses
- **Avoid extracting untrusted archives** where possible; Python guidelines say extraction of untrusted `zipfile`/`tarfile` input should be avoided. [[raw/medium.com/python-secure-coding-guidelines-2857|Python Secure Coding Guidelines]]
- **Filter members explicitly** and check the resolved path of each one against the resolved root; keep the runtime current because stdlib filters have been bypassed.
```python
root = Path(dest).resolve()
with tarfile.open(src) as tf:
for m in tf.getmembers():
if m.issym() or m.islnk() or not (m.isfile() or m.isdir()):
raise ValueError(f"refusing link/special member {m.name}")
if not (root / m.name).resolve().is_relative_to(root):
raise ValueError(f"member escapes root: {m.name}")
tf.extractall(root, filter="data") # defense in depth, not the only control
```
- **Root the filesystem operations.** Imperva: string prefix checks and normalization cannot hold once symlinks and concurrent changes are involved; the kernel must enforce containment (Linux `openat2()` with `RESOLVE_BENEATH`, per Snyk). [[raw/imperva.com/copyescape-container-to-host-arbitrary-file-write-via-docker-cp-cve-20-11286|CopyEscape]] [[raw/snyk.io/symlinks-are-still-scary-and-yes-you-can-commit-them-to-git-10268|Symlinks Are Still Scary]]
- **Enable library safety flags** (libarchive's security flags) rather than only preserve-metadata flags, and make integrity checks mandatory. [[raw/blog.sentry.security/beyond-prompt-injection-hacking-apple-s-private-cloud-compute-11210|Hacking Apple's PCC]]
- **Never derive the destination from user input**; generate it server-side.
- **Least privilege and sandboxing:** extract as an unprivileged user into an isolated directory that is not on any code-loading path. [[raw/aikido.dev/python-security-vulnerabilities-top-issues-aikido-2859|Aikido]]
- **Detect:** Aikido flags `extractall` without member filtering; Bandit's `tarfile_unsafe_members` is in [[Python SAST Tools]].
## Related
- [[Path Traversal]] (parent guide) · [[Local File Inclusion]] · [[Unrestricted File Upload]] · [[Remote Code Execution]] · [[Unsafe Python Functions]] · [[Python Security]] · [[SSRF in Kubernetes and Containers]] · [[Software Supply Chain Security]]
## Sources
- [[raw/aikido.dev/python-security-vulnerabilities-top-issues-aikido-2859|Python Security Vulnerabilities - Top Issues - Aikido]]
- [[raw/snyk.io/symlinks-are-still-scary-and-yes-you-can-commit-them-to-git-10268|Symlinks Are Still Scary (And Yes, You Can Commit Them to Git)]]
- [[raw/rhinosecuritylabs.com/multiple-vulnerabilities-in-frappe-lms-leading-to-remote-code-executio-12026|Multiple Vulnerabilities in Frappe LMS Leading to Remote Code Execution]]
- [[raw/imperva.com/copyescape-container-to-host-arbitrary-file-write-via-docker-cp-cve-20-11286|CopyEscape: Container-to-host arbitrary file write via docker cp (CVE-2026-17106)]]
- [[raw/stack.watch/python-security-vulnerabilities-in-2026-3395|Python Security Vulnerabilities in 2026]]
- [[raw/secalerts.co/python-security-vulnerabilities-risk-score-3392|Python Security Vulnerabilities & Risk Score]]
- [[raw/blog.sentry.security/beyond-prompt-injection-hacking-apple-s-private-cloud-compute-11210|Beyond Prompt Injection: Hacking Apple's Private Cloud Compute]]
- [[raw/0xdf.gitlab.io/0xdf-hacks-stuff-ctf-solutions-malware-analysis-home-lab-development-115|0xdf hacks stuff]]
- [[raw/portswigger.net/top-10-web-hacking-techniques-of-2025-call-for-nominations-4820|Top 10 Web Hacking Techniques of 2025: Call for Nominations]]
- [[raw/medium.com/python-secure-coding-guidelines-2857|Python Secure Coding Guidelines]]