Redact Database Connection Strings
Detect and redact database connection strings containing passwords from config files and environment variables. Supports PostgreSQL, MySQL, MongoDB, and Redis URLs.
Detailed Explanation
Redacting Database Connection Strings
Database connection strings typically embed credentials directly in the URL, making them one of the most sensitive pieces of configuration in any application. A leaked connection string can give an attacker direct access to your database.
Connection String Formats
Most databases use a URI format that includes the password:
postgresql://admin:s3cretP@ssw0rd@db.example.com:5432/myapp
mysql://root:hunter2@localhost:3306/production
mongodb://appuser:M0ng0P@ss!@cluster0.abc123.mongodb.net/mydb
redis://:authpassword@redis.example.com:6379/0
Anatomy of a Database URL
scheme://username:password@host:port/database
└───────┬──────┘
credentials
The redactor targets the credentials portion — specifically the password between the colon and the @ symbol — while preserving the rest of the connection string structure:
# Before
DATABASE_URL=postgresql://admin:s3cretP@ssw0rd@db.example.com:5432/myapp
# After
DATABASE_URL=postgresql://admin:[REDACTED]@db.example.com:5432/myapp
Detection Challenges
Database URLs present unique detection challenges:
- Special characters in passwords — Passwords may contain
@,:,/, and other URL-significant characters, sometimes percent-encoded - Multiple schemes —
postgresql://,postgres://,mysql://,mongodb://,mongodb+srv://,redis://,rediss:// - Optional components — Port, database name, and query parameters are all optional
- Embedded in longer strings — Connection strings appear inside environment variables, JSON configs, YAML files, and Docker Compose definitions
What Gets Redacted
A good redaction tool replaces only the password while keeping the host, port, and database name visible. This allows you to share configuration structure without exposing credentials. The username may also be partially redacted depending on sensitivity requirements.
Use Case
A DevOps engineer is troubleshooting a database connectivity issue and needs to share the application's environment configuration with a colleague. The .env file contains connection strings for PostgreSQL, Redis, and MongoDB. The Secret Redactor strips passwords from all database URLs while preserving the host and port information needed for debugging.