From 7f0520ae9a7194a9a55810f97d2a957e67efce2f Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Tue, 24 Mar 2020 23:35:38 +0000 Subject: [PATCH] Bug 1598278 - Check that Service Worker controls client in navigate() r=asuth Differential Revision: https://phabricator.services.mozilla.com/D66040 --HG-- extra : moz-landing-system : lando --- dom/clients/api/Client.cpp | 3 +- dom/clients/manager/ClientIPCTypes.ipdlh | 1 + dom/clients/manager/ClientManagerService.cpp | 13 ++++++++ .../windowclient-navigate.https.html.ini | 32 ------------------- 4 files changed, 16 insertions(+), 33 deletions(-) delete mode 100644 testing/web-platform/meta/service-workers/service-worker/windowclient-navigate.https.html.ini diff --git a/dom/clients/api/Client.cpp b/dom/clients/api/Client.cpp index 5017b4e36013..bba8ee13817c 100644 --- a/dom/clients/api/Client.cpp +++ b/dom/clients/api/Client.cpp @@ -185,7 +185,8 @@ already_AddRefed Client::Navigate(const nsAString& aURL, } ClientNavigateArgs args(mData->info(), NS_ConvertUTF16toUTF8(aURL), - workerPrivate->GetLocationInfo().mHref); + workerPrivate->GetLocationInfo().mHref, + workerPrivate->GetServiceWorkerDescriptor().ToIPC()); RefPtr self = this; StartClientManagerOp( diff --git a/dom/clients/manager/ClientIPCTypes.ipdlh b/dom/clients/manager/ClientIPCTypes.ipdlh index 17fe458d17bb..7ab0270478ac 100644 --- a/dom/clients/manager/ClientIPCTypes.ipdlh +++ b/dom/clients/manager/ClientIPCTypes.ipdlh @@ -85,6 +85,7 @@ struct ClientNavigateArgs IPCClientInfo target; nsCString url; nsCString baseURL; + IPCServiceWorkerDescriptor serviceWorker; }; struct ClientPostMessageArgs diff --git a/dom/clients/manager/ClientManagerService.cpp b/dom/clients/manager/ClientManagerService.cpp index d9fb2fc2d2a3..5c36340c9e9f 100644 --- a/dom/clients/manager/ClientManagerService.cpp +++ b/dom/clients/manager/ClientManagerService.cpp @@ -284,6 +284,19 @@ RefPtr ClientManagerService::Navigate( return ClientOpPromise::CreateAndReject(rv, __func__); } + const IPCServiceWorkerDescriptor& serviceWorker = aArgs.serviceWorker(); + + // Per https://w3c.github.io/ServiceWorker/#dom-windowclient-navigate step 4, + // if the service worker does not control the client, reject with a TypeError. + const Maybe& controller = source->GetController(); + if (controller.isNothing() || + controller.ref().Scope() != serviceWorker.scope() || + controller.ref().Id() != serviceWorker.id()) { + CopyableErrorResult rv; + rv.ThrowTypeError("Client is not controlled by this Service Worker"); + return ClientOpPromise::CreateAndReject(rv, __func__); + } + PClientManagerParent* manager = source->Manager(); MOZ_DIAGNOSTIC_ASSERT(manager); diff --git a/testing/web-platform/meta/service-workers/service-worker/windowclient-navigate.https.html.ini b/testing/web-platform/meta/service-workers/service-worker/windowclient-navigate.https.html.ini deleted file mode 100644 index 95c4d2e4d121..000000000000 --- a/testing/web-platform/meta/service-workers/service-worker/windowclient-navigate.https.html.ini +++ /dev/null @@ -1,32 +0,0 @@ -[windowclient-navigate.https.html] - expected: [OK, ERROR, TIMEOUT] - [in scope but not controlled test on installing worker worker side] - expected: FAIL - - [in scope but not controlled test on active worker worker side] - expected: FAIL - - [out of scope worker side] - expected: FAIL - - [invalid url (about:blank)] - expected: [PASS, TIMEOUT, NOTRUN] - - [in scope but not controlled test on active worker] - expected: [PASS, NOTRUN] - - [out of scope] - expected: [PASS, NOTRUN] - - [invalid url (view-source://example.com)] - expected: [PASS, NOTRUN] - - [invalid url (http://[example.com\])] - expected: [PASS, NOTRUN] - - [invalid url (file:///)] - expected: [PASS, NOTRUN] - - [cross orgin url] - expected: [PASS, NOTRUN] -