fix: require api auth in server factory

This commit is contained in:
hamb1y
2026-07-08 12:16:12 +08:00
committed by Xubin Ren
parent 6c59332a8a
commit e86133c434
4 changed files with 90 additions and 34 deletions
+2 -2
View File
@@ -414,11 +414,11 @@ def create_app(
@web.middleware
async def auth_middleware(request: web.Request, handler) -> web.StreamResponse:
if not api_key:
return await handler(request)
# Allow unauthenticated health checks.
if request.path == "/health":
return await handler(request)
if not api_key:
return _error_json(401, "API key is not configured")
auth = request.headers.get("Authorization", "")
if not auth.startswith("Bearer "):
return _error_json(401, "Missing Authorization header. Use: Bearer <api_key>")