Browse Source

Fixed security vulnerability: now LDAP password hashes are not stored, same as trusted header auth.
LDAP users role now getting DEFAULT_USER_ROLE, not "pending".

alexey_rechkalov 5 tháng trước cách đây
mục cha
commit
b1237cf389
1 tập tin đã thay đổi với 14 bổ sung4 xóa
  1. 14 4
      backend/open_webui/apps/webui/routers/auths.py

+ 14 - 4
backend/open_webui/apps/webui/routers/auths.py

@@ -238,10 +238,20 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
 
             user = Users.get_user_by_email(mail)
             if not user:
-
                 try:
-                    hashed = get_password_hash(form_data.password)
-                    user = Auths.insert_new_auth(mail, hashed, cn)
+                    role = (
+                        "admin"
+                        if Users.get_num_users() == 0
+                        else request.app.state.config.DEFAULT_USER_ROLE
+                    )
+
+                    user = Auths.insert_new_auth(
+                        mail,
+                        str(uuid.uuid4()),
+                        cn,
+                        None,
+                        role,
+                    )
 
                     if not user:
                         raise HTTPException(
@@ -253,7 +263,7 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
                 except Exception as err:
                     raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err))
 
-            user = Auths.authenticate_user(mail, password=str(form_data.password))
+            user = Auths.authenticate_user_by_trusted_header(mail)
 
             if user:
                 token = create_token(