Redact secrets in FastAPI requests, responses, and logs.
Project description
📦 fastapi-redaction
Automatic secret & sensitive-data redaction for FastAPI (logs, headers, responses)
Prevent AWS keys, Okta tokens, DB passwords, SFTP credentials, SharePoint secrets, JWT secrets, and any sensitive values from leaking into logs or API responses — without modifying your FastAPI endpoint code.
🚨 Why this package exists
FastAPI applications often log or return sensitive information during:
- 🐞 Debugging
- ⚠️ Exception handling
- 🔄 Background tasks
- 📜 Request logging
- 🛡 Middleware traces
- 📤 API responses
This can unintentionally expose:
- 🔑 AWS access keys
- 🔐 Okta API tokens
- 🔑 SFTP / SSH passwords
- 📂 SharePoint / MS Graph secrets
- 🗄 Database passwords
- 🔒 JWT secrets & signing keys
- 🌍 Third-party API keys
👉 This library fully prevents such leaks by automatically redacting secrets at multiple layers.
✨ Features
-
🔥 Full-stack secret masking
Redacts secrets from JSON responses, headers, logs, and any string containing sensitive substrings. -
🔍 Automatic secret discovery
Detects environment variables like*_SECRET,*_KEY,*_TOKEN,*_PASSWORD,CREDENTIAL,PRIVATE_KEY. -
🧠 Substring-based masking
Any secret value is replaced with:REDACTED. -
🛡 Configurable JSON key masking
Force-hide fields such as:password,token,secret,api_key,session. -
💨 Zero changes to your API endpoints
Just one line:redaction.init_app(app)
📥 Installation
pip install fastapi-redaction
🚀 Quick Start Example
python -m build
pip install dist/fastapi_redaction-0.1.0-py3-none-any.whl
python .\example_app.py
⚙️ Advanced Usage
🔧 Explicit environment variables
config = RedactionConfig(
explicit_env_keys=[
"SFTP_PASSWORD",
"SHAREPOINT_CLIENT_SECRET",
"MY_SERVICE_TOKEN",
]
)
🔐 Security Notes
This package prevents secret leakage to:
- 🌐 API clients
- 🖥 Browser DevTools
- ☁️ Cloud logs
- 🔄 Reverse proxies
- 🤖 AI tools in IDEs (Copilot, Cursor, Windsurf)
- 💻 Local console output
⚠️ It does not modify your internal logic — handlers still receive the real values.
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 fastapi_redaction-0.1.0.tar.gz.
File metadata
- Download URL: fastapi_redaction-0.1.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6645a57c482f4a2d3081368b79984a89db55ff63afe7f4565973fd4f6c917dcb
|
|
| MD5 |
a1ac7b33591e281d3a9482ef33e26f94
|
|
| BLAKE2b-256 |
910d0ede94977040052f5bfb96ef67f52b8d26035d517ba24a0a8745ee9f4d09
|
File details
Details for the file fastapi_redaction-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_redaction-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aebe8c93eb86a94477dda9a47a250fe9f36e6f5ec39d69d3c5ebd9b29318c6d4
|
|
| MD5 |
cc6fd04b073f691dc299d09d4e0a3579
|
|
| BLAKE2b-256 |
ad4d481dec7c55ab4b0947b9c22cc9fbd6d09f00f7eab450c0d532aa713260fd
|