|
|
@@ -35,7 +35,7 @@ from open_webui.env import (
|
|
|
)
|
|
|
from fastapi import APIRouter, Depends, HTTPException, Request, status
|
|
|
from fastapi.responses import RedirectResponse, Response, JSONResponse
|
|
|
-from open_webui.config import OPENID_PROVIDER_URL, ENABLE_OAUTH_SIGNUP, ENABLE_LDAP
|
|
|
+from open_webui.config import OPENID_PROVIDER_URL, ENABLE_OAUTH_SIGNUP, ENABLE_LDAP, ENABLE_PASSWORD_AUTH
|
|
|
from pydantic import BaseModel
|
|
|
|
|
|
from open_webui.utils.misc import parse_duration, validate_email_format
|
|
|
@@ -185,7 +185,17 @@ async def update_password(
|
|
|
############################
|
|
|
@router.post("/ldap", response_model=SessionUserResponse)
|
|
|
async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|
|
- ENABLE_LDAP = request.app.state.config.ENABLE_LDAP
|
|
|
+ # Security checks FIRST - before loading any config
|
|
|
+ if not request.app.state.config.ENABLE_LDAP:
|
|
|
+ raise HTTPException(400, detail="LDAP authentication is not enabled")
|
|
|
+
|
|
|
+ if (not ENABLE_PASSWORD_AUTH):
|
|
|
+ raise HTTPException(
|
|
|
+ status_code=status.HTTP_403_FORBIDDEN,
|
|
|
+ detail=ERROR_MESSAGES.ACTION_PROHIBITED,
|
|
|
+ )
|
|
|
+
|
|
|
+ # NOW load LDAP config variables
|
|
|
LDAP_SERVER_LABEL = request.app.state.config.LDAP_SERVER_LABEL
|
|
|
LDAP_SERVER_HOST = request.app.state.config.LDAP_SERVER_HOST
|
|
|
LDAP_SERVER_PORT = request.app.state.config.LDAP_SERVER_PORT
|
|
|
@@ -206,9 +216,6 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|
|
else "ALL"
|
|
|
)
|
|
|
|
|
|
- if not ENABLE_LDAP:
|
|
|
- raise HTTPException(400, detail="LDAP authentication is not enabled")
|
|
|
-
|
|
|
try:
|
|
|
tls = Tls(
|
|
|
validate=LDAP_VALIDATE_CERT,
|
|
|
@@ -463,6 +470,12 @@ async def ldap_auth(request: Request, response: Response, form_data: LdapForm):
|
|
|
|
|
|
@router.post("/signin", response_model=SessionUserResponse)
|
|
|
async def signin(request: Request, response: Response, form_data: SigninForm):
|
|
|
+ if (not ENABLE_PASSWORD_AUTH):
|
|
|
+ raise HTTPException(
|
|
|
+ status_code=status.HTTP_403_FORBIDDEN,
|
|
|
+ detail=ERROR_MESSAGES.ACTION_PROHIBITED,
|
|
|
+ )
|
|
|
+
|
|
|
if WEBUI_AUTH_TRUSTED_EMAIL_HEADER:
|
|
|
if WEBUI_AUTH_TRUSTED_EMAIL_HEADER not in request.headers:
|
|
|
raise HTTPException(400, detail=ERROR_MESSAGES.INVALID_TRUSTED_HEADER)
|