-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal: Provide a secure drop-in replacement for window.postMessage()
#77
Comments
window.postMessage()
Once an API has been introduced to get the frameId of a frame (#12), it becomes more feasible to introduce an extension API to allow communication between content scripts in a tab. @carlosjeurissen As mentoned in #89 (meeting notes of today's meeting), you were going to file an issue about globally unique frameIDs, right? Otherwise it may be somewhat difficult to communicate between frames in different tabs (e.g. |
@Rob--W Correct. See #90 browser.runtime.sendFrameMessage(frameId, "ping"); Or update sendMessage to also allow a target object instead of an extensionId. So you get: browser.runtime.sendMessage({
frameId: someFrameId
}, "ping"); And the extension target could then be specified like this: browser.runtime.sendMessage({
extensionId: someFrameId
}, "ping"); |
I've opened an issue on CRBug to track the Edit 2021-10-11: Whoops, meant to comment in issue 12. Thanks for covering me, @carlosjeurissen! |
As mentioned in #12, exposing an API to get both the frame and the tab ID would be beneficial here too. |
Such a replacement must support FWIW, there's a simple method of secure communication shown here. TLDR it creates the iframe with a random token in the URL inside a closed ShadowDOM so the site cannot see it, then sends MessageChannel's port into the iframe that will be accepted only if the message equals that random token, then this port will be used for all communication. Of course this is also slightly convoluted, hence it won't be used by 99% of extensions. |
Along with @tophf I came up with a similar trivially simple securement idea myself, having just reading the description of this bug. The one thing I would absolutely hate to see happen is that we break & disable the deliberate ability for the page & extensions to communicate in ad-hoc manners. Extensions right now have the capability & right to listen to the page, and the page has the right to communicate to them. This is not a bug! I'm tentatively ok with adding something more secure, but it would be horrific if we were to unweave the broader web extension capability with a an aggressively retrogressive alternative that does far less.
I dunno. I think adding Not an insufficient argument to say no, but, have we seen this be an issue yet? Absolutely, extensions should have more control than the page. There seem to be a good number of easy to do options here. I'm interested in this capability, in offering better securement, but the web already seems to offer a very clear securement channel. I'm afraid that trying to go further might run afoul of the Low Level Extensibility Manifesto, by offering some kind of high level option that might not really be as well suited as we might desire, and might cut off the more general platform capability that already permits fine security (with extremely small lift, albeit lift many aren't informed about). |
This is proposed in the past by Palant. See CrBugReport. He found several security vulnerabilities related to the less secure postMessage API in extensions. And concluded a drop-in replacement is a must have.
Extension content scripts will often use window.postMessage() for internal communication within a tab. This is almost always a security issue. On the one hand, this communication is visible to the website and might leak private information. On the other hand, it’s impossible to distinguish legitimate messages from those sent by the website. Examples of security issues this introduces:
No amount of educating extension developers about runtime.sendMessage() is going to help here. This alternative is just too complicated when you merely need to send a message to another frame in the same tab: you need code in the background page to forward your messages, and you need to somehow figure out the frame ID of the target frame. This is complicated and error-prone, so it is unsurprising that developers choose window.postMessage() given how it “just works.”
A simpler API could help here, even if it is merely JavaScript boilerplate wrapping runtime.sendMessage() – as long as extension developers don’t need to write that boilerplate code themselves. Something like this:
The important properties here: communication isn’t visible to website or other extensions, incoming message are guaranteed to originate from content scripts of the same extension.
The text was updated successfully, but these errors were encountered: