Skip to content

Commit

Permalink
Merge pull request #1391 from Ghoughpteighbteau/issue-1389
Browse files Browse the repository at this point in the history
Added option to disable EFF Do Not Track policy checking.
  • Loading branch information
ghostwords authored May 25, 2017
2 parents 9fed305 + bf7f9a8 commit f6a67f6
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/_locales/en_US/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
"options_title": {
"message": "Privacy Badger Options"
},
"options_dnt_policy_setting": {
"message": "Check if sites comply with EFF's Do Not Track policy"
},
"options_dnt_policy_learn_more": {
"message": "Learn more"
},
"options_webrtc_setting": {
"message": "Prevent WebRTC from leaking local IP address *"
},
Expand Down
19 changes: 17 additions & 2 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ Badger.prototype = {
* Fetch acceptable DNT policy hashes from the EFF server
*/
updateDNTPolicyHashes: function(){
if (! badger.isCheckingDNTPolicyEnabled()) {
// user has disabled this, we can check when they re-enable
return ;
}

var self = this;
utils.xhrRequest(constants.DNT_POLICIES_URL, function(err,response){
if(err){
Expand All @@ -322,10 +327,15 @@ Badger.prototype = {
return;
}

log('Checking', domain, 'for DNT policy.');

var badger = this;

if (! badger.isCheckingDNTPolicyEnabled()) {
// user has disabled this check
return ;
}

log('Checking', domain, 'for DNT policy.');

// update timestamp first;
// avoids queuing the same domain multiple times
var recheckTime = utils.getRandom(
Expand Down Expand Up @@ -382,6 +392,7 @@ Badger.prototype = {
*/
defaultSettings: {
socialWidgetReplacementEnabled: true,
checkForDNTPolicy: true,
showCounter: true,
disabledSites: [],
isFirstRun: true,
Expand Down Expand Up @@ -565,6 +576,10 @@ Badger.prototype = {
return this.getSettings().getItem("socialWidgetReplacementEnabled");
},

isCheckingDNTPolicyEnabled: function() {
return this.getSettings().getItem("checkForDNTPolicy");
},

/**
* Check if WebRTC IP leak protection is enabled; query Chrome's internal
* value, update our local setting if it has gone out of sync, then return our
Expand Down
8 changes: 8 additions & 0 deletions src/js/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ function loadOptions() {
$("#show_counter_checkbox").prop("checked", badger.showCounter());
$("#replace_social_widgets_checkbox").click(updateSocialWidgetReplacement);
$("#replace_social_widgets_checkbox").prop("checked", badger.isSocialWidgetReplacementEnabled());
$("#check_dnt_policy_checkbox").click(updateCheckingDNTPolicy);
$("#check_dnt_policy_checkbox").prop("checked", badger.isCheckingDNTPolicyEnabled());
if(chrome.privacy && badger.webRTCAvailable){
$("#toggle_webrtc_mode").click(toggleWebRTCIPProtection);
$("#toggle_webrtc_mode").prop("checked", badger.isWebRTCIPProtectionEnabled());
Expand Down Expand Up @@ -210,6 +212,12 @@ function updateSocialWidgetReplacement() {
settings.setItem("socialWidgetReplacementEnabled", replaceSocialWidgets);
}

function updateCheckingDNTPolicy() {
var newDNTSetting = $("#check_dnt_policy_checkbox").prop("checked");
settings.setItem("checkForDNTPolicy", newDNTSetting);
refreshFilterPage(); // This setting means sites need to be re-evaluated
}

function reloadWhitelist() {
var sites = settings.getItem("disabledSites");
var sitesList = $('#excludedDomainsBox');
Expand Down
4 changes: 4 additions & 0 deletions src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ BadgerPen.prototype = {
* @returns {String} the presumed action for this FQDN
**/
getAction: function (domain, ignoreDNT) {
if(! badger.isCheckingDNTPolicyEnabled()){
ignoreDNT = true;
}

if (_.isString(domain)) {
domain = this.getBadgerStorageObject('action_map').getItem(domain) || {};
}
Expand Down
7 changes: 7 additions & 0 deletions src/skin/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ <h1><span class="i18n_options_title"></span></h1>
<span class="i18n_options_social_widgets_checkbox"></span>
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="check_dnt_policy_checkbox">
<span class="i18n_options_dnt_policy_setting"></span>
</label>
<a target="_blank" href="https://www.eff.org/dnt-policy"><span class="i18n_options_dnt_policy_learn_more"></span></a>
</div>
<div class="checkbox" id="webRTCToggle">
<label>
<input type="checkbox" id="toggle_webrtc_mode">
Expand Down
21 changes: 21 additions & 0 deletions src/tests/tests/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,25 @@
}
});

QUnit.test("DNT checking obeys user setting", (assert) => {
const NUM_TESTS = 5;

let done = assert.async(NUM_TESTS);
// TODO: unit tests may be effected by user settings, and should be isolated somehow
let old_dnt_check_func = badger.isCheckingDNTPolicyEnabled;

assert.expect(NUM_TESTS);
badger.isCheckingDNTPolicyEnabled = () => false;

for (let i = 0; i < NUM_TESTS; i++) {
badger.checkForDNTPolicy(
DNT_COMPLIANT_DOMAIN,
0);
clock.tick(constants.DNT_POLICY_CHECK_INTERVAL);
assert.equal(xhrSpy.callCount, 0);
done();
}

badger.isCheckingDNTPolicyEnabled = old_dnt_check_func;
});
}());
17 changes: 17 additions & 0 deletions src/tests/tests/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,23 @@
);
});

QUnit.test("DNT does not return as an action if user has chosen not to", (assert) => {
let settings_map = storage.getBadgerStorageObject('settings_map');
settings_map.setItem("checkForDNTPolicy", false);
storage.setupDNT(DOMAIN);

assert.equal(
storage.getAction(DOMAIN),
constants.NO_TRACKING,
"domain is marked as DNT directly, but returns as NO_TRACKING because user has disabled DNT"
);
assert.equal(
storage.getBestAction(DOMAIN),
constants.NO_TRACKING,
"domain is marked as DNT directly, but returns as NO_TRACKING because user has disabled DNT"
);
});

QUnit.test("blocking still cascades after domain declares DNT", (assert) => {
storage.setupHeuristicAction(DOMAIN, constants.BLOCK);
storage.setupDNT(DOMAIN);
Expand Down
4 changes: 4 additions & 0 deletions tests/selenium/localstorage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def test_should_init_local_storage_entries(self):

self.assertFalse(len(disabled_sites),
"Shouldn't have any disabledSites after installation")

self.assertTrue(js("return (badger.storage.getBadgerStorageObject("\
"'settings_map').getItem('checkForDNTPolicy'))"),
"Should start with DNT policy enabled")
# TODO: do we expect currentVersion to be present after the first run?


Expand Down

0 comments on commit f6a67f6

Please sign in to comment.