Timothy J. Baek 6 месяцев назад
Родитель
Сommit
4616b508b1
2 измененных файлов с 17 добавлено и 2 удалено
  1. 8 1
      backend/open_webui/main.py
  2. 9 1
      backend/open_webui/utils/utils.py

+ 8 - 1
backend/open_webui/main.py

@@ -2224,7 +2224,14 @@ async def get_app_config(request: Request):
     user = None
     if "token" in request.cookies:
         token = request.cookies.get("token")
-        data = decode_token(token)
+        try:
+            data = decode_token(token)
+        except Exception as e:
+            log.debug(e)
+            raise HTTPException(
+                status_code=status.HTTP_401_UNAUTHORIZED,
+                detail="Invalid token",
+            )
         if data is not None and "id" in data:
             user = Users.get_user_by_id(data["id"])
 

+ 9 - 1
backend/open_webui/utils/utils.py

@@ -91,7 +91,15 @@ def get_current_user(
         return get_current_user_by_api_key(token)
 
     # auth by jwt token
-    data = decode_token(token)
+
+    try:
+        data = decode_token(token)
+    except Exception as e:
+        raise HTTPException(
+            status_code=status.HTTP_401_UNAUTHORIZED,
+            detail="Invalid token",
+        )
+
     if data is not None and "id" in data:
         user = Users.get_user_by_id(data["id"])
         if user is None: