01Issue
Overview
An archive stores file names along with file contents. During extraction, the application should place every file inside the chosen destination folder. Zip Slip is a path traversal flaw where an archive entry name causes the extractor to write outside that folder. The same class of risk can involve absolute paths, alternate separators, links, or nested archives depending on the library and operating system.
Common causes
- The extractor joins an archive entry name to the destination without checking the resolved final path.
- The application blocks one traversal spelling but misses encoded or platform-specific path forms.
- Symlinks or hard links inside an archive are followed without a defined policy.
- The extraction process runs with write access to unrelated application files.
References: CWE-22: Path Traversal ↗OWASP File Upload Cheat Sheet ↗Snyk: Zip Slip Vulnerability ↗
02Examples
Illustrative test archive: docs/readme.txt plus an entry named ../outside-marker.txt, containing only TEST-MARKER. Extract it in a disposable test directory and inspect both the destination and its parent. A secure extractor rejects the second entry or keeps it inside the extraction root; an error message alone does not show where it wrote.
03Impact
The application must extract an archive whose entry names can be influenced by a user, and the extractor must be able to write outside its intended directory. Confirm the actual write location; finding ../ in an archive is only an indicator.
A confirmed path escape may overwrite files the service can write or place content where another component later loads it. The impact depends on process permissions and what reads the written file. An extraction error or suspicious entry name is not proof that an outside file was created.
04Testing
Test cases
1. Check whether archive entries escape the destination
Create an archive with a controlled marker entry containing a parent-directory path. Extract it through the test feature and inspect the intended and surrounding test folders.
Example: A file appearing outside the target folder confirms an extraction boundary failure. A rejected entry or error alone does not.
POST /api/import HTTP/1.1
Host: app.example.test
Content-Type: multipart/form-data; boundary=demo
--demo
Content-Disposition: form-data; name="file"; filename="test.zip"
Content-Type: application/zip
[TEST_ARCHIVE_BYTES]
--demo--
2. Compare path and link handling
Review absolute paths, alternate separators, duplicate names, and symbolic links if the extractor supports them. Inspect actual output paths.
Example: An archive may contain both normal and unusual entries. Compare where each entry was written.
POST /api/import HTTP/1.1
Host: app.example.test
Content-Type: application/zip
[SECOND_TEST_ARCHIVE_BYTES]
3. Check permissions, limits, and cleanup
Review overwrite behavior, extraction permissions, expanded size limits, and cleanup after failures. Verify that existing test files are not unexpectedly changed.
Example: An extraction error may happen after a partial write. Inspect the resulting test directory.
Testing references: CWE-22: Path Traversal ↗OWASP File Upload Cheat Sheet ↗Snyk: Zip Slip Vulnerability ↗
05Mitigation
Use a maintained archive library and validate each entry’s final canonical destination before writing. Reject absolute paths and traversal segments, define how links are handled, and create files without following unexpected links. Enforce limits on entry count and expanded size. Extract into a fresh directory under a restricted service account, then move validated output into its final location.
Retest
Repeat traversal, absolute-path, link, duplicate-name, and nested-archive cases. Confirm every file remains under the extraction root and valid archives still import correctly.