File Audit – Simplify Python Secure Programming by adding one line! Build secure Python applications by default. Validate files before you use them.
Python File Audit protects you from using insecure files and file-based attacks with a comprehensive set of safety checks.
- File size limit – Prevents oversized files from being processed
- GZip decompression ratio – Guards against decompression bombs
- Tar member count – Limits the number of entries inside tar archives
- Total extracted size – Caps the overall size of extracted content
- Individual file size – Enforces a maximum size per extracted file
- Path traversal protection – Blocks
../and absolute path tricks - Reject symlinks – Disallows symbolic links
- Reject hardlinks – Disallows hard links
- Reject device files – Blocks device nodes
- Reject FIFOs – Blocks named pipes
- Filename length – Enforces a maximum filename length
- Directory depth – Limits how deeply nested directories can be
These checks can be used via a simple API or by adding a decorator — without changing your existing code.
pip install fileauditpip install fileauditValidate a local CSV file:
validate_csv("data.csv")Validate a CSV file from a URL:
validate_csv("https://example.com/data.csv")Use as a decorator (first function argument is treated as the CSV path):
@validate_csv
def process_csv(csv_path):
...Use as a decorator with default validation options:
@validate_csv()
def process_csv(csv_path):
...Specify the decorated function argument that contains the CSV path:
@validate_csv("input_file")
def process_csv(input_file):
...Configure validation limits:
@validate_csv(
max_file_size=10 * 1024 * 1024,
max_rows=10_000,
max_columns=50,
)
def process_csv(csv_path):
...You can also inspect a file directly from the command line:
fileaudit path/to/fileFile types are auto-detected from the extension:
| Extension | Description |
|---|---|
csv |
CSV files |
gz |
GZIP files |
json |
JSON files |
py |
Python source files |
tar |
TAR archives |
tar-gz |
TAR.GZ archives |
tgz |
TAR.GZ archives |
xml |
XML files |
zip |
ZIP archives |
Python File Audit helps you validate files before they reach your application logic, reducing the risk of common file-based attacks.
All contributions are welcome! Think of corrections on the documentation, code or more and better tests.
Simple Guidelines:
- Questions, Feature Requests, Bug Reports please use on the Github Issue Tracker.
Pull Requests are welcome!
When you contribute to FileAudit, your contributions are made under the same license as the file you are working on.
Note
This is an open community driven project. Contributors will be mentioned in the documentation.
We adopt the Collective Code Construction Contract(C4) to streamline collaboration.
fileaudit is distributed under the terms of the GPL-3.0-or-later license.