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 491104 14c0adad8a503f183a52ae35466da67c1f72f186
parent 491103 f54dd68a3330bc25ff9896a0dcc08cc69d19d936
child 491105 5671f49a7aa58b30a557cb965fe422a285613a2b
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjohannh
bugs1482055
milestone65.0a1
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",