fileaudit.zip_check module#
License MPL-2.0 (C) 2026 Created by Maikel Mardjan - https://nocomplexity.com/ FileAudit - ZIP File Security Checker
- class fileaudit.zip_check.HTTPSOnlyRedirectHandler[source]#
Bases:
HTTPRedirectHandlerAllow redirects only to valid HTTPS URLs.
- redirect_request(req, fp, code, msg, headers, newurl)[source]#
Return a Request or None in response to a redirect.
This is called by the http_error_30x methods when a redirection response is received. If a redirection should take place, return a new Request to allow http_error_30x to perform the redirect. Otherwise, raise HTTPError if no-one else should try to handle this url. Return None if you can’t but another Handler might.
- exception fileaudit.zip_check.ZipValidationError[source]#
Bases:
ExceptionRaised when a ZIP archive fails security validation.
- fileaudit.zip_check.validate_zip(func_or_path=None, max_file_size=None, max_uncompressed_ratio=None, max_zip_members=None, max_total_extracted_size=None, max_individual_file_size=None, max_filename_length=None, max_directory_depth=None)[source]#
Validate ZIP files via decorator or direct invocation.
Supports:
Bare decorator:
@validate_zip def process(path): ...
Decorator factory:
@validate_zip() def process(path): ...
Named function argument:
@validate_zip("zip_path") def process(zip_path): ...
Named argument with limits:
@validate_zip( "zip_path", max_file_size=500 * 1024 * 1024, max_zip_members=5000, ) def process(zip_path): ...
Direct / CLI invocation (local):
validate_zip("archive.zip")
Direct / CLI invocation (remote HTTPS):
validate_zip("https://example.com/archive.zip")
- Returns:
The decorated function.
In direct mode:
True if validation succeeds, False otherwise.
- Return type:
In decorator mode
- Raises:
- ZipValidationError –
If validation fails in decorator mode. –