fix(devtools-kit): guard SuperJSON.parse against non-string message payloads - #4
Open
arena-ai-coding-agent[bot] wants to merge 1 commit into
Open
fix(devtools-kit): guard SuperJSON.parse against non-string message payloads#4arena-ai-coding-agent[bot] wants to merge 1 commit into
arena-ai-coding-agent[bot] wants to merge 1 commit into
Conversation
…ayloads When a message event carries a non-string payload (e.g. an object posted to a shared BroadcastChannel, or a window message whose payload is not a JSON string), SuperJSON.parse throws an uncaught "SyntaxError: \"[object Object]\" is not valid JSON". This shows up in the console as an unhandled error while DevTools is running. Only attempt to parse the payload when it is a string, otherwise ignore the message. This makes the broadcast, extension-server and Vite messaging channels resilient to foreign messages on shared channels. Closes vuejs#911
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DevTools' messaging channels call
SuperJSON.parse(...)on incoming payloads. When a message event carries a non-string value (for example an object posted to a sharedBroadcastChannel, or a window message whosepayloadis not a JSON string), parsing throws an uncaught:This surfaces as an unhandled error in the console while DevTools is running (reported when
event.datais an object instead of a JSON string).Change
Guard the parse with a
typeof … === 'string'check and ignore non-string payloads in the affected channels:broadcast-channel/index.ts— only parseevent.datawhen it is a string.extension/server.ts— only parseevent.data.payloadwhen it is a string.vite/client.tsandvite/server.ts— only parse the event payload when it is a string.The
iframechannels already defensively wrap parsing in atry/catch.Tests
Full suite passes (
85tests) along withtype-check,lint, andbuild.Closes vuejs#911