Test files › Archives › valid-flat.zip
Sample ZIP file (valid flat)
Three deflated text files at the archive root, no directories.
↓ Download valid-flat.zip| Filename | valid-flat.zip |
| Format | ZIP |
| Size | 376 bytes (376 bytes) |
| MIME type | application/zip |
| SHA-256 | a8e3fb09b187d71285f1b908f39f1734e43e8143d182505306af44b442852c32 |
What this file catchesBaseline extraction check.
Handle it in code
Each snippet below was run against this exact file with Python 3.14.4 and Node 24.15.0 when this page was built, and the output shown is what it printed.
Python
Check every entry before extracting anything. Python's extractall already strips "../" and leading slashes, but silently, so the file lands somewhere the archive did not say. Rejecting makes the attack visible and matches what other languages need.
import os, zipfile
def safe_extract(archive, dest):
dest = os.path.realpath(dest)
with zipfile.ZipFile(archive) as z:
for info in z.infolist():
target = os.path.realpath(os.path.join(dest, info.filename))
if os.path.commonpath([dest, target]) != dest:
raise ValueError(f"blocked: {info.filename!r} escapes the target folder")
z.extractall(dest)
try:
safe_extract("valid-flat.zip", "out")
print("extracted")
except ValueError as e:
print(e)Run against this file, it prints: extracted
Related guides and tools
Download & verify
curl -fsSL -o "valid-flat.zip" "https://files.hexaqa.com/archive/valid-flat.zip"
curl -fsSL "https://files.hexaqa.com/archive/valid-flat.zip" | sha256sum
# expect: a8e3fb09b187d71285f1b908f39f1734e43e8143d182505306af44b442852c32