tarslip-guard
Find and fix tar-slip / zip-slip path-traversal bugs (CWE-22). Two complementary, dependency-free tools:
- A static checker that flags
extractall()calls with nofilter=ormembers=argument — the pattern that lets a malicious archive write files outside the intended directory. - A safe runtime extractor (
safe_extractall) that validates every member before writing it, so you can extract untrusted archives without traversal.
Install
pip install tarslip-guard
Static checking
from tarslip_guard import check_source, check_path
check_source("import tarfile\ntarfile.open('x').extractall('out')\n")
# -> [Finding(... rule='TARSLIP-EXTRACTALL', cwe='CWE-22', line=2 ...)]
for finding in check_path("src/"):
print(finding)
tarslip-guard src/ tests/ # exits 1 if any unsafe call is found
extractall(..., filter="data") (Python 3.12+) and extractall(members=...)
are treated as safe and not flagged.
Safe extraction
from tarslip_guard import safe_extractall, UnsafeArchiveError
try:
safe_extractall("untrusted.tar.gz", "output_dir")
except UnsafeArchiveError as exc:
print("refused:", exc)
- Accepts an open
tarfile.TarFile/zipfile.ZipFile, or a path (type is auto-detected). - Rejects absolute paths and
..traversal for every member. - Rejects symlink/hardlink members that escape the destination (pass
allow_symlinks=Trueto permit links that stay inside it). safe_extract_to_temp(archive)extracts into a fresh temp dir and returns it.
Why
TarFile.extractall() has no path sanitization before Python 3.12's data
filter, and even on newer versions a lot of code passes untrusted archives
without opting in. This library gives you a linter to find those call sites and
a safe function to replace them.
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tarslip_guard-0.1.0.tar.gz.
File metadata
- Download URL: tarslip_guard-0.1.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b4aeb221389a7b54168e553cd04377bb1da6a6554b7752a6df74c0fbde7aa5b
|
|
| MD5 |
295d3c9993b99873be659fae575964bf
|
|
| BLAKE2b-256 |
b1aa648ca18ead58602f4274a15f74d198e4bf40bcc053ee35f7636f6d68bf5b
|
File details
Details for the file tarslip_guard-0.1.0-py3-none-any.whl.
File metadata
- Download URL: tarslip_guard-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.10.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af352c4b0f417ee991e5e7b26d9828c7b6f3c8f1eb538ccfeacb465ffc832f78
|
|
| MD5 |
efc77f408317100100d3185b23cdbe51
|
|
| BLAKE2b-256 |
0bd7699f2790b8d794a53d2d9afef8e76728bb56e9881abc763c90888cf0152f
|