Conversation
| reject(new Error(event.data.error || "Screenshot capture failed")); | ||
| } | ||
| } | ||
| window.addEventListener("message", onMessage); |
Check failure
Code scanning / SonarCloud
Origins should be verified during cross-origin communications High
| window.removeEventListener("message", onMessage); | ||
| reject(new Error("Screenshot capture timed out after 30 seconds")); | ||
| }, TIMEOUT_MS); | ||
| window.postMessage({ type: "phoenix_screenshot_request", id }, "*"); |
Check failure
Code scanning / SonarCloud
Origins should be verified during cross-origin communications High
|
|
||
| // Dispatch to registered handler, or built-in defaults | ||
| if (msg.type && handlers[msg.type]) { | ||
| handlers[msg.type](msg); |
Check failure
Code scanning / CodeQL
Unvalidated dynamic method call High
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 1 day ago
In general, to fix unvalidated dynamic method calls, we should ensure that the property name derived from untrusted data is validated against a known set of allowed values, or at least check that the looked-up property is an own property and that its value is a function before invoking it. This prevents unexpected prototype methods or non-functions from being called and avoids runtime exceptions from malformed inputs.
Here, the best targeted fix is to guard the call to handlers[msg.type](msg) with checks that (1) msg.type is a string, (2) handlers actually has that key as an own property (not via the prototype chain), and (3) the resulting value is a function. If any of these checks fail, we simply ignore the message (or could add optional logging) without throwing. This preserves existing behavior for valid messages, while safely handling malicious or malformed ones.
Concretely, in src/phoenix-builder/phoenix-builder-boot.js, in the ws.onmessage handler around lines 251–264, replace the current dispatch block:
// Dispatch to registered handler, or built-in defaults
if (msg.type && handlers[msg.type]) {
handlers[msg.type](msg);
} else if (msg.type === "ping") {
_sendMessage({ type: "pong" });
}with a safer version that uses Object.prototype.hasOwnProperty.call and a function-type check:
// Dispatch to registered handler, or built-in defaults
if (typeof msg.type === "string" &&
Object.prototype.hasOwnProperty.call(handlers, msg.type) &&
typeof handlers[msg.type] === "function") {
handlers[msg.type](msg);
} else if (msg.type === "ping") {
_sendMessage({ type: "pong" });
}This change stays within the shown snippet, adds no new imports, and does not alter visible functionality for correct inputs.
| @@ -257,7 +257,9 @@ | ||
| } | ||
|
|
||
| // Dispatch to registered handler, or built-in defaults | ||
| if (msg.type && handlers[msg.type]) { | ||
| if (typeof msg.type === "string" && | ||
| Object.prototype.hasOwnProperty.call(handlers, msg.type) && | ||
| typeof handlers[msg.type] === "function") { | ||
| handlers[msg.type](msg); | ||
| } else if (msg.type === "ping") { | ||
| _sendMessage({ type: "pong" }); |
|




No description provided.