Skip to content

Conversation

@jvigliotta
Copy link
Collaborator

@jvigliotta jvigliotta commented Mar 25, 2025

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.

…nt prevent sockets from openening for the same channels between views
@jvigliotta jvigliotta requested a review from davetsay March 25, 2025 19:13
}
};
worker = new MCWSStreamWorker();
self.onmessage = function (messageEvent) {

Check warning

Code scanning / CodeQL

Missing origin verification in `postMessage` handler Medium

Postmessage handler has no origin check.

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.

  1. Define a list of trusted origins.
  2. Modify the onmessage handler to check the origin of the incoming message.
  3. Only process the message if the origin is in the list of trusted origins.
Suggested changeset 1
src/realtime/MCWSStreamWorkerScript.js

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/realtime/MCWSStreamWorkerScript.js b/src/realtime/MCWSStreamWorkerScript.js
--- a/src/realtime/MCWSStreamWorkerScript.js
+++ b/src/realtime/MCWSStreamWorkerScript.js
@@ -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;
EOF
@@ -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;
Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Collaborator

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.

@jvigliotta jvigliotta changed the title Better handling for WebSocket reconnect closures Improved WS reconnect closures and increased connection batching interval Mar 28, 2025
@jvigliotta jvigliotta requested a review from davetsay March 28, 2025 16:30
Copy link
Collaborator

@davetsay davetsay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work

@sonarqubecloud
Copy link

@jvigliotta jvigliotta merged commit 34e5f9c into release/5.3.1 Mar 28, 2025
3 checks passed
@jvigliotta jvigliotta deleted the 3.0.1-patch-release branch March 28, 2025 20:28
davetsay added a commit that referenced this pull request Apr 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants