mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-06 10:58:17 -05:00
[PR #18411] [MERGED] feat: add CORS validation to WebSocket connections for defense-in-depth #47830
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/18411
Author: @ricdikulous
Created: 10/18/2025
Status: ✅ Merged
Merged: 10/20/2025
Merged by: @tjbck
Base:
dev← Head:feat/websocket-cors-security📝 Commits (2)
9ae06a3Merge pull request #18138 from open-webui/dev25087e0feat: Add CORS validation to WebSocket connections. #18410📊 Changes
1 file changed (+6 additions, -2 deletions)
View changed files
📝
backend/open_webui/socket/main.py(+6 -2)📄 Description
Pull Request Checklist
devbranchfeat:prefix usedChangelog Entry
Description
Added CORS (Cross-Origin Resource Sharing) validation to WebSocket connections as a defense-in-depth security measure. While authentication protects WebSocket endpoints, this change prevents potential cross-site WebSocket hijacking attacks by validating the origin of WebSocket connection requests against the configured
CORS_ALLOW_ORIGINsetting.Fixes #18410
Added
socketio.AsyncServerinitialization in both Redis-managed and standard configurationsCORS_ALLOW_ORIGINfromopen_webui.configmoduleChanged
cors_allowed_originsparameterSecurity
Additional Information
This change implements defense-in-depth security principles. While WebSocket endpoints are already protected by authentication mechanisms, adding CORS validation provides an additional security layer that:
CORS_ALLOW_ORIGINconfiguration without requiring new environment variablesThe implementation affects both deployment scenarios:
Code changes:
from open_webui.config import CORS_ALLOW_ORIGINcors_allowed_origins=CORS_ALLOW_ORIGINto bothsocketio.AsyncServerinstancesTesting performed:
CORS_ALLOW_ORIGIN=*settingCORS_ALLOW_ORIGIN=http://localhost:8080)Screenshots or Videos
[Optional: Add screenshots if you have them showing WebSocket connections working]
Contributor License Agreement
By submitting this pull request, I confirm that I have read and fully agree to the Contributor License Agreement (CLA), and I am providing my contributions under its terms.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.