-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Securing websockets #1802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Securing websockets #1802
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,8 +30,12 @@ export class WebsocketController extends EventController implements EventControl | |
| const url = new URL(req.url || '', 'http://localhost'); | ||
| const params = new URLSearchParams(url.search); | ||
|
|
||
| const remoteAddress = req.socket.remoteAddress; | ||
| const isLocalhost = | ||
| remoteAddress === '127.0.0.1' || remoteAddress === '::1' || remoteAddress === '::ffff:127.0.0.1'; | ||
|
Comment on lines
+34
to
+35
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Consider IPv6-mapped IPv4 and proxy scenarios for localhost detection. This check may not handle all localhost scenarios, such as alternative IPv6-mapped formats or proxy headers like X-Forwarded-For. Consider updating the logic or documenting these limitations if relevant to your deployment. |
||
|
|
||
| // Permite conexões internas do Socket.IO (EIO=4 é o Engine.IO v4) | ||
| if (params.has('EIO')) { | ||
| if (params.has('EIO') && isLocalhost) { | ||
| return callback(null, true); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (code-quality): Prefer object destructuring when accessing and using properties. (
use-object-destructuring)Explanation
Object destructuring can often remove an unnecessary temporary reference, as well as making your code more succinct.From the Airbnb Javascript Style Guide