Repository navigation
Conversation
Browsers do not apply the same-origin policy to WebSocket connections, so any page loaded on a client joined to the setup AP could open /ws and send shocker commands. The pre-handshake callback only checked the Host header. Accept a handshake only with no Origin (not a browser), the page's own origin (http:// plus the Host, already confined to an IP literal) or a loopback origin (the frontend dev server). Others get 403. Resolves code scanning alert #8 (CWE-1385).
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 59 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Contributor
Change file check✅ OK: 1 valid change file(s) added in this PR. Version impact: patch bump (fix). The next release stays 2.0.0 (latest stable: 1.6.0). |
This branch has not been deployed
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.
What does this change?
The portal's
/wspre-handshake callback only rejected requests whose Host header is a name (RFC8908::IsForeignHost) and never looked at the Origin header. Browsers do not apply the same-origin policy to WebSocket connections, so any web page loaded on a client joined to the setup AP (for example a phone that also has cellular data) could openws://<AP IP>/wsand sendShockerCommandListmessages or read hub state.The handshake now also checks the Origin header. It is accepted when:
http://plus the request's own Host (the portal page itself; the Host check already confines Host to an IP literal, so DNS rebinding cannot match), orlocalhostor127.0.0.1on any port (the frontend dev server, whichgetDeviceHostname()points at 4.3.2.1).Any other Origin, including
null,https://and anything longer than an IPv4 literal with a port, gets403 Forbiddenand the connection is closed.Resolves code scanning alert #8 (CWE-1385).
This touches device control and authentication: it gates who can reach the local command path. The portal page itself connects exactly as before.
How was it tested?
http://4.3.2.1/still connects; the frontend dev server onlocalhoststill connects; a WebSocket opened from another origin (e.g. a browser console on another site while joined to the AP) is refused with 403.Checklist