mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
fix: ensure trusted email header matches logged-in user
When using trusted email header authentication, verify that the logged-in user's email matches the value in the header. This prevents session conflicts when the OAuth server changes the authenticated user. - Move trusted email verification after user existence check - Raise 401 if email mismatch is detected - Only perform verification when WEBUI_AUTH_TRUSTED_EMAIL_HEADER is enabled
This commit is contained in:
parent
53764fe648
commit
61f49ff580
@ -23,6 +23,7 @@ from open_webui.env import (
|
|||||||
TRUSTED_SIGNATURE_KEY,
|
TRUSTED_SIGNATURE_KEY,
|
||||||
STATIC_DIR,
|
STATIC_DIR,
|
||||||
SRC_LOG_LEVELS,
|
SRC_LOG_LEVELS,
|
||||||
|
WEBUI_AUTH_TRUSTED_EMAIL_HEADER,
|
||||||
)
|
)
|
||||||
|
|
||||||
from fastapi import BackgroundTasks, Depends, HTTPException, Request, Response, status
|
from fastapi import BackgroundTasks, Depends, HTTPException, Request, Response, status
|
||||||
@ -225,6 +226,14 @@ def get_current_user(
|
|||||||
detail=ERROR_MESSAGES.INVALID_TOKEN,
|
detail=ERROR_MESSAGES.INVALID_TOKEN,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
if WEBUI_AUTH_TRUSTED_EMAIL_HEADER:
|
||||||
|
trusted_email = request.headers.get(WEBUI_AUTH_TRUSTED_EMAIL_HEADER)
|
||||||
|
if trusted_email and user.email != trusted_email:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||||
|
detail="User mismatch. Please sign in again.",
|
||||||
|
)
|
||||||
|
|
||||||
# Add user info to current span
|
# Add user info to current span
|
||||||
current_span = trace.get_current_span()
|
current_span = trace.get_current_span()
|
||||||
if current_span:
|
if current_span:
|
||||||
|
Loading…
Reference in New Issue
Block a user