Redact database URL passwords from logs

- Add SanitizeDatabaseURL() function to config package that redacts passwords from database connection URLs
- Handles various URL formats: postgresql, mysql, etc.
- Correctly handles passwords containing special characters including @ symbols by using LastIndex
- Update startup logging in cmd/server/main.go to use sanitized database URL
- Add comprehensive tests covering various URL formats and edge cases

This ensures sensitive database credentials are not exposed in application logs.
This commit is contained in:
2025-10-31 00:37:10 -07:00
parent 1cbe58888c
commit 5eaf6fe6fb
3 changed files with 108 additions and 1 deletions
+1 -1
View File
@@ -103,7 +103,7 @@ func main() {
if err != nil {
logger.Fatalf("Failed to create database key store: %v", err)
}
logger.Infof("Connected to authentication database: %s", cfg.Auth.Database.URL)
logger.Infof("Connected to authentication database: %s", config.SanitizeDatabaseURL(cfg.Auth.Database.URL))
} else {
logger.Warn("No database configured for authentication - API keys will only be stored in memory")
}