Bug 1568991 - Ensure marionette event listeners are isolated from content, r=ato,bzbarsky

Internal marionette listeners should neither be visible to content
script, nor have their registation affected by changes made in
content. The evaluate method was breaking these constraints by
creating listeners in a sandbox with Xrays disabled, which is
appropriate to the injected script itself but not to the
harness-internal parts.

Use a different sandbox for the harness code compared to the injected
code, and move away from using onunload to using addEventListener for
the unload handler.

Differential Revision: https://phabricator.services.mozilla.com/D39522

--HG--
extra : moz-landing-system : lando
This commit is contained in:
James Graham 2019-07-29 08:48:50 +00:00
parent a4f1b3fdcd
commit 027befb9ba

View File

@ -99,6 +99,8 @@ evaluate.sandbox = function(
) {
let unloadHandler;
let marionetteSandbox = sandbox.create(sb.window);
// timeout handler
let scriptTimeoutID, timeoutPromise;
if (timeout !== null) {
@ -128,9 +130,9 @@ evaluate.sandbox = function(
unloadHandler = sandbox.cloneInto(
() => reject(new JavaScriptError("Document was unloaded")),
sb
marionetteSandbox
);
sb.window.onunload = unloadHandler;
marionetteSandbox.window.addEventListener("unload", unloadHandler);
let promises = [
Cu.evalInSandbox(src, sb, "1.8", file, line),
@ -165,7 +167,7 @@ evaluate.sandbox = function(
})
.finally(() => {
clearTimeout(scriptTimeoutID);
sb.window.removeEventListener("unload", unloadHandler);
marionetteSandbox.window.removeEventListener("unload", unloadHandler);
});
};