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(); + } +}); 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));