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
Metadata
Release files for tarslip-guard 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tarslip_guard-0.1.0.tar.gz | 6.7 kB | Without provenance | Details for tarslip_guard-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tarslip_guard-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for tarslip_guard-0.1.0-py3-none-any.whl |
Total release size: 14.9 kB
Release files / tarslip_guard-0.1.0.tar.gz
| Download URL | tarslip_guard-0.1.0.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b4aeb221389a7b54168e553cd04377bb1da6a6554b7752a6df74c0fbde7aa5b
|
|
BLAKE2b-256 checksum How to use checksums |
b1aa648ca18ead58602f4274a15f74d198e4bf40bcc053ee35f7636f6d68bf5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Release files / tarslip_guard-0.1.0-py3-none-any.whl
| Download URL | tarslip_guard-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af352c4b0f417ee991e5e7b26d9828c7b6f3c8f1eb538ccfeacb465ffc832f78
|
|
BLAKE2b-256 checksum How to use checksums |
0bd7699f2790b8d794a53d2d9afef8e76728bb56e9881abc763c90888cf0152f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.11
|
Security for tarslip-guard 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.