mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-11 20:05:19 +00:00
fix: properly sign out user on trusted email mismatch
When using trusted email header authentication, properly sign out the user when the logged-in user's email doesn't match the trusted email header value. This ensures proper session cleanup when the OAuth server changes the authenticated user. - Add response parameter to get_current_user function - Delete JWT token cookie on email mismatch - Delete OAuth token cookie if present - Force re-authentication with 401 error
This commit is contained in:
parent
61f49ff580
commit
6860dec08f
1 changed files with 6 additions and 0 deletions
|
|
@ -158,6 +158,7 @@ def get_http_authorization_cred(auth_header: Optional[str]):
|
||||||
|
|
||||||
def get_current_user(
|
def get_current_user(
|
||||||
request: Request,
|
request: Request,
|
||||||
|
response: Response,
|
||||||
background_tasks: BackgroundTasks,
|
background_tasks: BackgroundTasks,
|
||||||
auth_token: HTTPAuthorizationCredentials = Depends(bearer_security),
|
auth_token: HTTPAuthorizationCredentials = Depends(bearer_security),
|
||||||
):
|
):
|
||||||
|
|
@ -229,6 +230,11 @@ def get_current_user(
|
||||||
if WEBUI_AUTH_TRUSTED_EMAIL_HEADER:
|
if WEBUI_AUTH_TRUSTED_EMAIL_HEADER:
|
||||||
trusted_email = request.headers.get(WEBUI_AUTH_TRUSTED_EMAIL_HEADER)
|
trusted_email = request.headers.get(WEBUI_AUTH_TRUSTED_EMAIL_HEADER)
|
||||||
if trusted_email and user.email != trusted_email:
|
if trusted_email and user.email != trusted_email:
|
||||||
|
# Delete the token cookie
|
||||||
|
response.delete_cookie("token")
|
||||||
|
# Delete OAuth token if present
|
||||||
|
if request.cookies.get("oauth_id_token"):
|
||||||
|
response.delete_cookie("oauth_id_token")
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
detail="User mismatch. Please sign in again.",
|
detail="User mismatch. Please sign in again.",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue