浏览代码

Fix code scanning alert no. 129: LDAP query built from user-controlled sources

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Timothy Jaeryang Baek 5 月之前
父节点
当前提交
1f36cad9ef
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      backend/open_webui/apps/webui/routers/auths.py

+ 2 - 1
backend/open_webui/apps/webui/routers/auths.py

@@ -44,6 +44,7 @@ from typing import Optional, List
 
 from ldap3 import Server, Connection, ALL, Tls
 from ssl import CERT_REQUIRED, PROTOCOL_TLS
+from ldap3.utils.conv import escape_filter_chars
 
 router = APIRouter()
 
@@ -181,7 +182,7 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
 
         search_success = connection_app.search(
             search_base=LDAP_SEARCH_BASE,
-            search_filter=f'(&({LDAP_ATTRIBUTE_FOR_USERNAME}={form_data.user.lower()}){LDAP_SEARCH_FILTERS})',
+            search_filter=f'(&({LDAP_ATTRIBUTE_FOR_USERNAME}={escape_filter_chars(form_data.user.lower())}){LDAP_SEARCH_FILTERS})',
             attributes=[f'{LDAP_ATTRIBUTE_FOR_USERNAME}', 'mail', 'cn']
         )