Bug 1331769 - Properly check whether new origin permissions are a subset of old origin permissions. r?aswan draft
authorIan Moody <moz-ian@perix.co.uk>
Thu, 21 Sep 2017 17:03:15 +0100
changeset 669570 a706ec72b98159e68e8980ca5a471dcb6d1c2767
parent 669553 ff40c5dcaa41261b39a4e9795e02a9d51dd30ced
child 669571 7418a985e88c075e782d2c9d2591076ca9e18682
child 670547 706beaf19e3f2aac8ac852a50d8eba00386df8f1
push id81365
push usermoz-ian@perix.co.uk
push dateSun, 24 Sep 2017 18:53:24 +0000
reviewersaswan
bugs1331769
milestone58.0a1
Bug 1331769 - Properly check whether new origin permissions are a subset of old origin permissions. r?aswan This prevents prompts occuring in cases where the new permissions are more specific but still covered by the old permissions. e.g.: ["<all_urls>"] -> ["<all_urls>", "*://*.example.com"] ["*://*.example.com"] -> ["http://subdomain.example.com"] MozReview-Commit-ID: B685pJ6kTNa
toolkit/components/extensions/Extension.jsm
--- a/toolkit/components/extensions/Extension.jsm
+++ b/toolkit/components/extensions/Extension.jsm
@@ -482,23 +482,19 @@ this.ExtensionData = class {
     result.permissions = [...this.permissions]
       .filter(p => !result.origins.includes(p) && !EXP_PATTERN.test(p));
     return result;
   }
 
   // Compute the difference between two sets of permissions, suitable
   // for presenting to the user.
   static comparePermissions(oldPermissions, newPermissions) {
-    // See bug 1331769: should we do something more complicated to
-    // compare host permissions?
-    // e.g., if we go from <all_urls> to a specific host or from
-    // a *.domain.com to specific-host.domain.com that's actually a
-    // drop in permissions but the simple test below will cause a prompt.
+    let oldMatcher = new MatchPatternSet(oldPermissions.origins);
     return {
-      origins: newPermissions.origins.filter(perm => !oldPermissions.origins.includes(perm)),
+      origins: newPermissions.origins.filter(perm => !oldMatcher.subsumes(new MatchPattern(perm))),
       permissions: newPermissions.permissions.filter(perm => !oldPermissions.permissions.includes(perm)),
     };
   }
 
   async parseManifest() {
     let [manifest] = await Promise.all([
       this.readJSON("manifest.json"),
       Management.lazyInit(),