Skip to main content

A safe zipfile library

Project description

safezipfile: A safe zipfile extract library for python

Summary

This library simply overrides the extractall method of the python ZipFile class with additional checks to prevent zip-slip and zip-bomb attacks. It can be used the same way as the usual extractall method but also accepts additional arguments to limit the number of allowed files in the archive, limit the size of each extract file, the total extracted file size and also the maximum allowed compression ratio (zip bombs have a very high compression ratio).

To make the base use case safe it already starts with some quite relaxed limits of:

  • 500 files in a zip
  • 1GB extracted file size
  • 10GB total extracted file size

But they can all be configured:

import safezipfile

# Base use case
with safezipfile.ZipFile("test.zip", "r") as zf:
    zf.extractall("./outdir")

# Or configure the limits
with safezipfile.ZipFile("test.zip", "r") as zf:
    zf.extractall(
        "./outdir", 
        max_files = 500, 
        max_file_size = 1 * 1024 * 1024 * 1024,
        max_total_size = 10 * 1024 * 1024 * 1024,
        max_compression_ratio = 100.0
    )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

safezipfile-0.0.0.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file safezipfile-0.0.0.tar.gz.

File metadata

  • Download URL: safezipfile-0.0.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for safezipfile-0.0.0.tar.gz
Algorithm Hash digest
SHA256 e454e7ef49db865afd54253ac2385efa70698ea71f43be4e52939a9bb16b8969
MD5 89d272dbc50aa83c2177f234ec0410da
BLAKE2b-256 31e67238696607352251cc22df8c4a227a04bf36bfce6e135bdd9717a4fd49aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page