Skip to content

Conversation

@davetsay
Copy link
Collaborator

Closes #219
topic branch to be merged into main after after sub issues #269 and #270 have been merged into topic branch

@davetsay davetsay requested a review from jvigliotta February 15, 2025 01:24
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

CodeQL found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

@davetsay davetsay marked this pull request as ready for review February 21, 2025 18:55
@sonarqubecloud
Copy link

'vista.encodingWatchConfigurationViewProvider',
'Config',
options,
ENCODING_WATCH_TYPE

Check warning

Code scanning / CodeQL

Superfluous trailing arguments Warning

Superfluous argument passed to
constructor of class FrameWatchConfigurationViewProvider
.
'vista.frameWatchConfigurationViewProvider',
'Config',
options,
FRAME_WATCH_TYPE

Check warning

Code scanning / CodeQL

Superfluous trailing arguments Warning

Superfluous argument passed to
constructor of class FrameWatchConfigurationViewProvider
.
@@ -6,11 +6,27 @@
const TOTAL_PARTS_FIELD = 'total_parts';

const PRODUCT_STARTED_RECORD_TYPE = 'PRODUCT_STARTED';
// eslint-disable-next-line no-unused-vars

Check notice

Code scanning / CodeQL

Unused variable, import, function or class Note

Unused variable COMPLETE_PRODUCT_RECORD_TYPE.

Copilot Autofix

AI 10 months ago

To fix the problem, we need to remove the unused variable COMPLETE_PRODUCT_RECORD_TYPE from the code. This involves deleting the line where the variable is declared. This change will not affect the existing functionality since the variable is not used anywhere in the provided code snippet.

Suggested changeset 1
src/product-status/DataProductRow.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/product-status/DataProductRow.js b/src/product-status/DataProductRow.js
--- a/src/product-status/DataProductRow.js
+++ b/src/product-status/DataProductRow.js
@@ -8,4 +8,3 @@
 const PRODUCT_STARTED_RECORD_TYPE = 'PRODUCT_STARTED';
-// eslint-disable-next-line no-unused-vars
-const COMPLETE_PRODUCT_RECORD_TYPE = 'COMPLETE_PRODUCT';
+
 const PRODUCT_PART_RECEIVED_RECORD_TYPE = 'PRODUCT_PART_RECEIVED';
EOF
@@ -8,4 +8,3 @@
const PRODUCT_STARTED_RECORD_TYPE = 'PRODUCT_STARTED';
// eslint-disable-next-line no-unused-vars
const COMPLETE_PRODUCT_RECORD_TYPE = 'COMPLETE_PRODUCT';

const PRODUCT_PART_RECEIVED_RECORD_TYPE = 'PRODUCT_PART_RECEIVED';
Copilot is powered by AI and may make mistakes. Always verify output.

}(self, WebSocket));
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 10 months ago

To fix the problem, we need to verify the origin of incoming messages in the messageEvent handler. This involves checking the origin property of the messageEvent object to ensure it matches a trusted origin before processing the message. This change should be made in the self.onmessage function within the src/realtime/MCWSStreamWorkerScript.js file.

  1. Identify the trusted origin(s) that should be allowed to send messages.
  2. Modify the self.onmessage function to include a check for the origin property of the messageEvent object.
  3. If the origin matches the trusted origin, proceed with processing the message; otherwise, ignore the message.
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
@@ -320,6 +320,9 @@
   self.onmessage = function (messageEvent) {
-    var data = messageEvent.data,
-      method = worker[data.key];
-    if (method) {
-      method.call(worker, data.value);
+    var trustedOrigin = 'https://www.example.com'; // Replace with the actual trusted origin
+    if (messageEvent.origin === trustedOrigin) {
+      var data = messageEvent.data,
+        method = worker[data.key];
+      if (method) {
+        method.call(worker, data.value);
+      }
     }
EOF
@@ -320,6 +320,9 @@
self.onmessage = function (messageEvent) {
var data = messageEvent.data,
method = worker[data.key];
if (method) {
method.call(worker, data.value);
var trustedOrigin = 'https://www.example.com'; // Replace with the actual trusted origin
if (messageEvent.origin === trustedOrigin) {
var data = messageEvent.data,
method = worker[data.key];
if (method) {
method.call(worker, data.value);
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
return !!(this.options.frameSummaryStreamUrl || this.options.frameSummaryStreamUrl);
};
Dataset.prototype.hasFrameSummary = function () {
return !!(this.options.frameSummaryStreamUrl || this.options.frameSummaryStreamUrl);

Check warning

Code scanning / CodeQL

Identical operands Warning

Operands
this.op ... reamUrl
and
this.op ... reamUrl
are identical.
};

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 10 months ago

To fix the problem, we need to verify the origin of the incoming messages in the messageEvent handler. This involves checking the origin property of the messageEvent object against a list of trusted origins before processing the message. This ensures that only messages from trusted sources are handled, mitigating the risk of malicious attacks.

  1. Identify the trusted origins for the application.
  2. Modify the self.onmessage handler to include a check for the origin property.
  3. Only process the message if the origin is in the list of trusted origins.
Suggested changeset 1
src/services/mcws/StreamWorker.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/services/mcws/StreamWorker.js b/src/services/mcws/StreamWorker.js
--- a/src/services/mcws/StreamWorker.js
+++ b/src/services/mcws/StreamWorker.js
@@ -244,6 +244,9 @@
   self.onmessage = function (messageEvent) {
-    var data = messageEvent.data,
-      method = worker[data.key];
-    if (method) {
-      method.call(worker, data.value);
+    var trustedOrigins = ['https://www.example.com', 'https://trusted.origin'];
+    if (trustedOrigins.includes(messageEvent.origin)) {
+      var data = messageEvent.data,
+        method = worker[data.key];
+      if (method) {
+        method.call(worker, data.value);
+      }
     }
EOF
@@ -244,6 +244,9 @@
self.onmessage = function (messageEvent) {
var data = messageEvent.data,
method = worker[data.key];
if (method) {
method.call(worker, data.value);
var trustedOrigins = ['https://www.example.com', 'https://trusted.origin'];
if (trustedOrigins.includes(messageEvent.origin)) {
var data = messageEvent.data,
method = worker[data.key];
if (method) {
method.call(worker, data.value);
}
}
Copilot is powered by AI and may make mistakes. Always verify output.
if (!sessionServiceInstance) {
sessionServiceInstance = new SessionService(openmct, openmctMCWSConfig);
}
export default function (openmct, openmctMCWSConfig) {

Check warning

Code scanning / CodeQL

Inconsistent use of 'new' Warning

Anonymous function is sometimes invoked as a constructor (for example
here
), and sometimes as a normal function (for example
here
).
Copy link
Collaborator

@jvigliotta jvigliotta left a comment

Choose a reason for hiding this comment

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

Having already reviewed the previous two PR's into this branch, we good...

@jvigliotta jvigliotta merged commit d28b915 into main Feb 21, 2025
3 checks passed
@jvigliotta jvigliotta deleted the topic/219-code-lint branch February 21, 2025 19:59
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.

Add Linter to Enforce Coding Standards Across the Codebase

3 participants