Logging Sensitive Data: Security Concerns
What you'll learn: Discover which data must never appear in logs and how to prevent dangerous information leaks through logging.
The Security Risk in Logs
Logs are immensely valuable for debugging and monitoring, but they become a security nightmare when they capture sensitive information. Unlike encrypted databases with access controls, logs often get:
- Stored in plain text
- Aggregated across many systems
- Accessed by numerous engineers
- Retained for extended periods
- Backed up to less-secure storage
Think of logs like sticky notes left around an office—they're convenient for quick reference, but you'd never write a password or credit card number on one.
What Must Never Be Logged
Absolutely forbidden:
- Passwords (plaintext, hashed, or otherwise)
- Authentication tokens and API keys
- Session IDs and cookies
- Credit card numbers and CVV codes
- Social Security numbers
- Private encryption keys
Generally avoided (PII - Personally Identifiable Information):
- Email addresses (use hashed IDs instead)
- Phone numbers
- Physical addresses
- Full names (unless required for audit trails)
Safe Logging Techniques
Use identifiers instead of values:
Bad: "User john.doe@example.com logged in with token abc123"
Good: "User ID 8472 authenticated successfully"
Redact sensitive fields:
Bad: "Payment failed: card=4532-1234-5678-9010"
Good: "Payment failed: card=****-****-****-9010"
Log references, not content:
Bad: "Decryption key: sk_live_xyz789"
Good: "Using credential key_id=prod_payment_key"
Sanitize before logging by running all log data through filters that detect and mask patterns like credit card numbers or tokens.
Key Takeaway: Logs are insecure by nature—never log passwords, tokens, keys, or PII; always use identifiers, redaction, and sanitization to prevent turning your observability system into a security liability.