-
Notifications
You must be signed in to change notification settings - Fork 7
Improved WS reconnect closures and increased connection batching interval #296
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
Conversation
…nt prevent sockets from openening for the same channels between views
… recent/active connection
src/realtime/MCWSStreamWorkerScript.js
Dismissed
| } | ||
| }; | ||
| worker = new MCWSStreamWorker(); | ||
| self.onmessage = function (messageEvent) { |
Check warning
Code scanning / CodeQL
Missing origin verification in `postMessage` handler Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 9 months ago
To fix the problem, we need to verify the origin of incoming messages in the onmessage handler. This involves checking the origin property of the messageEvent object against a list of trusted origins. If the origin is not trusted, the message should be ignored.
- Define a list of trusted origins.
- Modify the
onmessagehandler to check the origin of the incoming message. - Only process the message if the origin is in the list of trusted origins.
-
Copy modified line R314 -
Copy modified lines R316-R318
| @@ -313,3 +313,7 @@ | ||
| worker = new MCWSStreamWorker(); | ||
| const trustedOrigins = ['https://www.example.com']; | ||
| self.onmessage = function (messageEvent) { | ||
| if (!trustedOrigins.includes(messageEvent.origin)) { | ||
| return; | ||
| } | ||
| const data = messageEvent.data; |
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.
Note to you and myself, @jvigliotta , you had triaged and addressed this type of security alert before as a non-issue. We should be sure to address this one too before this goes into patch release, so we can provide a scan for this release.
davetsay
left a comment
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.
good work
|



closes #292
closes #293
Updated Realtime code to ES6 classes/syntax.
Increase reconnect debounce time from 10ms to 100ms to add additional time for connection batching.
When closing WebSockets (due to no subscribers or because of updated filters/topics) suppress any errors. In high latency environments, these sockets can be closed before even connecting, which will throw errors. Other errors can pop up due to high latency environments that are not useful to the end user as these connections are no longer being used (either being replaced with a new connection, once that connection opens so no data is lost or because there are no subscribers). These errors just cause confusion and serve no informational purpose.