devtools
cb171f26 - Validate extension message origin

Commit
2 hours ago
Validate extension message origin 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
Author
Committer
Parents
Loading