From 4f9dae786d36cd1a1bf7b462331369b770fc12e7 Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Thu, 14 Sep 2017 15:11:21 +0800 Subject: [PATCH 1/2] Bug 1384330 - Part 1: Blocking the mozAddonManager when pref 'privacy.resistFingerprinting.block_mozAddonManager' is true. r=arthuredelstein,mossop This patch adds a hidden pref 'privacy.resistFingerprinting.block_mozAddonManager', which is false by default. When this is true, the navigator.mozAddonManager will be blocked even the website is AMO. The purpose of this pref is for Tor browser can disable navigator.mozAddonManager through this. MozReview-Commit-ID: Lf37gHXETCz --- toolkit/mozapps/extensions/AddonManagerWebAPI.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/toolkit/mozapps/extensions/AddonManagerWebAPI.cpp b/toolkit/mozapps/extensions/AddonManagerWebAPI.cpp index 3f2a7a5299f20..17ea9b0210cc3 100644 --- a/toolkit/mozapps/extensions/AddonManagerWebAPI.cpp +++ b/toolkit/mozapps/extensions/AddonManagerWebAPI.cpp @@ -20,6 +20,12 @@ using namespace mozilla::dom; static bool IsValidHost(const nsACString& host) { + // This hidden pref allows users to disable mozAddonManager entirely if they want + // for fingerprinting resistance. Someone like Tor browser will use this pref. + if (Preferences::GetBool("privacy.resistFingerprinting.block_mozAddonManager")) { + return false; + } + // This is ugly, but Preferences.h doesn't have support // for default prefs or locked prefs nsCOMPtr prefService (do_GetService(NS_PREFSERVICE_CONTRACTID)); From 835188bd109aec9c13e27e6c0c2b49489f2f93a7 Mon Sep 17 00:00:00 2001 From: Tim Huang Date: Thu, 14 Sep 2017 16:49:33 +0800 Subject: [PATCH 2/2] Bug 1384330 - Part 2: Add a test case for testing that navigator.mozAddonManager is correctly blocked when pref 'privacy.resistFingerprinting.block_mozAddonManager' is true. r=arthuredelstein,mossop The patch adds a test case which will first test with the pref off to see that navigator.mozAddonManager can be accessed successfully. And then turn the pref on to see that whether navigator.mozAddonManager is blocked. MozReview-Commit-ID: 3nptUqdg7p7 --- .../test/browser/browser.ini | 1 + .../browser/browser_block_mozAddonManager.js | 35 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 browser/components/resistfingerprinting/test/browser/browser_block_mozAddonManager.js diff --git a/browser/components/resistfingerprinting/test/browser/browser.ini b/browser/components/resistfingerprinting/test/browser/browser.ini index cc5adcad044d5..0124998f41723 100644 --- a/browser/components/resistfingerprinting/test/browser/browser.ini +++ b/browser/components/resistfingerprinting/test/browser/browser.ini @@ -8,6 +8,7 @@ support-files = file_workerPerformance.js head.js +[browser_block_mozAddonManager.js] [browser_navigator.js] [browser_netInfo.js] [browser_performanceAPI.js] diff --git a/browser/components/resistfingerprinting/test/browser/browser_block_mozAddonManager.js b/browser/components/resistfingerprinting/test/browser/browser_block_mozAddonManager.js new file mode 100644 index 0000000000000..ee094670983ee --- /dev/null +++ b/browser/components/resistfingerprinting/test/browser/browser_block_mozAddonManager.js @@ -0,0 +1,35 @@ +/** + * Bug 1384330 - A test case for making sure the navigator.mozAddonManager will + * be blocked when pref 'privacy.resistFingerprinting.block_mozAddonManager' is true. + */ + +const TEST_PATH = "https://example.com/browser/browser/" + + "components/resistfingerprinting/test/browser/" + +add_task(async function test() { + await SpecialPowers.pushPrefEnv({"set": + [["extensions.webapi.testing", true]] + }); + + for (let pref of [false, true]) { + await SpecialPowers.pushPrefEnv({"set": + [["privacy.resistFingerprinting.block_mozAddonManager", pref]] + }); + + let tab = await BrowserTestUtils.openNewForegroundTab( + gBrowser, TEST_PATH + "file_dummy.html"); + + await ContentTask.spawn(tab.linkedBrowser, pref, function(aPref) { + if (aPref) { + is(content.navigator.mozAddonManager, undefined, + "The navigator.mozAddonManager should not exist when the pref is on."); + } else { + ok(content.navigator.mozAddonManager, + "The navigator.mozAddonManager should exist when the pref is off."); + } + }); + + await BrowserTestUtils.removeTab(tab); + await SpecialPowers.popPrefEnv(); + } +});