Secret Redaction¶
Cub includes built-in secret redaction to prevent sensitive data from appearing in logs, status files, and console output. This protects API keys, passwords, and other credentials from accidental exposure.
How Redaction Works¶
Cub scans output for patterns that look like secrets and replaces them with [REDACTED]:
Redaction applies to:
- JSONL audit logs
- Status files
- Console output (when applicable)
- Error messages
Default Secret Patterns¶
Cub includes these default regex patterns for secret detection:
| Pattern | Matches |
|---|---|
api[_-]?key | API_KEY, api-key, apikey |
password | password, PASSWORD |
token | token, access_token, refresh_token |
secret | secret, client_secret |
authorization | Authorization headers |
credentials | credentials, aws_credentials |
How Patterns Are Applied¶
Patterns match case-insensitively on key names. When a match is found, the associated value is redacted:
// Input
{"api_key": "sk-abc123", "user": "alice"}
// Output (redacted)
{"api_key": "[REDACTED]", "user": "alice"}
Configuration¶
Adding Custom Patterns¶
Add project-specific patterns in .cub.json:
{
"guardrails": {
"secret_patterns": [
"api[_-]?key",
"password",
"token",
"secret",
"authorization",
"credentials",
"stripe[_-]?key",
"database[_-]?url",
"private[_-]?key"
]
}
}
Pattern Replacement
Setting secret_patterns replaces the defaults. Include the default patterns if you want to keep them.
Pattern Syntax¶
Patterns use Python regex syntax:
# Match variations
"api[_-]?key" # api_key, api-key, apikey
"pass(word|phrase)" # password, passphrase
".*_secret$" # anything ending in _secret
Disabling Redaction¶
To disable redaction (not recommended):
Viewing Redacted Logs¶
JSONL Logs¶
Logs at ~/.local/share/cub/logs/{project}/{session}.jsonl are redacted:
{
"timestamp": "2026-01-17T10:30:00Z",
"event_type": "task_start",
"data": {
"task_id": "cub-054",
"env": {
"ANTHROPIC_API_KEY": "[REDACTED]",
"HOME": "/Users/alice"
}
}
}
Status Files¶
Status files at .cub/runs/{session}/status.json are also redacted:
What Gets Redacted¶
Environment Variables¶
Any environment variable matching a secret pattern has its value redacted:
JSON Values¶
JSON keys matching patterns have their values redacted:
// Original
{"database_password": "hunter2", "port": 5432}
// Redacted
{"database_password": "[REDACTED]", "port": 5432}
Error Messages¶
Secrets in error messages are redacted:
Original: Authentication failed for token sk-abc123xyz
Redacted: Authentication failed for token [REDACTED]
What Is NOT Redacted¶
Cub's redaction is pattern-based and cannot detect all secrets:
| Item | Redacted? | Notes |
|---|---|---|
| API keys with known prefixes | sk-, pk_, etc. | |
| Values matching patterns | If key matches | |
| Random strings | No pattern match | |
| Encoded secrets | Base64, etc. | |
| Secrets in prose | Unstructured text |
Best Practices¶
Use Environment Variables¶
Keep secrets in environment variables, not in code or config:
# Good: Secret in environment
export ANTHROPIC_API_KEY=sk-ant-...
# Bad: Secret in config file
# .cub.json: {"api_key": "sk-ant-..."}
Add Project-Specific Patterns¶
If your project uses custom secret names, add patterns:
{
"guardrails": {
"secret_patterns": [
"api[_-]?key",
"password",
"token",
"secret",
"authorization",
"credentials",
"stripe[_-]?(key|secret)",
"twilio[_-]?(sid|token)",
"sendgrid[_-]?key",
"jwt[_-]?secret"
]
}
}
Review Logs Before Sharing¶
Even with redaction, review logs before sharing:
# Search for potential secrets
grep -i "key\|token\|secret\|password" ~/.local/share/cub/logs/myproject/*.jsonl
Use Separate Keys for Development¶
Use dedicated API keys for autonomous sessions that can be revoked if exposed:
Troubleshooting¶
Secrets Still Appearing¶
If secrets appear in logs:
- Check if the key name matches a pattern
- Add a custom pattern for the key format
- Verify
secret_patternsin config includes defaults
Too Much Redaction¶
If non-secrets are being redacted:
- Review your custom patterns for over-matching
- Use more specific regex patterns
- Consider excluding certain fields
Verifying Redaction¶
Test redaction with debug mode:
Security Considerations¶
Cub's redaction is a defense-in-depth measure, not a security guarantee:
- Redaction happens after processing - Secrets are briefly in memory
- Pattern-based - Novel secret formats may not match
- Log files persist - Redacted logs should still be protected
- Not encryption - Redacted values are removed, not encrypted
For maximum security:
- Use short-lived API keys
- Set strict file permissions on log directories
- Consider disabling logging for highly sensitive work
- Regularly rotate credentials