From b4277c7d2e0f482defc8af14b6d22055faca97ab Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Sat, 5 Apr 2025 09:56:11 -0400 Subject: [PATCH 1/2] Make auth error messages generic --- backend/open_webui/routers/auths.py | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/backend/open_webui/routers/auths.py b/backend/open_webui/routers/auths.py index 07804f9ea..12499ca70 100644 --- a/backend/open_webui/routers/auths.py +++ b/backend/open_webui/routers/auths.py @@ -194,8 +194,8 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm): ciphers=LDAP_CIPHERS, ) except Exception as e: - log.error(f"An error occurred on TLS: {str(e)}") - raise HTTPException(400, detail=str(e)) + log.error(f"TLS configuration error: {str(e)}") + raise HTTPException(400, detail="Failed to configure TLS for LDAP connection.") try: server = Server( @@ -232,7 +232,7 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm): username = str(entry[f"{LDAP_ATTRIBUTE_FOR_USERNAME}"]).lower() email = str(entry[f"{LDAP_ATTRIBUTE_FOR_MAIL}"]) if not email or email == "" or email == "[]": - raise HTTPException(400, f"User {form_data.user} does not have email.") + raise HTTPException(400, "User does not have a valid email address.") else: email = email.lower() @@ -248,7 +248,7 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm): authentication="SIMPLE", ) if not connection_user.bind(): - raise HTTPException(400, f"Authentication failed for {form_data.user}") + raise HTTPException(400, "Authentication failed.") user = Users.get_user_by_email(email) if not user: @@ -276,7 +276,8 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm): except HTTPException: raise except Exception as err: - raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err)) + log.error(f"LDAP user creation error: {str(err)}") + raise HTTPException(500, detail="Internal error occurred during LDAP user creation.") user = Auths.authenticate_user_by_trusted_header(email) @@ -312,12 +313,10 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm): else: raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_CRED) else: - raise HTTPException( - 400, - f"User {form_data.user} does not match the record. Search result: {str(entry[f'{LDAP_ATTRIBUTE_FOR_USERNAME}'])}", - ) + raise HTTPException(400, "User record mismatch.") except Exception as e: - raise HTTPException(400, detail=str(e)) + log.error(f"LDAP authentication error: {str(e)}") + raise HTTPException(400, detail="LDAP authentication failed.") ############################ @@ -519,7 +518,8 @@ async def signup(request: Request, response: Response, form_data: SignupForm): else: raise HTTPException(500, detail=ERROR_MESSAGES.CREATE_USER_ERROR) except Exception as err: - raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err)) + log.error(f"Signup error: {str(err)}") + raise HTTPException(500, detail="An internal error occurred during signup.") @router.get("/signout") @@ -547,7 +547,8 @@ async def signout(request: Request, response: Response): detail="Failed to fetch OpenID configuration", ) except Exception as e: - raise HTTPException(status_code=500, detail=str(e)) + log.error(f"OpenID signout error: {str(e)}") + raise HTTPException(status_code=500, detail="Failed to sign out from the OpenID provider.") return {"status": True} @@ -591,7 +592,8 @@ async def add_user(form_data: AddUserForm, user=Depends(get_admin_user)): else: raise HTTPException(500, detail=ERROR_MESSAGES.CREATE_USER_ERROR) except Exception as err: - raise HTTPException(500, detail=ERROR_MESSAGES.DEFAULT(err)) + log.error(f"Add user error: {str(err)}") + raise HTTPException(500, detail="An internal error occurred while adding the user.") ############################ From 324550423c5bce26080751ba8f3ef7fc2e8cb490 Mon Sep 17 00:00:00 2001 From: Juan Calderon-Perez <835733+gaby@users.noreply.github.com> Date: Sat, 5 Apr 2025 10:03:24 -0400 Subject: [PATCH 2/2] Fix formatting issues --- backend/open_webui/retrieval/utils.py | 7 ++++++- backend/open_webui/routers/auths.py | 13 ++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/backend/open_webui/retrieval/utils.py b/backend/open_webui/retrieval/utils.py index b600080cf..f2d2c61de 100644 --- a/backend/open_webui/retrieval/utils.py +++ b/backend/open_webui/retrieval/utils.py @@ -322,7 +322,12 @@ def query_collection_with_hybrid_search( # Prepare tasks for all collections and queries # Avoid running any tasks for collections that failed to fetch data (have assigned None) - tasks = [(cn, q) for cn in collection_names if collection_results[cn] is not None for q in queries] + tasks = [ + (cn, q) + for cn in collection_names + if collection_results[cn] is not None + for q in queries + ] with ThreadPoolExecutor() as executor: future_results = [executor.submit(process_query, cn, q) for cn, q in tasks] diff --git a/backend/open_webui/routers/auths.py b/backend/open_webui/routers/auths.py index 12499ca70..67c2e9f2a 100644 --- a/backend/open_webui/routers/auths.py +++ b/backend/open_webui/routers/auths.py @@ -277,7 +277,9 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm): raise except Exception as err: log.error(f"LDAP user creation error: {str(err)}") - raise HTTPException(500, detail="Internal error occurred during LDAP user creation.") + raise HTTPException( + 500, detail="Internal error occurred during LDAP user creation." + ) user = Auths.authenticate_user_by_trusted_header(email) @@ -548,7 +550,10 @@ async def signout(request: Request, response: Response): ) except Exception as e: log.error(f"OpenID signout error: {str(e)}") - raise HTTPException(status_code=500, detail="Failed to sign out from the OpenID provider.") + raise HTTPException( + status_code=500, + detail="Failed to sign out from the OpenID provider.", + ) return {"status": True} @@ -593,7 +598,9 @@ async def add_user(form_data: AddUserForm, user=Depends(get_admin_user)): raise HTTPException(500, detail=ERROR_MESSAGES.CREATE_USER_ERROR) except Exception as err: log.error(f"Add user error: {str(err)}") - raise HTTPException(500, detail="An internal error occurred while adding the user.") + raise HTTPException( + 500, detail="An internal error occurred while adding the user." + ) ############################