Security fix: Restrict WebSocket origins to prevent Cross-Site WebSocket Hijacking (CWE-942)#1160
Open
anushkasrvstv wants to merge 3 commits into
Open
Conversation
|
@anushkasrvstv is attempting to deploy a commit to the CodeBlooded's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Hi @anushkasrvstv, thanks for contributing to Nyay Setu! 🎉 I have automatically:
Our workflows will now analyze your changes to classify:
Tip Ensure your PR description references the issue it resolves (e.g. Happy coding! 🚀 |
Author
|
Implemented the fix for WebSocket origin validation. |
viru0909-dev
requested changes
Jun 7, 2026
Owner
viru0909-dev
left a comment
There was a problem hiding this comment.
Requires Changes: The test suite failed. Please fix the failing tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
PR Description
Summary
This PR fixes a security vulnerability where WebSocket endpoints previously allowed unrestricted or wildcard origins (*), which could lead to Cross-Site WebSocket Hijacking (CWE-942).
It introduces strict origin validation to ensure only explicitly trusted frontend origins can establish WebSocket connections.
Security Fix
➤Removed wildcard "" origin usage from WebSocket configuration
➤Added strict validation for allowed origins in WebSocketConfig
➤Rejects:
▫Empty origins
▫Null values
▫Wildcard "" origins
➤Prevents Cross-Site WebSocket Hijacking (CWE-942)
Changes
➤Introduced app.websocket.allowed-origins configuration property
➤Validated origins using getValidatedOrigins() method
➤Applied secure origins to:
▫/api/ws/notifications (raw WebSocket handler)
▫/api/ws/stomp (STOMP + SockJS endpoints)
➤Updated application.properties with configurable allowlist
Result
➤WebSocket connections are restricted to trusted origins only
➤Eliminates wildcard-based security risk
➤No breaking changes for valid configured environments
➤Backward compatible via environment variables (WEBSOCKET_ALLOWED_ORIGINS)
Issue Reference
Closes #1069