mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 19:08:59 -05:00
[PR #23972] [CLOSED] fix(auth): don't crash session/signout on missing bearer; preserve primary-admin 403s #66316
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/23972
Author: @crbender
Created: 4/22/2026
Status: ❌ Closed
Base:
dev← Head:fix/auth-session-signout-and-primary-admin-guard📝 Commits (10+)
fe6783cMerge pull request #19030 from open-webui/devfc05e0aMerge pull request #19405 from open-webui/deve3faec6Merge pull request #19416 from open-webui/dev9899293Merge pull request #19448 from open-webui/dev140605eMerge pull request #19462 from open-webui/dev6f1486fMerge pull request #19466 from open-webui/devd95f533Merge pull request #19729 from open-webui/deva7271530.6.43 (#20093)6adde20Merge pull request #20394 from open-webui/devf9b0534Merge pull request #20522 from open-webui/dev📊 Changes
2 files changed (+22 additions, -5 deletions)
View changed files
📝
backend/open_webui/routers/auths.py(+16 -5)📝
backend/open_webui/routers/users.py(+6 -0)📄 Description
Summary
Three small, related bug fixes in the auth and user-admin routers. No API
contract changes; only affected error paths change behavior.
Bugs fixed
GET /api/v1/auths/crashes for cookie-only sessions / malformed headers.get_current_useraccepts a JWT from theAuthorizationheader, thetokencookie, orrequest.state.token(set by middleware, e.g. forx-api-key). The handler, however, unconditionally did:get_http_authorization_credreturnsNonewhen the header is missingor malformed, so an authenticated request that reached the endpoint via
cookie (or with a malformed
Authorizationheader) raisedAttributeError→ HTTP 500 instead of returning the session payload.Fix: mirror the token-resolution order used by
get_current_user(header → cookie →
request.state.token) and only decode when a tokenis available.
GET /api/v1/auths/signoutcrashes on a malformedAuthorizationheader.The handler assumed that a present
Authorizationheader always yieldedcredentials and did
token = auth_cred.credentialswithout checkingauth_cred is not None. A malformed header (e.g.Authorization: Bearerwith no token, or any value that doesn't split into two parts) caused a
500 and prevented cookie clearing / token revocation.
Fix: guard the
Nonereturn and fall back to the cookie token, thesame way the other branch already does.
Primary-admin protection returns 500 instead of 403.
update_user_by_idanddelete_user_by_idboth wrap their primary-adminguard in
try/except Exception. BecauseHTTPExceptionis anExceptionsubclass, the intentionalraise HTTPException(status_code=403, detail=ACTION_PROHIBITED)wascaught and rewritten as
HTTPException(500, "Could not verify primary admin status.").Clients saw a generic server error for what is actually an authorization
decision.
Fix: re-raise
HTTPExceptionbefore the generic catch (same patternalready used in
signup).Files changed
backend/open_webui/routers/auths.pybackend/open_webui/routers/users.pyRisk / compatibility
/auths/,/auths/signout,and the affected user routes are unchanged on the existing happy paths.
(cookie-auth session), a clean signout, or 403 (primary-admin protection)
instead of 500.
Tests
Existing integration tests in
backend/open_webui/test/apps/webui/routers/test_auths.pyandtest_users.pyonly exercise the header-auth happy paths and alreadypass. Happy to add tests covering the three affected error paths as a
follow-up if maintainers prefer them in this PR — the
AbstractPostgresTestfixture makes it a slightly larger change than the fixes themselves.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.