Fix Unauthenticated Access to Bot Proxy Endpoints (/bot/v1/chat, /bot/v1/chat/stream)#996
Conversation
…n-bot-proxy-endpoints Enforce authentication for bot proxy chat endpoints
|
Failed to generate code suggestions for PR |
|
Thanks for the security fix — enforcing auth on the bot proxy endpoints makes sense. One suggestion: could we merge the “required token” check into verify_auth() instead of introducing require_auth_token()? Right now the call sites read as require_auth_token(await verify_auth(request)), which is a bit harder to follow, especially since verify_auth() is only used within this module. If we change verify_auth() to return str and raise HTTPException(status_code=401, ...) when the token is missing, the handlers become simpler and the intent is clearer. Alternatively, if you want to keep the separation, renaming verify_auth() to something like extract_auth_token() would better reflect that it doesn’t enforce auth. |
|
Thanks @yeshion23333, that makes sense. I pushed a follow-up that keeps extraction and enforcement separate, but cleans up the API by renaming I also added tests for both supported auth header formats and restored |
This PR fixes a Broken Access Control issue on the bot proxy endpoints by requiring authentication before proxying requests upstream.
Previously,
POST /bot/v1/chatandPOST /bot/v1/chat/streamcould accept unauthenticated requests because token extraction was optional and non-blocking. This change enforces authentication with401 Unauthorizedwhen credentials are missing.Changes
verify_auth()toextract_auth_token()and made it synchronous.require_auth_token(request)to enforce auth before proxying./bot/v1/chatand/bot/v1/chat/streamto require auth.X-API-KeyAuthorization: Bearer ...BOT_API_URLafter each test to avoid leaking module-global state.Testing
401.