From 76ed7fced97a41b71991c30db06748d520b9bec1 Mon Sep 17 00:00:00 2001 From: Alexei Date: Mon, 17 Jun 2019 12:44:58 -0400 Subject: [PATCH 1/2] Add flag to disable remote updates. --- src/data/schema.json | 5 +++++ src/js/background.js | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/data/schema.json b/src/data/schema.json index bfa36dd514..852e547ac5 100644 --- a/src/data/schema.json +++ b/src/data/schema.json @@ -14,6 +14,11 @@ "type": "string" } }, + "fetchRemoteResources": { + "title": "Fetch remote resources", + "description": "Set to false to avoid fetching more recent versions of Privacy Badger resources over the Web from eff.org.", + "type": "boolean" + }, "learnInIncognito": { "title": "Learn in Private/Incognito windows", "description": "Enabling learning in Private/Incognito windows may leave traces of your private browsing history on your computer. By default, Privacy Badger will block trackers it already knows about in Private/Incognito windows, but it won't learn about new trackers. You might want to enable this option if a lot of your browsing happens in Private/Incognito windows.", diff --git a/src/js/background.js b/src/js/background.js index 9f81949334..a5a38addef 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -313,6 +313,10 @@ Badger.prototype = { callback = _.noop; } + if (!self.getSettings().getItem("fetchRemoteResources")) { + return callback(false); + } + utils.xhrRequest(constants.YELLOWLIST_URL, function (err, response) { if (err) { console.error( @@ -397,12 +401,16 @@ Badger.prototype = { /** * Fetch acceptable DNT policy hashes from the EFF server */ - updateDNTPolicyHashes: function() { + updateDNTPolicyHashes: function () { var self = this; if (!self.isCheckingDNTPolicyEnabled()) { // user has disabled this, we can check when they re-enable - return ; + return; + } + + if (!self.getSettings().getItem("fetchRemoteResources")) { + return; } utils.xhrRequest(constants.DNT_POLICIES_URL, function(err, response) { @@ -493,6 +501,7 @@ Badger.prototype = { defaultSettings: { checkForDNTPolicy: true, disabledSites: [], + fetchRemoteResources: true, hideBlockedElements: true, isFirstRun: true, learnInIncognito: false, From f2da47a97fa12055990aae99a99804370b825caa Mon Sep 17 00:00:00 2001 From: Alexei Date: Mon, 17 Jun 2019 13:17:30 -0400 Subject: [PATCH 2/2] Add a unit test for disabling remote updates. --- src/tests/tests/yellowlist.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/tests/tests/yellowlist.js b/src/tests/tests/yellowlist.js index f67b72f1ab..b90019b82f 100644 --- a/src/tests/tests/yellowlist.js +++ b/src/tests/tests/yellowlist.js @@ -178,6 +178,33 @@ QUnit.module("Yellowlist", (hooks) => { } }); + QUnit.test("Disabling remote updates", (assert) => { + let done = assert.async(); + assert.expect(3); + + server.respondWith("GET", constants.YELLOWLIST_URL, + [200, {}, Object.keys(get_ylist()).join("\n")]); + + badger.updateYellowlist(function (success) { + assert.ok(success, "updating works by default"); + + // disable remote updates + badger.getSettings().setItem("fetchRemoteResources", false); + + badger.updateYellowlist(function (success2) { + assert.notOk(success2, "updating fails when remote updates are disabled"); + + // re-enable remote updates + badger.getSettings().setItem("fetchRemoteResources", true); + + badger.updateYellowlist(function (success3) { + assert.ok(success3, "updating works again"); + done(); + }); + }); + }); + }); + QUnit.module("Removing domains", () => { let TESTS = [ {