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.1.3.tar.gz (5.3 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: safezipfile-0.1.3.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.1.3.tar.gz
Algorithm Hash digest
SHA256 d589038d112b96b1747122f8c843266bac23debc9eb98fb1a3642ffa5f3fa2c6
MD5 8a92c450f1cbf8ddf099a05701fa2e3b
BLAKE2b-256 afff1144c985e32e4ec0908afa630942f740eff6a0f5611a58927e4691b6041f

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