Bug 1546598 - Remove domain cookies in nsICookieService.removeCookiesFromRootDomain(), r=Ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 08 May 2019 22:37:02 +0000
changeset 531996 d5a1d15601fee97edc3a13598bfd16b47759fbb8
parent 531995 c3c9221f25abff8ec02a66455f3b0117c7a14fcc
child 531997 9f6e01596b42c2a9648dd4a74f8c0956724ebe6a
push id11265
push userffxbld-merge
push dateMon, 13 May 2019 10:53:39 +0000
treeherdermozilla-beta@77e0fe8dbdd3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1546598
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 1546598 - Remove domain cookies in nsICookieService.removeCookiesFromRootDomain(), r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D30384
netwerk/cookie/nsCookieService.cpp
toolkit/forgetaboutsite/test/browser/browser.ini
toolkit/forgetaboutsite/test/browser/browser_cookieDomain.js
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -4851,17 +4851,17 @@ nsresult nsCookieService::RemoveCookiesF
     }
 
     uint32_t cookiesCount = entry->GetCookies().Length();
     for (nsCookieEntry::IndexType i = cookiesCount; i != 0; --i) {
       nsListIter iter(entry, i - 1);
       RefPtr<nsCookie> cookie = iter.Cookie();
 
       bool hasRootDomain = false;
-      rv = mTLDService->HasRootDomain(cookie->Host(), aHost, &hasRootDomain);
+      rv = mTLDService->HasRootDomain(cookie->RawHost(), aHost, &hasRootDomain);
       NS_ENSURE_SUCCESS(rv, rv);
 
       if (!hasRootDomain) {
         continue;
       }
 
       // Remove the cookie.
       RemoveCookieFromList(iter);
--- a/toolkit/forgetaboutsite/test/browser/browser.ini
+++ b/toolkit/forgetaboutsite/test/browser/browser.ini
@@ -1,4 +1,5 @@
 [DEFAULT]
 support-files = browser_clearplugindata.html
 
 [browser_clearplugindata.js]
+[browser_cookieDomain.js]
new file mode 100644
--- /dev/null
+++ b/toolkit/forgetaboutsite/test/browser/browser_cookieDomain.js
@@ -0,0 +1,35 @@
+let {ForgetAboutSite} = ChromeUtils.import("resource://gre/modules/ForgetAboutSite.jsm");
+
+function checkCookie(host, originAttributes) {
+  for (let cookie of Services.cookies.enumerator) {
+    if (ChromeUtils.isOriginAttributesEqual(originAttributes,
+                                            cookie.originAttributes) &&
+        cookie.host.includes(host)) {
+      return true;
+    }
+  }
+  return false;
+}
+
+add_task(async _ => {
+  info("Test single cookie domain");
+
+  // Let's clean up all the data.
+  await new Promise(resolve => {
+    Services.clearData.deleteData(Ci.nsIClearDataService.CLEAR_ALL, resolve);
+  });
+
+  // A cookie domain
+  Services.cookies.add(".example.com", "/test", "foo", "bar",
+    false, false, false, Date.now() + 24000 * 60 * 60, {},
+    Ci.nsICookie2.SAMESITE_UNSET);
+
+  // Cleaning up.
+  await ForgetAboutSite.removeDataFromDomain("example.com");
+
+  // All good.
+  ok(!checkCookie("example.com", {}), "No cookies");
+
+  // Clean up.
+  await Sanitizer.sanitize([ "cookies", "offlineApps" ]);
+});