Bug 1482055 - Cleanup old cookies at shutdown if network.cookie.lifetimePolicy is ACCEPT_SESSION, r=johannh
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 24 Oct 2018 17:48:17 +0200
changeset 442772 14c0adad8a503f183a52ae35466da67c1f72f186
parent 442771 f54dd68a3330bc25ff9896a0dcc08cc69d19d936
child 442773 5671f49a7aa58b30a557cb965fe422a285613a2b
push id109233
push useramarchesini@mozilla.com
push dateWed, 24 Oct 2018 15:48:49 +0000
treeherdermozilla-inbound@14c0adad8a50 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjohannh
bugs1482055
milestone65.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 1482055 - Cleanup old cookies at shutdown if network.cookie.lifetimePolicy is ACCEPT_SESSION, r=johannh
browser/modules/Sanitizer.jsm
--- a/browser/modules/Sanitizer.jsm
+++ b/browser/modules/Sanitizer.jsm
@@ -733,16 +733,30 @@ async function sanitizeSessionPrincipals
   }).catch(() => []);
 
   let serviceWorkers = serviceWorkerManager.getAllRegistrations();
   for (let i = 0; i < serviceWorkers.length; i++) {
     let sw = serviceWorkers.queryElementAt(i, Ci.nsIServiceWorkerRegistrationInfo);
     principals.push(sw.principal);
   }
 
+  // Let's take the list of unique hosts+OA from cookies.
+  let enumerator = Services.cookies.enumerator;
+  let hosts = new Set();
+  for (let cookie of enumerator) {
+    hosts.add(cookie.host + ChromeUtils.originAttributesToSuffix(cookie.originAttributes));
+  }
+
+  hosts.forEach(host => {
+    // Cookies and permissions are handled by origin/host. Doesn't matter if we
+    // use http: or https: schema here.
+    principals.push(
+      Services.scriptSecurityManager.createCodebasePrincipalFromOrigin("https://" + host));
+  });
+
   await maybeSanitizeSessionPrincipals(principals);
 }
 
 // This method receives a list of principals and it checks if some of them need
 // to be sanitize.
 async function maybeSanitizeSessionPrincipals(principals) {
   let promises = [];
 
@@ -756,17 +770,18 @@ async function maybeSanitizeSessionPrinc
   }
 
   return Promise.all(promises);
 }
 
 async function sanitizeSessionPrincipal(principal) {
   await new Promise(resolve => {
     Services.clearData.deleteDataFromPrincipal(principal, true /* user request */,
-                                               Ci.nsIClearDataService.CLEAR_DOM_STORAGES,
+                                               Ci.nsIClearDataService.CLEAR_DOM_STORAGES |
+                                               Ci.nsIClearDataService.CLEAR_COOKIES,
                                                resolve);
   });
 }
 
 function sanitizeNewTabSegregation() {
   let identity = ContextualIdentityService.getPrivateIdentity("userContextIdInternal.thumbnail");
   if (identity) {
     Services.obs.notifyObservers(null, "clear-origin-attributes-data",