fix(adev): validate postMessage origin in code editor iframe handler#69267
Open
S3DFX-CYBER wants to merge 2 commits into
Open
fix(adev): validate postMessage origin in code editor iframe handler#69267S3DFX-CYBER wants to merge 2 commits into
S3DFX-CYBER wants to merge 2 commits into
Conversation
Added NodeRuntimeSandbox injection and updated error handling logic.
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.
Description
The
postMessagehandler inCodeEditorComponentaccepted messages from any origin without validatingevent.origin. This allowed any cross-origin page to silently triggeropenFileAtLocationactions in the editor by sending craftedpostMessageevents.Additionally,
error-filename-handler.tsused a wildcard targetOrigin(
'*') when posting messages from the WebContainer preview iframe to the parent frame, which is a postMessage security best practiceviolation.
Changes
code-editor.component.ts: Captures the trusted preview origin fromNodeRuntimeSandbox.previewUrl$once the WebContainer dev server starts, then validatesevent.originagainst it in thehandlePostMessagehandler. Messages from any other origin are silently dropped.error-filename-handler.ts: Replaces the wildcard'*'targetOrigin with the explicit
'https://angular.dev'origin. Thismatches the existing
ANGULAR_DEVconstant used elsewhere in the component.Notes
The preview iframe runs on a dynamic
*.webcontainer.iosubdomain (cross-origin), sowindow.location.origincannot be used directly as the trusted origin. The origin is instead derived at runtime from the URL emitted bypreviewUrl$after the dev server becomes ready.