Bug 1336364 P5 Disable service worker getRegistrations() if storage is disallowed for a window. r=asuth

This commit is contained in:
Ben Kelly 2017-09-20 09:24:07 -07:00
Родитель 2e6f616841
Коммит 3e50d90115
3 изменённых файлов: 29 добавлений и 8 удалений

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

@ -1080,14 +1080,19 @@ ServiceWorkerManager::GetRegistrations(mozIDOMWindow* aWindow,
}
auto* window = nsPIDOMWindowInner::From(aWindow);
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
if (NS_WARN_IF(!doc)) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
// Don't allow a service worker to access service worker registrations
// from a window with storage disabled. If these windows can access
// the registration it increases the chance they can bypass the storage
// block via postMessage(), etc.
auto storageAllowed = nsContentUtils::StorageAllowedForWindow(window);
if (storageAllowed != nsContentUtils::StorageAccess::eAllow) {
return NS_ERROR_DOM_SECURITY_ERR;
}
// Don't allow service workers to register when the *document* is chrome for
// now.
MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(doc->NodePrincipal()));
MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(window->GetExtantDoc()->NodePrincipal()));
nsCOMPtr<nsIGlobalObject> sgo = do_QueryInterface(window);
ErrorResult result;
@ -1193,14 +1198,19 @@ ServiceWorkerManager::GetRegistration(mozIDOMWindow* aWindow,
}
auto* window = nsPIDOMWindowInner::From(aWindow);
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
if (NS_WARN_IF(!doc)) {
return NS_ERROR_DOM_INVALID_STATE_ERR;
// Don't allow a service worker to access service worker registrations
// from a window with storage disabled. If these windows can access
// the registration it increases the chance they can bypass the storage
// block via postMessage(), etc.
auto storageAllowed = nsContentUtils::StorageAllowedForWindow(window);
if (storageAllowed != nsContentUtils::StorageAccess::eAllow) {
return NS_ERROR_DOM_SECURITY_ERR;
}
// Don't allow service workers to register when the *document* is chrome for
// now.
MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(doc->NodePrincipal()));
MOZ_ASSERT(!nsContentUtils::IsSystemPrincipal(window->GetExtantDoc()->NodePrincipal()));
nsCOMPtr<nsIGlobalObject> sgo = do_QueryInterface(window);
ErrorResult result;

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

@ -166,6 +166,15 @@ function testShouldNotIntercept(policy, done) {
next: function() {
iframe.src = thirdPartyOrigin + basePath + "unregister.html";
}
}, {
status: "getregistrationfailed",
next: function() {
SpecialPowers.pushPrefEnv({"set": [
["network.cookie.cookieBehavior", COOKIE_BEHAVIOR_ACCEPT],
]}, function() {
iframe.src = thirdPartyOrigin + basePath + "unregister.html";
});
}
}, {
status: "unregistrationdone",
next: function() {

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

@ -7,5 +7,7 @@
registration.unregister().then(() => {
window.parent.postMessage({status: "unregistrationdone"}, "*");
});
}).catch(function(e) {
window.parent.postMessage({status: "getregistrationfailed"}, "*");
});
</script>