Skip to content

Commit 463c4d8

Browse files
gkorlandclaude
andauthored
fix: require authentication on validate-api-key endpoint (#481)
* fix: require authentication on validate-api-key endpoint The POST /api/validate-api-key endpoint was missing the @token_required decorator, allowing unauthenticated users to proxy LLM API calls through the server. Add @token_required to match all other POST endpoints. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: suppress pylint unused-argument for decorated request param The @token_required decorator consumes the request argument before the function body, so pylint incorrectly flags it as unused. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: add 401 response to OpenAPI docs for validate-api-key Add responses={401: UNAUTHORIZED_RESPONSE} to match the convention used by all other @token_required endpoints. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5e7f6a7 commit 463c4d8

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

api/routes/settings.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from pydantic import BaseModel
77
from litellm import completion
88

9+
from api.auth.user_management import token_required
10+
from api.routes.tokens import UNAUTHORIZED_RESPONSE
11+
912
settings_router = APIRouter(tags=["Settings"])
1013

1114

@@ -21,14 +24,14 @@ class ValidateKeyRequest(BaseModel):
2124
model: str = "gpt-3.5-turbo"
2225

2326

24-
@settings_router.post("/validate-api-key")
25-
async def validate_api_key(request: Request, data: ValidateKeyRequest): # pylint: disable=too-many-return-statements
27+
@settings_router.post("/validate-api-key", responses={401: UNAUTHORIZED_RESPONSE})
28+
@token_required
29+
async def validate_api_key(request: Request, data: ValidateKeyRequest): # pylint: disable=too-many-return-statements,unused-argument
2630
"""
2731
Validate an AI provider API key by making a simple test request.
2832
This endpoint does not store the key, it only validates it.
2933
Supports: openai, google, anthropic
3034
"""
31-
_ = request
3235
api_key = data.api_key.strip()
3336
vendor = data.vendor.lower()
3437
model = data.model

0 commit comments

Comments
 (0)