fix(server): restrict Socket.IO CORS to configured frontend origin [NSoC'26]#141
Merged
Merged
Conversation
…SoC'26]
cors: { origin: '*' } allowed any website to open a WebSocket upgrade
request to the FlowForge server. A malicious third-party page could
join rooms, receive real-time chat events, or inject messages through
a visitor's active browser session without any origin restriction.
Replaced the wildcard with ALLOWED_ORIGIN sourced from the FRONTEND_URL
environment variable (defaults to http://localhost:5173 for local
development). Added methods: ['GET', 'POST'] to the cors config for
explicit control.
Closes Shriii19#136
|
@anshul23102 is attempting to deploy a commit to the shreemp194-gmailcom's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
👋 Thank you for opening this pull request! I will review your changes and assist you soon. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Description
The Socket.IO server was initialized with
cors: { origin: "*" }. This allowed any third-party website to open a WebSocket connection to FlowForge from a visitor's browser, subscribe to real-time chat events, join rooms, and inject messages without any origin restriction.Related Issue
Closes #136
Type of Change
Root Cause
origin: "*"is a wildcard that permits WebSocket upgrade requests from any origin. There was no mechanism to restrict connections to the known frontend URL.Changes Made
backend/server.jscors: { origin: "*" }withcors: { origin: ALLOWED_ORIGIN, methods: ["GET", "POST"] }backend/server.jsALLOWED_ORIGINconstant read fromprocess.env.FRONTEND_URL, defaulting tohttp://localhost:5173Screenshots or Demo
Not applicable (backend-only change).
Testing Done
http://localhost:5173succeeds.FRONTEND_URL=https://your-production-domain.comin.envfor production deployments.Checklist
NSoC Label Request
@Shriii19 could you please add the appropriate NSoC '26 label to this PR? It helps with tracking and scoring. Thank you!