Skip to content

Validate origin and source on DevTools extension postMessage events - #10099

Open
johnpryan wants to merge 1 commit into
masterfrom
validate-message-origin
Open

johnpryan wants to merge 1 commit into
masterfrom
validate-message-origin

Conversation

@johnpryan

Copy link
Copy Markdown
Contributor

This change validates MessageEvent.origin and MessageEvent.source on postMessage events between DevTools and extensions. Before this change, incoming message events were parsed without checking their sender, allowing untrusted origins or unrelated windows to spoof extension or host events.

  • Validate that event.origin matches the expected HTTP(S) origin of extensionUrl and verify event.source strictly equals extensionIFrame.contentWindow in ExtensionIFrameController._handleMessage, dropping and logging unexpected messages.
  • Add isAllowedDevToolsOrigin to devtools_extensions to reject empty (null), non-HTTP(S), and malformed origins, allowing only the extension's own window.origin or loopback HTTP(S) hosts.
  • Validate event.origin with isAllowedDevToolsOrigin and verify event.source strictly equals the expected window (window.parent when embedded, or window in the simulated environment) in ExtensionManager._handleMessage and SimulatedDevToolsController._handleMessage.
  • Guard against null message payloads in tryParseExtensionEvent instead of force-unwrapping data.dartify().
  • Add browser unit tests covering origin and source validation for ExtensionIFrameController, ExtensionManager, and isAllowedDevToolsOrigin, and update packages/devtools_extensions/CHANGELOG.md.

Fixes https://github.com/flutter/dash-devexp-internal/issues/86

@johnpryan
johnpryan requested review from a team and kenzieschmoll as code owners November 23, 2026 17:12
@johnpryan
johnpryan requested review from srawlins and removed request for a team November 23, 2026 17:12

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request enhances security by validating the origin and source of incoming MessageEvents in ExtensionIFrameController, ExtensionManager, and SimulatedDevToolsController before processing them. This prevents the execution of messages from untrusted origins or unexpected window sources. Comprehensive unit tests have been added to verify these validation rules. The feedback points out that the CHANGELOG entry should be updated to use the past tense to comply with the repository's style guide.

@johnpryan
johnpryan force-pushed the validate-message-origin branch from 13967ca to 4ef9029 Compare November 24, 2026 17:50
This change validates `MessageEvent.origin` and `MessageEvent.source` on `postMessage` events between DevTools and extensions. Before this change, incoming `message` events were parsed without checking their sender, allowing untrusted origins or unrelated windows to spoof extension or host events.

* Validate that `event.origin` matches the expected HTTP(S) origin of `extensionUrl` and verify `event.source` strictly equals `extensionIFrame.contentWindow` in `ExtensionIFrameController._handleMessage`, dropping and logging unexpected messages.
* Add `isAllowedDevToolsOrigin` to `devtools_extensions` to reject empty (`null`), non-HTTP(S), and malformed origins, allowing only the extension's own `window.origin` or loopback HTTP(S) hosts.
* Validate `event.origin` with `isAllowedDevToolsOrigin` and verify `event.source` strictly equals the expected window (`window.parent` when embedded, or `window` in the simulated environment) in `ExtensionManager._handleMessage` and `SimulatedDevToolsController._handleMessage`.
* Guard against `null` message payloads in `tryParseExtensionEvent` instead of force-unwrapping `data.dartify()`.
* Add browser unit tests covering origin and source validation for `ExtensionIFrameController`, `ExtensionManager`, and `isAllowedDevToolsOrigin`, and update `packages/devtools_extensions/CHANGELOG.md`.

Fixes flutter/dash-devexp-internal#86
@johnpryan
johnpryan force-pushed the validate-message-origin branch from 4ef9029 to cb171f2 Compare November 24, 2026 17:51
@johnpryan

Copy link
Copy Markdown
Contributor Author

@kenzieschmoll @srawlins could you take a look?

This branch has not been deployed

No deployments
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.

1 participant