Repository navigation
fix(client): secure postMessage communications and close iframe injection vector - #1310
Open
vibemasshq-dev wants to merge 1 commit into
Open
vibemasshq-dev wants to merge 1 commit into
vibemasshq-dev wants to merge 1 commit into
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
|
@vibemasshq-dev is attempting to deploy a commit to the CodeSandbox Team on Vercel. A member of the Team first needs to authorize it. |
|
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. |
Author
|
Hello, any review on this? Thank you |
This branch has not been deployed
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.
What does this PR do?
This PR hardens the
postMessagecommunication layer insandpack-client/src/clients/node/index.tsandinject-scripts/historyListener.ts.While reviewing the event listeners, I noticed a critical nuance in how messages are handled:
messageChannelIdprovides a good security token for most dispatched events, thePREVIEW_LOADED_MESSAGE_TYPEcheck inglobalListenerslacks both channel ID and origin validation. Any malicious page that knows this public event type could send it to the Sandpack instance and triggerinjectScriptToIframe. This PR scopes that listener strictly to the expectedbundlerURLorigin.dispatchmethod,urlbackandurlforwardmessages are broadcast to the iframe using a wildcard*target origin. If the preview iframe were somehow navigated to an unexpected origin, it would receive these internal navigation commands. This PR scopes those outbound messages specifically tonew URL(this.iframePreviewUrl).origin.Architecture Heads-Up 🏗️
While investigating the messaging layer, I was looking through the
runtimeclient folder and noticed thatsandpack-client/src/clients/runtime/index.tsis growing into quite a monolithic module (~800+ lines handling everything from bundler compilation to iframe management).As Sandpack continues to scale, it might be worth decomposing that core runtime client into smaller, more focused sub-modules (e.g., separating the message handlers from the state manager) to improve testability and make onboarding easier for future contributors!
Best,
@vibemasshq-dev