feat: Add CORS validation to WebSocket connections. #18410

This commit is contained in:
Richard Watts-Seale 2025-10-18 20:25:45 +11:00
parent 9ae06a3cac
commit 25087e09e6

View file

@ -18,6 +18,10 @@ from open_webui.utils.redis import (
get_sentinel_url_from_env, get_sentinel_url_from_env,
) )
from open_webui.config import (
CORS_ALLOW_ORIGIN,
)
from open_webui.env import ( from open_webui.env import (
ENABLE_WEBSOCKET_SUPPORT, ENABLE_WEBSOCKET_SUPPORT,
WEBSOCKET_MANAGER, WEBSOCKET_MANAGER,
@ -58,7 +62,7 @@ if WEBSOCKET_MANAGER == "redis":
else: else:
mgr = socketio.AsyncRedisManager(WEBSOCKET_REDIS_URL) mgr = socketio.AsyncRedisManager(WEBSOCKET_REDIS_URL)
sio = socketio.AsyncServer( sio = socketio.AsyncServer(
cors_allowed_origins=[], cors_allowed_origins=CORS_ALLOW_ORIGIN,
async_mode="asgi", async_mode="asgi",
transports=(["websocket"] if ENABLE_WEBSOCKET_SUPPORT else ["polling"]), transports=(["websocket"] if ENABLE_WEBSOCKET_SUPPORT else ["polling"]),
allow_upgrades=ENABLE_WEBSOCKET_SUPPORT, allow_upgrades=ENABLE_WEBSOCKET_SUPPORT,
@ -67,7 +71,7 @@ if WEBSOCKET_MANAGER == "redis":
) )
else: else:
sio = socketio.AsyncServer( sio = socketio.AsyncServer(
cors_allowed_origins=[], cors_allowed_origins=CORS_ALLOW_ORIGIN,
async_mode="asgi", async_mode="asgi",
transports=(["websocket"] if ENABLE_WEBSOCKET_SUPPORT else ["polling"]), transports=(["websocket"] if ENABLE_WEBSOCKET_SUPPORT else ["polling"]),
allow_upgrades=ENABLE_WEBSOCKET_SUPPORT, allow_upgrades=ENABLE_WEBSOCKET_SUPPORT,