Bug 1319070 - Match against the principal. r=kmag

MozReview-Commit-ID: BB6UfZ6qjKr
This commit is contained in:
Tomislav Jovanovic 2016-11-23 18:46:10 +01:00
parent 9bf0b6bb08
commit 5c8692f989
2 changed files with 15 additions and 5 deletions

View File

@ -135,7 +135,7 @@ exports.testEmbeddedWebExtensionContentScript = function* (assert, done) {
browser.runtime.onConnect.addListener(portListener);
});
let url = "data:text/html;charset=utf-8,<h1>Test Page</h1>";
let url = "http://example.org/";
var openedTab;
tabs.once('open', function onOpen(tab) {

View File

@ -143,6 +143,7 @@ Script.prototype = {
matches(window) {
let uri = window.document.documentURIObject;
let principal = window.document.nodePrincipal;
// If mozAddonManager is present on this page, don't allow
// content scripts.
@ -150,16 +151,25 @@ Script.prototype = {
return false;
}
if (this.match_about_blank && ["about:blank", "about:srcdoc"].includes(uri.spec)) {
const principal = window.document.nodePrincipal;
if (this.match_about_blank) {
// When matching top-level about:blank documents,
// allow loading into any with a NullPrincipal.
if (window === window.top && principal.isNullPrincipal) {
if (uri.spec === "about:blank" && window === window.top && principal.isNullPrincipal) {
return true;
}
// When matching about:blank/srcdoc iframes, the checks below
// need to be performed against the "owner" document's URI.
if (["about:blank", "about:srcdoc"].includes(uri.spec)) {
uri = principal.URI;
}
}
// Documents from data: URIs also inherit the principal.
if (Services.netUtils.URIChainHasFlags(uri, Ci.nsIProtocolHandler.URI_INHERITS_SECURITY_CONTEXT)) {
if (!this.match_about_blank) {
return false;
}
uri = principal.URI;
}