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:
Shuai Lin
2025-07-21 10:40:24 +08:00
parent f3d9cb2b85
commit 9d4d6464bf
6 changed files with 216 additions and 27 deletions

View File

@@ -9,7 +9,7 @@ from app.config.config import settings, sync_initial_settings
from app.database.connection import connect_to_db, disconnect_from_db
from app.database.initialization import initialize_database
from app.exception.exceptions import setup_exception_handlers
from app.log.logger import get_application_logger
from app.log.logger import get_application_logger, setup_access_logging
from app.middleware.middleware import setup_middlewares
from app.router.routes import setup_routers
from app.scheduler.scheduled_tasks import start_scheduler, stop_scheduler
@@ -150,4 +150,7 @@ def create_app() -> FastAPI:
# 配置路由
setup_routers(app)
# 配置访问日志API密钥隐藏
setup_access_logging()
return app