Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added option to disable DNT policy checking #1391

Merged
merged 9 commits into from
May 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't seem to test anything: try getting it to fail by removing the "is DNT checking enabled" checks in the code. The test will still pass because DOMAIN is always seen as NO_TRACKING, not DNT.

Copy link
Author

@Ghoughpteighbteau Ghoughpteighbteau May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm. this test works in the suite, but does not work on its own because I mistakenly depended on the leftover state of a previous test.

QUnit.test("DNT does not cascade", (assert) => { runs storage.setupDNT(DOMAIN);

because that marks down DOMAIN as having a DNT policy, the next test disabling it does test it. I'll add that setupDNT to the disable test explicitly.

edit: wait... no... I already added that. now I'm confused. I'm running storage.setupDNT(DOMAIN);??

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, seems fine now, I don't know what I was seeing earlier.

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