Closed Bug 1040257 Opened 12 years ago Closed 8 years ago

postMessage from chrome to content does not have an event.origin

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED WONTFIX

People

(Reporter: mkaply, Unassigned)

Details

We're using postMessage in our bootstrapped extension to send a message to a web page. win.postMessage({'handler': 'AppController:START_NEW_POST_EVENT', 'content': content}, 'https://new.addvocate.com'); When we receive the message on the web page, event.origin is null, so we can't safely check that the message came from where we think it came. The documentation here: https://developer.mozilla.org/en-US/docs/Web/API/window.postMessage?redirectlocale=en-US&redirectslug=DOM%2Fwindow.postMessage#Using_window.postMessage_in_extensions__ Says: > the source property of the dispatched event is always null as a security restriction. (The other properties have their expected values.) What is the expected value for event.origin in this case?
> What is the expected value for event.origin in this case? "null", since origins are only defined for things that have an authority section in their URLs and chrome:// urls don't really have that.
So is there any way for the website to know safely that it can handle the postMessage that came from the extension?
The extension could post the message from a sandbox that uses the site's principal, so the origin would be that of the site?
So something like this does seem to work: var sandbox = Components.utils.Sandbox('https://new.addvocate.com'); sandbox.win = win; sandbox.content = content; Components.utils.evalInSandbox("win.postMessage({'handler': 'AppController:START_NEW_POST_EVENT', 'content': content}, 'https://new.addvocate.com');", sandbox); Although it seems a little clunky. Is there any better way to do this?
(In reply to Mike Kaply (:mkaply) from comment #4) > Is there any better way to do this? The best idea I've got is to add a ChromeOnly (or maybe ChromeOrExpandedPrincipalOnly) method called postMessageFromOrigin that lets you explicitly specify the origin you want to come from. Boris, do you think that's worth adding?
Might be nicer than the sandbox games...
OK. So here's what needs to happen here: (1) Add a function like IsChromeOrXBL called IsSystemOrExpandedPrincipal, which checks the above. (2) Add a similar function called postMessageFromOrigin with Func=IsSystemOrExpandedPrincipal in Window.webidl. (3) Implement it in nsGlobalWindow.cpp (with a subsumes check to make sure that, in the case that the caller is an nsEP, that it subsumes the origin that it's impersonating).
Per policy at https://wiki.mozilla.org/Bug_Triage/Projects/Bug_Handling/Bug_Husbandry#Inactive_Bugs. If this bug is not an enhancement request or a bug not present in a supported release of Firefox, then it may be reopened.
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → INACTIVE
Legacy Extension.
Resolution: INACTIVE → WONTFIX
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.