Skip to main content

tarslip-guard

Find and fix tar-slip / zip-slip path-traversal bugs (CWE-22). Two complementary, dependency-free tools:

  1. A static checker that flags extractall() calls with no filter= or members= argument — the pattern that lets a malicious archive write files outside the intended directory.
  2. 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=True to 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

tarslip_guard-0.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tarslip_guard-0.1.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

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

Hashes for tarslip_guard-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0b4aeb221389a7b54168e553cd04377bb1da6a6554b7752a6df74c0fbde7aa5b
MD5 295d3c9993b99873be659fae575964bf
BLAKE2b-256 b1aa648ca18ead58602f4274a15f74d198e4bf40bcc053ee35f7636f6d68bf5b

See more details on using hashes here.

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

Hashes for tarslip_guard-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 af352c4b0f417ee991e5e7b26d9828c7b6f3c8f1eb538ccfeacb465ffc832f78
MD5 efc77f408317100100d3185b23cdbe51
BLAKE2b-256 0bd7699f2790b8d794a53d2d9afef8e76728bb56e9881abc763c90888cf0152f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page