Bug 1450097 - Don't allow legacy add-ons to be installed via policy. r?felipe draft
authorMichael Kaply <mozilla@kaply.com>
Thu, 29 Mar 2018 18:05:26 -0500
changeset 775057 c9c36ec025f76cc734e5147a2b3259a580a41cf5
parent 775051 dcd10220d55aea46db212314c46d25a96a7be243
push id104583
push userbmo:mozilla@kaply.com
push dateThu, 29 Mar 2018 23:06:03 +0000
reviewersfelipe
bugs1450097
milestone61.0a1
Bug 1450097 - Don't allow legacy add-ons to be installed via policy. r?felipe MozReview-Commit-ID: LwR3PXY3RuX
browser/components/enterprisepolicies/Policies.jsm
npm-shrinkwrap.json
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -304,31 +304,47 @@ var Policies = {
               try {
                 xpiFile.initWithPath(location);
               } catch (e) {
                 log.error(`Invalid extension path location - ${location}`);
                 continue;
               }
               url = Services.io.newFileURI(xpiFile).spec;
             }
-            AddonManager.getInstallForURL(url, (install) => {
+            AddonManager.getInstallForURL(url, null, "application/x-xpinstall").then(install => {
+              if (install.addon && install.addon.appDisabled) {
+                log.error(`Incompatible add-on - ${location}`);
+                install.cancel();
+                return;
+              }
               let listener = {
+              /* eslint-disable-next-line no-shadow */
+                onDownloadEnded: (install) => {
+                  if (install.addon && install.addon.appDisabled) {
+                    log.error(`Incompatible add-on - ${location}`);
+                    install.removeListener(listener);
+                    install.cancel();
+                  }
+                },
                 onDownloadFailed: () => {
+                  install.removeListener(listener);
                   log.error(`Download failed - ${location}`);
                 },
                 onInstallFailed: () => {
+                  install.removeListener(listener);
                   log.error(`Installation failed - ${location}`);
                 },
                 onInstallEnded: () => {
+                  install.removeListener(listener);
                   log.debug(`Installation succeeded - ${location}`);
                 }
               };
               install.addListener(listener);
               install.install();
-            }, "application/x-xpinstall");
+            });
           }
         });
       }
       if ("Uninstall" in param) {
         runOncePerModification("extensionsUninstall", JSON.stringify(param.Uninstall), () => {
           AddonManager.getAddonsByIDs(param.Uninstall, (addons) => {
             for (let addon of addons) {
               if (addon) {
--- a/npm-shrinkwrap.json
+++ b/npm-shrinkwrap.json
@@ -983,33 +983,33 @@
         "is-fullwidth-code-point": "2.0.0"
       }
     },
     "sprintf-js": {
       "version": "1.0.3",
       "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
       "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
     },
+    "string_decoder": {
+      "version": "1.0.3",
+      "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
+      "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
+      "requires": {
+        "safe-buffer": "5.1.1"
+      }
+    },
     "string-width": {
       "version": "2.1.1",
       "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
       "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==",
       "requires": {
         "is-fullwidth-code-point": "2.0.0",
         "strip-ansi": "4.0.0"
       }
     },
-    "string_decoder": {
-      "version": "1.0.3",
-      "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz",
-      "integrity": "sha512-4AH6Z5fzNNBcH+6XDMfA/BTt87skxqJlO0lAh3Dker5zThcAxG6mKz+iGu308UKoPPQ8Dcqx/4JhujzltRa+hQ==",
-      "requires": {
-        "safe-buffer": "5.1.1"
-      }
-    },
     "strip-ansi": {
       "version": "4.0.0",
       "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz",
       "integrity": "sha1-qEeQIusaw2iocTibY1JixQXuNo8=",
       "requires": {
         "ansi-regex": "3.0.0"
       },
       "dependencies": {