security: Implemented API key redaction for secure logging

- Add redact_key_for_logging() helper function to show only first/last 6 chars
- Fix API key exposure in app/service/key/key_manager.py line 68
- Apply key redaction across all Python files with API key logging
- Standardize logging security across 17 files including routers, services, handlers
This commit is contained in:
Shuai Lin
2025-07-21 02:03:29 +08:00
parent b25cf7d978
commit 6abda7d902
17 changed files with 78 additions and 46 deletions
+16
View File
@@ -154,6 +154,22 @@ def is_valid_api_key(key: str) -> bool:
def redact_key_for_logging(key: str) -> str:
"""
Redacts API key for secure logging by showing only first and last 6 characters.
Args:
key: API key to redact
Returns:
str: Redacted key in format "first6...last6" or original if too short
"""
if not key or len(key) <= 12:
return "***"
return f"{key[:6]}...{key[-6:]}"
def get_current_version(default_version: str = "0.0.0") -> str:
"""Reads the current version from the VERSION file."""
version_file = VERSION_FILE_PATH