Bug 1543314 - Cookies should be sent to the content process also for first-party channels when cookieBehavior is set to 2, r=Ehsan a=pascalc
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 10 Apr 2019 15:25:13 +0000
changeset 526325 ee086cda5837f5ad84d6a8e6fb9d9b413a90acdc
parent 526324 5e0fd434e5beaab719a82588712916f60b563b43
child 526326 34fee7231b147dd5fb2ccc6a7cfc7e5b3495b02b
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan, pascalc
bugs1543314
milestone67.0
Bug 1543314 - Cookies should be sent to the content process also for first-party channels when cookieBehavior is set to 2, r=Ehsan a=pascalc Differential Revision: https://phabricator.services.mozilla.com/D26859
netwerk/cookie/CookieServiceParent.cpp
toolkit/components/antitracking/test/browser/browser.ini
toolkit/components/antitracking/test/browser/browser_cookieBetweenTabs.js
toolkit/components/antitracking/test/browser/empty.html
--- a/netwerk/cookie/CookieServiceParent.cpp
+++ b/netwerk/cookie/CookieServiceParent.cpp
@@ -135,18 +135,18 @@ void CookieServiceParent::TrackCookieLoa
   bool isTrackingResource = false;
   bool storageAccessGranted = false;
   nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel);
   if (httpChannel) {
     isTrackingResource = httpChannel->IsTrackingResource();
     // Check first-party storage access even for non-tracking resources, since
     // we will need the result when computing the access rights for the reject
     // foreign cookie behavior mode.
-    if (isForeign && AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(
-                         httpChannel, uri, nullptr)) {
+    if (AntiTrackingCommon::IsFirstPartyStorageAccessGrantedFor(httpChannel,
+                                                                uri, nullptr)) {
       storageAccessGranted = true;
     }
   }
 
   nsTArray<nsCookie *> foundCookieList;
   mCookieService->GetCookiesForURI(
       uri, aChannel, isForeign, isTrackingResource, storageAccessGranted,
       isSafeTopLevelNav, aIsSameSiteForeign, false, attrs, foundCookieList);
--- a/toolkit/components/antitracking/test/browser/browser.ini
+++ b/toolkit/components/antitracking/test/browser/browser.ini
@@ -14,16 +14,17 @@ support-files =
   page.html
   3rdParty.html
   3rdPartySVG.html
   3rdPartyUI.html
   3rdPartyWO.html
   3rdPartyOpen.html
   3rdPartyOpenUI.html
   empty.js
+  empty.html
   popup.html
   server.sjs
   storageAccessAPIHelpers.js
   !/browser/modules/test/browser/head.js
 
 [browser_allowListNotifications.js]
 skip-if = serviceworker_e10s
 support-files = subResources.sjs
@@ -82,8 +83,9 @@ skip-if = serviceworker_e10s
 [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
+[browser_cookieBetweenTabs.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/browser_cookieBetweenTabs.js
@@ -0,0 +1,44 @@
+add_task(async function() {
+  await SpecialPowers.flushPrefEnv();
+  await SpecialPowers.pushPrefEnv({"set": [
+    ["dom.storage_access.enabled", true],
+    ["network.cookie.cookieBehavior", BEHAVIOR_REJECT],
+    ["privacy.trackingprotection.enabled", false],
+    ["privacy.trackingprotection.pbmode.enabled", false],
+    ["privacy.trackingprotection.annotate_channels", true],
+    ["dom.ipc.processCount", 4],
+  ]});
+
+  info("First tab opened");
+  let tab = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "empty.html");
+  gBrowser.selectedTab = tab;
+
+  let browser = gBrowser.getBrowserForTab(tab);
+  await BrowserTestUtils.browserLoaded(browser);
+
+  info("Disabling content blocking for this page");
+  ContentBlocking.disableForCurrentPage();
+
+  await BrowserTestUtils.browserLoaded(browser);
+
+  await ContentTask.spawn(browser, null, async _ => {
+    is(content.document.cookie, "", "No cookie set");
+    content.document.cookie = "a=b";
+    is(content.document.cookie, "a=b", "Cookie set");
+  });
+
+  info("Second tab opened");
+  let tab2 = BrowserTestUtils.addTab(gBrowser, TEST_DOMAIN + TEST_PATH + "empty.html");
+  gBrowser.selectedTab = tab2;
+
+  let browser2 = gBrowser.getBrowserForTab(tab2);
+  await BrowserTestUtils.browserLoaded(browser2);
+
+  await ContentTask.spawn(browser2, null, async _ => {
+    is(content.document.cookie, "a=b", "Cookie set");
+  });
+
+  info("Removing tabs");
+  BrowserTestUtils.removeTab(tab);
+  BrowserTestUtils.removeTab(tab2);
+});
new file mode 100644
--- /dev/null
+++ b/toolkit/components/antitracking/test/browser/empty.html
@@ -0,0 +1,1 @@
+<h1>Empty</h1>