Spaces:
Sleeping
Sleeping
fix: enforce API key validation in verify_api_key dependency
Browse files- app/api/dependencies.py +4 -3
app/api/dependencies.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from fastapi import Header
|
| 2 |
from typing import Optional
|
| 3 |
from app.core.config import get_settings
|
| 4 |
|
|
@@ -7,10 +7,11 @@ settings = get_settings()
|
|
| 7 |
|
| 8 |
def verify_api_key(x_api_key: Optional[str] = Header(default=None)) -> None:
|
| 9 |
if not settings.api_key:
|
| 10 |
-
# API_KEY not configured — open access (dev/HF Spaces mode)
|
| 11 |
import logging
|
| 12 |
logging.getLogger(__name__).warning(
|
| 13 |
"WARNING: API_KEY is not set — all endpoints are publicly accessible. "
|
| 14 |
"Set API_KEY in your .env or environment to enable authentication."
|
| 15 |
)
|
| 16 |
-
return
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import Header, HTTPException
|
| 2 |
from typing import Optional
|
| 3 |
from app.core.config import get_settings
|
| 4 |
|
|
|
|
| 7 |
|
| 8 |
def verify_api_key(x_api_key: Optional[str] = Header(default=None)) -> None:
|
| 9 |
if not settings.api_key:
|
|
|
|
| 10 |
import logging
|
| 11 |
logging.getLogger(__name__).warning(
|
| 12 |
"WARNING: API_KEY is not set — all endpoints are publicly accessible. "
|
| 13 |
"Set API_KEY in your .env or environment to enable authentication."
|
| 14 |
)
|
| 15 |
+
return
|
| 16 |
+
if x_api_key != settings.api_key:
|
| 17 |
+
raise HTTPException(status_code=401, detail="Invalid or missing API key")
|