Skip to content

Conversation

@riknoll
Copy link
Member

@riknoll riknoll commented Nov 21, 2024

no need to review this just yet; mostly just opening this for visibility. adds an alternate auth client that proxies cloud requests to the parent frame. in the future, i'll swap out the frame implementation with one that talks over the IPC channel to minecraft


protected handleResponse(response: pxt.editor.CloudProxyResponse) {
if (this.pendingMessages[response.id]) {
this.pendingMessages[response.id](response);

Check failure

Code scanning / CodeQL

Unvalidated dynamic method call High

Invocation of method with
user-controlled
name may dispatch to unexpected target and cause an exception.

Copilot Autofix

AI 7 months ago

To address the issue, we need to validate the response.id field before using it to access this.pendingMessages. Specifically:

  1. Check if response.id exists as a key in this.pendingMessages using Object.prototype.hasOwnProperty.call.
  2. Ensure that the value associated with response.id in this.pendingMessages is a function before invoking it.

This fix ensures that only valid and expected keys are used for dynamic method calls, mitigating the risk of runtime exceptions or unexpected behavior.


Suggested changeset 1
webapp/src/minecraftAuthClient.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/webapp/src/minecraftAuthClient.ts b/webapp/src/minecraftAuthClient.ts
--- a/webapp/src/minecraftAuthClient.ts
+++ b/webapp/src/minecraftAuthClient.ts
@@ -352,3 +352,4 @@
     protected handleResponse(response: pxt.editor.CloudProxyResponse) {
-        if (this.pendingMessages[response.id]) {
+        if (Object.prototype.hasOwnProperty.call(this.pendingMessages, response.id) &&
+            typeof this.pendingMessages[response.id] === 'function') {
             this.pendingMessages[response.id](response);
EOF
@@ -352,3 +352,4 @@
protected handleResponse(response: pxt.editor.CloudProxyResponse) {
if (this.pendingMessages[response.id]) {
if (Object.prototype.hasOwnProperty.call(this.pendingMessages, response.id) &&
typeof this.pendingMessages[response.id] === 'function') {
this.pendingMessages[response.id](response);
Copilot is powered by AI and may make mistakes. Always verify output.
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