mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-07-08 00:01:32 +08:00
security: enhance API key redaction with comprehensive testing and error handling
- Refactored redaction logic to use centralized helper function - Added robust error handling in AccessLogFormatter - Improved regex patterns for better OpenAI key detection - Added comprehensive unit tests covering edge cases and error scenarios - Enhanced input validation with descriptive error placeholders
This commit is contained in:
@@ -162,12 +162,15 @@ def redact_key_for_logging(key: str) -> str:
|
||||
key: API key to redact
|
||||
|
||||
Returns:
|
||||
str: Redacted key in format "first6...last6" or original if too short
|
||||
str: Redacted key in format "first6...last6" or descriptive placeholder for edge cases
|
||||
"""
|
||||
if not key or len(key) <= 12:
|
||||
return "***"
|
||||
if not key:
|
||||
return key
|
||||
|
||||
return f"{key[:6]}...{key[-6:]}"
|
||||
if len(key) <= 12:
|
||||
return f"{key[:3]}...{key[-3:]}"
|
||||
else:
|
||||
return f"{key[:6]}...{key[-6:]}"
|
||||
|
||||
|
||||
def get_current_version(default_version: str = "0.0.0") -> str:
|
||||
|
||||
Reference in New Issue
Block a user