Bug 1536110 - StorageAccess should be propagated to workers, r=Ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 20 Mar 2019 01:06:33 +0000
changeset 465155 c51e49873b76b33aa9271c24a0a5214c5342d04e
parent 465154 1df7ae29b1214757985e5406ecababb9c08b0a9c
child 465156 e4044386c8ae00a2ac888b73458ccae53a51b172
push id35732
push useropoprus@mozilla.com
push dateWed, 20 Mar 2019 10:52:37 +0000
treeherdermozilla-central@708979f9c3f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1536110
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1536110 - StorageAccess should be propagated to workers, r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D23861
dom/base/nsGlobalWindowInner.cpp
toolkit/components/antitracking/test/browser/browser.ini
toolkit/components/antitracking/test/browser/browser_workerPropagation.js
toolkit/components/antitracking/test/browser/workerIframe.html
--- a/dom/base/nsGlobalWindowInner.cpp
+++ b/dom/base/nsGlobalWindowInner.cpp
@@ -6806,16 +6806,18 @@ void nsGlobalWindowInner::StoreSharedWor
 void nsGlobalWindowInner::ForgetSharedWorker(SharedWorker* aSharedWorker) {
   MOZ_ASSERT(aSharedWorker);
   MOZ_ASSERT(mSharedWorkers.Contains(aSharedWorker));
 
   mSharedWorkers.RemoveElement(aSharedWorker);
 }
 
 void nsGlobalWindowInner::StorageAccessGranted() {
+  PropagateFirstPartyStorageAccessGrantedToWorkers(this);
+
   // If we have a partitioned localStorage, it's time to replace it with a real
   // one in order to receive notifications.
 
   if (mLocalStorage &&
       mLocalStorage->Type() == Storage::ePartitionedLocalStorage) {
     IgnoredErrorResult error;
     GetLocalStorage(error);
     if (NS_WARN_IF(error.Failed())) {
--- a/toolkit/components/antitracking/test/browser/browser.ini
+++ b/toolkit/components/antitracking/test/browser/browser.ini
@@ -82,8 +82,10 @@ skip-if = serviceworker_e10s
 [browser_storageAccessWithHeuristics.js]
 [browser_allowPermissionForTracker.js]
 [browser_denyPermissionForTracker.js]
 [browser_localStorageEvents.js]
 support-files = localStorage.html
 [browser_partitionedLocalStorage.js]
 [browser_partitionedLocalStorage_events.js]
 support-files = localStorageEvents.html
+[browser_workerPropagation.js]
+support-files = workerIframe.html
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/browser_workerPropagation.js
@@ -0,0 +1,74 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/* eslint-disable mozilla/no-arbitrary-setTimeout */
+
+add_task(async function() {
+  info("Starting subResources test");
+
+  await SpecialPowers.flushPrefEnv();
+  await SpecialPowers.pushPrefEnv({"set": [
+    ["browser.contentblocking.allowlist.annotations.enabled", true],
+    ["browser.contentblocking.allowlist.storage.enabled", true],
+    [ContentBlocking.prefIntroCount, ContentBlocking.MAX_INTROS],
+    ["dom.storage_access.auto_grants", true],
+    ["dom.storage_access.auto_grants.delayed", false],
+    ["dom.storage_access.enabled", true],
+    ["dom.storage_access.prompt.testing", false],
+    ["network.cookie.cookieBehavior", Ci.nsICookieService.BEHAVIOR_REJECT_TRACKER],
+    ["privacy.trackingprotection.enabled", false],
+    ["privacy.trackingprotection.pbmode.enabled", false],
+    ["privacy.trackingprotection.annotate_channels", true],
+    ["privacy.restrict3rdpartystorage.userInteractionRequiredForHosts", "tracking.example.com,tracking.example.org"],
+  ]});
+
+  await UrlClassifierTestUtils.addTestTrackers();
+
+  info("Creating a new tab");
+  let tab = BrowserTestUtils.addTab(gBrowser, TEST_TOP_PAGE);
+  gBrowser.selectedTab = tab;
+
+  let browser = gBrowser.getBrowserForTab(tab);
+  await BrowserTestUtils.browserLoaded(browser);
+
+  // Let's create an iframe and run the test there.
+  let page = TEST_3RD_PARTY_DOMAIN + TEST_PATH + "workerIframe.html";
+  await ContentTask.spawn(browser, page, async function(page) {
+    await new content.Promise(resolve => {
+      let ifr = content.document.createElement("iframe");
+      ifr.id = "test";
+
+      content.addEventListener("message", e => {
+        if (e.data.type == "finish") {
+          resolve();
+          return;
+        }
+
+        if (e.data.type == "info") {
+          info(e.data.msg);
+          return;
+        }
+
+        if (e.data.type == "ok") {
+          ok(e.data.what, e.data.msg);
+          return;
+        }
+
+        ok(false, "Unknown message");
+      });
+
+      content.document.body.appendChild(ifr);
+      ifr.src = page;
+    });
+  });
+
+  info("Removing the tab");
+  BrowserTestUtils.removeTab(tab);
+});
+
+add_task(async function() {
+  info("Cleaning up.");
+  await new Promise(resolve => {
+    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, value => resolve());
+  });
+});
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/workerIframe.html
@@ -0,0 +1,71 @@
+<html>
+<head>
+  <title>3rd party content!</title>
+  <script type="text/javascript" src="https://example.com/browser/toolkit/components/antitracking/test/browser/storageAccessAPIHelpers.js"></script>
+</head>
+<body>
+<h1>Here the 3rd party content!</h1>
+<script>
+
+function info(msg) {
+  parent.postMessage({ type: "info", msg }, "*");
+}
+
+function ok(what, msg) {
+  parent.postMessage({ type: "ok", what: !!what, msg }, "*");
+}
+
+function is(a, b, msg) {
+  ok(a === b, msg);
+}
+
+async function runTest() {
+  function workerCode() {
+    onmessage = e => {
+      try {
+        indexedDB.open("test", "1");
+        postMessage(true);
+      } catch (e) {
+        postMessage(false);
+      }
+    };
+  }
+
+  /* import-globals-from storageAccessAPIHelpers.js */
+  await noStorageAccessInitially();
+  info("Initialized");
+
+  let blob = new Blob([workerCode.toString() + "; workerCode();"]);
+  let blobURL = URL.createObjectURL(blob);
+  info("Blob created");
+
+  let w = new Worker(blobURL);
+  info("Worker created");
+
+  await new Promise(resolve => {
+    w.addEventListener("message", e => {
+      ok(!e.data, "IDB is disabled");
+      resolve();
+    }, { once: true });
+    w.postMessage("go");
+  });
+
+  /* import-globals-from storageAccessAPIHelpers.js */
+  await callRequestStorageAccess();
+
+  await new Promise(resolve => {
+    w.addEventListener("message", e => {
+      ok(e.data, "IDB is enabled");
+      resolve();
+    }, { once: true });
+    w.postMessage("go");
+  });
+
+  parent.postMessage({ type: "finish" }, "*");
+}
+
+runTest();
+
+</script>
+</body>
+</html>