diff --git a/caps/BasePrincipal.cpp b/caps/BasePrincipal.cpp index c59ca5e37c..6e0d001922 100644 --- a/caps/BasePrincipal.cpp +++ b/caps/BasePrincipal.cpp @@ -681,7 +681,10 @@ BasePrincipal::GetUnknownAppId(bool* aUnknownAppId) bool BasePrincipal::AddonHasPermission(const nsAString& aPerm) { - if (mOriginAttributes.mAddonId.IsEmpty()) { + nsAutoString addonId; + NS_ENSURE_SUCCESS(GetAddonId(addonId), false); + + if (addonId.IsEmpty()) { return false; } nsCOMPtr aps = @@ -689,7 +692,7 @@ BasePrincipal::AddonHasPermission(const nsAString& aPerm) NS_ENSURE_TRUE(aps, false); bool retval = false; - nsresult rv = aps->AddonHasPermission(mOriginAttributes.mAddonId, aPerm, &retval); + nsresult rv = aps->AddonHasPermission(addonId, aPerm, &retval); NS_ENSURE_SUCCESS(rv, false); return retval; } @@ -767,7 +770,10 @@ BasePrincipal::CloneStrippingUserContextIdAndFirstPartyDomain() bool BasePrincipal::AddonAllowsLoad(nsIURI* aURI) { - if (mOriginAttributes.mAddonId.IsEmpty()) { + nsAutoString addonId; + NS_ENSURE_SUCCESS(GetAddonId(addonId), false); + + if (addonId.IsEmpty()) { return false; } @@ -775,7 +781,7 @@ BasePrincipal::AddonAllowsLoad(nsIURI* aURI) NS_ENSURE_TRUE(aps, false); bool allowed = false; - nsresult rv = aps->AddonMayLoadURI(mOriginAttributes.mAddonId, aURI, &allowed); + nsresult rv = aps->AddonMayLoadURI(addonId, aURI, &allowed); return NS_SUCCEEDED(rv) && allowed; } diff --git a/caps/tests/mochitest/test_extensionURL.html b/caps/tests/mochitest/test_extensionURL.html index 315c473213..f994490f33 100644 --- a/caps/tests/mochitest/test_extensionURL.html +++ b/caps/tests/mochitest/test_extensionURL.html @@ -93,7 +93,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1161831 is(stripTrailingSlash(prin.URI.spec), url, 'Principal uri is correct: ' + url); function stripPath(s) { return s.replace(/(.*\/\/.+)\/.*/, '$1'); }; is(prin.originNoSuffix, stripPath(url), 'Principal origin is correct: ' + prin.originNoSuffix); - is(prin.originAttributes.addonId, 'imaginaryaddon-' + url[url.indexOf('/') + 2], 'addonId is correct'); + is(prin.addonId, 'imaginaryaddon-' + url[url.indexOf('/') + 2], 'addonId is correct'); if (/_blank/.test(url)) { is(SpecialPowers.wrap(ifr.contentWindow).document.documentElement.innerHTML, '', 'blank document looks right'); diff --git a/devtools/server/actors/webbrowser.js b/devtools/server/actors/webbrowser.js index 6d205d6c55..cca588423c 100644 --- a/devtools/server/actors/webbrowser.js +++ b/devtools/server/actors/webbrowser.js @@ -1390,8 +1390,8 @@ TabActor.prototype = { .outerWindowID; } - // Collect the addonID from the document origin attributes. - let addonID = window.document.nodePrincipal.originAttributes.addonId; + // Collect the addonID from the document principal. + let addonID = window.document.nodePrincipal.addonId; return { id, diff --git a/devtools/server/actors/webextension.js b/devtools/server/actors/webextension.js index 0e83fc999b..d53bb43b72 100644 --- a/devtools/server/actors/webextension.js +++ b/devtools/server/actors/webextension.js @@ -309,7 +309,15 @@ WebExtensionActor.prototype._shouldAddNewGlobalAsDebuggee = function (newGlobal) const global = unwrapDebuggerObjectGlobal(newGlobal); if (global instanceof Ci.nsIDOMWindow) { - return global.document.nodePrincipal.originAttributes.addonId == this.id; + try { + global.document; + } catch (e) { + // Sandboxes can expose a window in their prototype chain without + // having permission to access their own proto after navigation. + return false; + } + + return global.document.nodePrincipal.addonId == this.id; } try { diff --git a/toolkit/components/webextensions/ExtensionContent.jsm b/toolkit/components/webextensions/ExtensionContent.jsm index 5f9b88f35c..138cddb7f4 100644 --- a/toolkit/components/webextensions/ExtensionContent.jsm +++ b/toolkit/components/webextensions/ExtensionContent.jsm @@ -356,7 +356,7 @@ class ContentScriptContextChild extends BaseContext { // the tab holding the content page. let metadata = { "inner-window-id": this.innerWindowID, - addonId: attrs.addonId, + addonId: extensionPrincipal.addonId, }; this.sandbox = Cu.Sandbox(principal, { diff --git a/toolkit/components/webextensions/ExtensionManagement.jsm b/toolkit/components/webextensions/ExtensionManagement.jsm index 324c5b71b9..a8ce955c8c 100644 --- a/toolkit/components/webextensions/ExtensionManagement.jsm +++ b/toolkit/components/webextensions/ExtensionManagement.jsm @@ -223,8 +223,7 @@ var Service = { }, // Finds the add-on ID associated with a given moz-extension:// URI. - // This is used to set the addonId on the originAttributes for the - // nsIPrincipal attached to the URI. + // This is used to set the addonId on the nsIPrincipal attached to the URI. extensionURIToAddonID(uri) { let uuid = uri.host; let extension = this.uuidMap.get(uuid); @@ -235,11 +234,11 @@ var Service = { // API Levels Helpers // Find the add-on associated with this document via the -// principal's originAttributes. This value is computed by +// principal's addonId. This value is computed by // extensionURIToAddonID, which ensures that we don't inject our // API into webAccessibleResources or remote web pages. function getAddonIdForWindow(window) { - return Cu.getObjectPrincipal(window).originAttributes.addonId; + return Cu.getObjectPrincipal(window).addonId; } const API_LEVELS = Object.freeze({