A powerful file sanitizer for env, YAML, JSON, CSV
Project description
๐ File Sanitizer
Prevent secret leaks. Sanitize configs safely. Ship with confidence.
File Sanitizer is a secure, developer-first CLI tool that detects, masks, hashes, cleans, and restores sensitive data across configuration files โ 100% offline, audit-ready, and CI-friendly.
Built for developers, DevOps engineers, and security teams.
โจ Why File Sanitizer?
๐จ Secrets in repositories are one of the top security risks.
๐ค Configs are constantly shared with teams, vendors, and auditors.
โ Manual redaction is error-prone and irreversible.
โ Zero network calls.
โ Safe .bak backups
โ Human-readable + machine-readable reports
โ Works locally and in CI/CD pipelines
๐ Key Features
| Feature | Description |
|---|---|
| ๐ Smart Secret Detection | Detects secrets in keys and embedded inside values (URLs, tokens, DSNs) |
| ๐จ Aesthetic CLI Output | Colorized, emoji-enhanced, human-friendly output |
| ๐ Auto-Generated Reports | Creates .json (CI/automation) and .txt (audit-ready) reports |
| ๐งน Multiple Redaction Strategies | Full mask, partial mask, or irreversible SHA-256 hashing |
| ๐ One-Click Undo | Restore originals from .bak backups |
| ๐ Format-Aware Intelligence | .env, .json, .yaml, .csv handled correctly |
| ๐ ๏ธ Custom Rules | Extend detection via rules.json |
| ๐ 100% Offline & Safe | No uploads, no telemetry, no tracking |
๐ Supported File Types
| Format | Capabilities |
|---|---|
.env, .env.example |
URL-aware secret masking |
.json |
Deep nested traversal |
.yaml, .yml |
Recursive scan, formatting preserved |
.csv |
Column-aware redaction & cleanup |
๐ Installation
pip install file-sanitizer
๐งพ Global CLI Syntax
filesan <command> <path> [options]
Commands
| Command | Description |
|---|---|
scan |
Detect secrets |
sanitize |
Redact / clean data |
undo |
Restore originals |
โ PATH can be a file or directory
๐ Scan (Detect Secrets)
filesan scan ./config/
๐ Auto-Generated Reports
./reports/
โโโ scan_YYYY-MM-DD_HH-MM-SS.json
โโโ scan_YYYY-MM-DD_HH-MM-SS.txt
โ JSON โ CI / automation
โ TXT โ audit-ready, human-readable
๐ Sample TXT Report
๐ฅ FILE SANITIZER โ SCAN REPORT
============================================================
๐ config.env
โข DB_PASSWORD โ supersecret123 (line 3)
โข API_KEY โ sk-abc123 (line 4)
โข DB_URL โ postgresql://user:***@host (line 5)
============================================================
โ ๏ธ 3 potential secret(s) detected.
============================================================
๐งน Sanitize (Redact Secrets)
๐ธ Full Mask (default)
filesan sanitize config.env
filesan sanitize config.env --mask "[REDACTED]"
๐ธ Partial Mask
filesan sanitize config.env --partial
๐ธ SHA-256 Hash (Irreversible)
filesan sanitize secrets.yaml --hash
๐ Undo (Restore Originals)
filesan undo config.env
โ Restores from config.env.bak
โ Safe and instant
๐ What Gets Sanitized?
Default Sensitive Keywords
Case-insensitive detection for:
password, passwd, pwd, secret, token, api_key, apikey,
access_key, client_secret, private_key, connection_string,
credential, auth, otp, key, db_url, dsn
๐ Embedded Secret Detection (ENV Only)
DATABASE_URL=postgresql://admin:MyPass123@localhost/db
โก Automatically becomes:
DATABASE_URL=postgresql://admin:***@localhost/db
โ No extra flags required
๐งฉ Custom Rules
Create rules.json:
{
"sensitive_keys": ["license_key", "jwt", "encryption_key"]
}
Use it:
filesan sanitize config.yaml --rules rules.json --partial
โ ๏ธ "sensitive_keys" must be the top-level key
๐น File-Type Specific Commands
1๏ธโฃ ENV Files (.env, .env.example)
โ Commands
scan, sanitize, undo
โ๏ธ Valid Options
| Flag | Description |
|---|---|
--rules PATH |
Custom rules |
--mask STRING |
Full mask |
--partial |
Partial mask |
--hash |
SHA-256 hash |
--json |
Raw JSON output |
--report PATH |
Custom JSON report |
โ Ignored:
--remove-nan, --delete-col, --drop-duplicates
๐ Examples
filesan scan config.env
filesan scan config.env --report audit.json
filesan scan config.env --json
filesan sanitize config.env
filesan sanitize config.env --partial
filesan sanitize config.env --hash
filesan sanitize config.env --rules rules.json --partial
filesan undo config.env
2๏ธโฃ JSON Files (.json)
Same behavior as .env
filesan scan app.json
filesan sanitize app.json --hash
filesan sanitize app.json --rules custom.json --partial
filesan undo app.json
3๏ธโฃ YAML Files (.yaml, .yml)
Same behavior as .env
filesan scan k8s.yaml --report k8s_audit.json
filesan sanitize k8s.yaml --partial
filesan sanitize k8s.yaml --hash --rules prod.json
filesan undo k8s.yaml
4๏ธโฃ CSV Files (.csv)
โ๏ธ Valid Options
| Flag | Effect |
|---|---|
--rules PATH |
Sensitive columns |
--mask STRING |
Mask values |
--partial |
Partial mask |
--hash |
Hash values |
--remove-nan |
Drop empty rows |
--delete-col NAME |
Remove column |
--drop-duplicates |
Remove duplicates |
--json |
Raw JSON output |
--report PATH |
Custom JSON report |
โ ๏ธ Cleanup flags are only valid with sanitize
๐ Examples
filesan scan users.csv
filesan scan users.csv --report users.json
filesan sanitize users.csv
filesan sanitize users.csv --partial
filesan sanitize users.csv --hash --rules pii.json
filesan sanitize users.csv --delete-col "ssn"
filesan sanitize users.csv --remove-nan --drop-duplicates
filesan sanitize users.csv \
--partial \
--delete-col "password" \
--remove-nan \
--drop-duplicates
filesan undo users.csv
๐ Directory Processing (Recursive)
filesan scan ./config/
filesan sanitize ./config/ --partial
filesan undo ./config/
โ Skips unsupported files
โ Applies correct logic per file type
โ One consolidated report per scan\
๐ค Output & Reporting Behavior
๐ Custom Report
filesan scan . --report out.json
โ Saves JSON only
โ No TXT file
๐จ๏ธ Raw JSON Output
filesan scan . --json
filesan scan . --report out.json --json
๐ฏ Masking Priority (Sanitize)
Only one strategy is applied:
--hash (highest)
--partial
--mask (lowest)
Example:
filesan sanitize x.env --hash --partial --mask "XXX"
โก Uses HASHING
๐ซ Invalid Flag Combinations
| Command | Invalid Flags |
|---|---|
scan, undo |
--remove-nan, --delete-col, --drop-duplicates |
Error:
"only valid with sanitize"
๐ข Real-World Use Cases
๐ Pre-Commit Secret Prevention
filesan scan .
# Fail commit if report contains โ ๏ธ
๐ Compliance & Auditing
โ SOC 2
โ ISO 27001
โ GDPR\
Human-readable .txt reports โ no parsing required.
โ๏ธ Cloud Migration
filesan scan terraform/
filesan sanitize terraform/ --hash
๐ฅ Safe Cross-Team Sharing
Sanitize before sharing with QA, support, vendors
Restore anytime with filesan undo
๐งโ๐ป Development Setup
git clone https://github.com/your-username/file-sanitizer.git
cd file-sanitizer
pip install -e .
filesan scan manual_tests/
filesan sanitize manual_tests/test.env --partial
โ ๏ธ Warning
This tool greatly reduces risk but manual review is always recommended before sharing sanitized files.
๐ License
MIT โ free for commercial and personal use.
๐ Built With
PyYAML โ YAML parsing
pandas โ CSV intelligence
hashlib โ SHA-256 hashing
Python Standard Library
๐ซ No external APIs
๐ซ No telemetry
๐ 100% Offline
Author
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file file_sanitizer-0.1.1.tar.gz.
File metadata
- Download URL: file_sanitizer-0.1.1.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bafc451d7a1ac254fa192b0786da402c4a483e52397a6c0f254504583a0e47a
|
|
| MD5 |
c31f4bd133736dae9e2a09b9fcb108e7
|
|
| BLAKE2b-256 |
0a482a9d6978998c6883c9bb8a58c9742a8a2fc6bd6d63b2e5bf8843ea50a9a4
|
File details
Details for the file file_sanitizer-0.1.1-py3-none-any.whl.
File metadata
- Download URL: file_sanitizer-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc5dca699746d31dc5e482add50fa6d010b585dd0066498411436a2fa533a18f
|
|
| MD5 |
b9df5036f6c9a979790dd07d9c2323ee
|
|
| BLAKE2b-256 |
14f6938bbf60f7c2efc19ae6d4219c2ce4e3e8ed302292800beb7ea905968f77
|