Bug 1560178 - disallow unsafe loads in the parent, r=bzbarsky

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gijs Kruitbosch 2019-07-12 16:29:01 +00:00
Родитель f862faa152
Коммит c097971fe3
3 изменённых файлов: 91 добавлений и 3 удалений

Просмотреть файл

@ -1564,8 +1564,8 @@ nsDocShell::SetRemoteSubframes(bool aUseRemoteSubframes) {
if (aUseRemoteSubframes && !annotated) {
annotated = true;
CrashReporter::AnnotateCrashReport(CrashReporter::Annotation::DOMFissionEnabled,
true);
CrashReporter::AnnotateCrashReport(
CrashReporter::Annotation::DOMFissionEnabled, true);
}
// Don't allow non-remote tabs with remote subframes.
@ -9534,6 +9534,86 @@ nsresult nsDocShell::InternalLoad(nsDocShellLoadState* aLoadState,
}
}
// In e10s, in the parent process, we refuse to load anything other than
// "safe" resources that we ship or trust enough to give "special" URLs.
if (XRE_IsE10sParentProcess()) {
nsCOMPtr<nsIURI> uri = aLoadState->URI();
do {
bool canLoadInParent = false;
if (NS_SUCCEEDED(NS_URIChainHasFlags(
uri, nsIProtocolHandler::URI_IS_UI_RESOURCE, &canLoadInParent)) &&
canLoadInParent) {
// We allow UI resources.
break;
}
// For about: and extension-based URIs, which don't get
// URI_IS_UI_RESOURCE, first remove layers of view-source:, if present.
while (uri && uri->SchemeIs("view-source")) {
nsCOMPtr<nsINestedURI> nested = do_QueryInterface(uri);
if (nested) {
nested->GetInnerURI(getter_AddRefs(uri));
} else {
break;
}
}
// Allow about: URIs, and allow moz-extension ones if we're running
// extension content in the parent process.
if (!uri || uri->SchemeIs("about") ||
(!StaticPrefs::extensions_webextensions_remote() &&
uri->SchemeIs("moz-extension"))) {
break;
}
nsAutoCString scheme;
uri->GetScheme(scheme);
// Allow ext+foo URIs (extension-registered custom protocols). See
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/protocol_handlers
if (StringBeginsWith(scheme, NS_LITERAL_CSTRING("ext+")) &&
!StaticPrefs::extensions_webextensions_remote()) {
break;
}
// This next bit is... awful. Basically, about:addons used to load the
// discovery pane remotely. Allow for that, if that's actually the state
// we're in (which is no longer the default at time of writing, but still
// tested). https://bugzilla.mozilla.org/show_bug.cgi?id=1565606 covers
// removing this atrocity.
nsCOMPtr<nsIWebNavigation> parent(do_QueryInterface(mParent));
if (parent) {
nsCOMPtr<nsIURI> parentURL;
parent->GetCurrentURI(getter_AddRefs(parentURL));
if (parentURL &&
parentURL->GetSpecOrDefault().EqualsLiteral("about:addons") &&
(!Preferences::GetBool("extensions.htmlaboutaddons.enabled",
true) ||
!Preferences::GetBool(
"extensions.htmlaboutaddons.discover.enabled", true))) {
nsCString discoveryURLString;
Preferences::GetCString("extensions.webservice.discoverURL",
discoveryURLString);
nsCOMPtr<nsIURI> discoveryURL;
NS_NewURI(getter_AddRefs(discoveryURL), discoveryURLString);
nsAutoCString discoveryPrePath;
if (discoveryURL) {
discoveryURL->GetPrePath(discoveryPrePath);
}
nsAutoCString requestedPrePath;
uri->GetPrePath(requestedPrePath);
// So allow the discovery path to load inside about:addons.
if (discoveryPrePath.Equals(requestedPrePath)) {
break;
}
}
}
// Final exception for some legacy automated tests:
if (xpc::IsInAutomation() &&
Preferences::GetBool("security.allow_unsafe_parent_loads", false)) {
break;
}
return NS_ERROR_FAILURE;
} while (0);
}
// Whenever a top-level browsing context is navigated, the user agent MUST
// lock the orientation of the document to the document's default
// orientation. We don't explicitly check for a top-level browsing context

Просмотреть файл

@ -2821,6 +2821,15 @@ VARCACHE_PREF(
bool, false
)
// This pref governs whether we run webextensions in a separate process (true)
// or the parent/main process (false)
VARCACHE_PREF(
Live,
"extensions.webextensions.remote",
extensions_webextensions_remote,
bool, false
)
//---------------------------------------------------------------------------
// Prefs starting with "fission."
//---------------------------------------------------------------------------

Просмотреть файл

@ -4802,7 +4802,6 @@ pref("extensions.webextensions.keepUuidOnUninstall", false);
pref("extensions.webextensions.identity.redirectDomain", "extensions.allizom.org");
pref("extensions.webextensions.restrictedDomains", "accounts-static.cdn.mozilla.net,accounts.firefox.com,addons.cdn.mozilla.net,addons.mozilla.org,api.accounts.firefox.com,content.cdn.mozilla.net,discovery.addons.mozilla.org,install.mozilla.org,oauth.accounts.firefox.com,profile.accounts.firefox.com,support.mozilla.org,sync.services.mozilla.com");
pref("extensions.webextensions.remote", false);
// Whether or not the moz-extension resource loads are remoted. For debugging
// purposes only. Setting this to false will break moz-extension URI loading
// unless other process sandboxing and extension remoting prefs are changed.