Skip to main content

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


Download files

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

Source Distribution

file_sanitizer-0.1.1.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

file_sanitizer-0.1.1-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

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

Hashes for file_sanitizer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2bafc451d7a1ac254fa192b0786da402c4a483e52397a6c0f254504583a0e47a
MD5 c31f4bd133736dae9e2a09b9fcb108e7
BLAKE2b-256 0a482a9d6978998c6883c9bb8a58c9742a8a2fc6bd6d63b2e5bf8843ea50a9a4

See more details on using hashes here.

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

Hashes for file_sanitizer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cc5dca699746d31dc5e482add50fa6d010b585dd0066498411436a2fa533a18f
MD5 b9df5036f6c9a979790dd07d9c2323ee
BLAKE2b-256 14f6938bbf60f7c2efc19ae6d4219c2ce4e3e8ed302292800beb7ea905968f77

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