From 45a12f9034ea9ca6e102992780c3fe2fee4f7ad9 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Fri, 2 Oct 2020 15:50:13 -0700 Subject: [PATCH 1/4] exit heuristicblockingaccounting when on localhost --- src/js/heuristicblocking.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/js/heuristicblocking.js b/src/js/heuristicblocking.js index 2e73d2d5da..f56a2057e7 100644 --- a/src/js/heuristicblocking.js +++ b/src/js/heuristicblocking.js @@ -122,6 +122,11 @@ HeuristicBlocker.prototype = { let tab_origin = self.tabOrigins[details.tabId]; + // ignore localhosts + if (window.isPrivateDomain(tab_origin)) { + return {}; + } + // ignore first-party requests if (!tab_origin || !utils.isThirdPartyDomain(request_origin, tab_origin)) { return {}; From 06fc1e906d0d9269fc78e0f1d01840959f65ffb6 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Fri, 2 Oct 2020 17:14:10 -0700 Subject: [PATCH 2/4] add check for localhost in learningEnabled function --- src/js/incognito.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/js/incognito.js b/src/js/incognito.js index 56d2d9332d..d274a8d42c 100644 --- a/src/js/incognito.js +++ b/src/js/incognito.js @@ -25,7 +25,7 @@ function startListeners() { chrome.tabs.onRemoved.addListener(onRemovedListener); } -function learningEnabled(tab_id) { +function learningEnabled(tab_id, tab_host) { if (badger.getSettings().getItem("learnInIncognito")) { // treat all pages as if they're not incognito return true; @@ -35,6 +35,10 @@ function learningEnabled(tab_id) { if (!tabs.hasOwnProperty(tab_id)) { return false; } + // if tab host is a localhost or any private domain, default to disabled + if (window.isPrivateDomain(tab_host)) { + return false; + } // else, do not learn in incognito tabs return !tabs[tab_id]; } From 7010c796ba2d4f5f41ce1d82eb988d9d5606d9a1 Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Fri, 2 Oct 2020 17:18:36 -0700 Subject: [PATCH 3/4] add tab host parameter to callbacks of learningEnabled and calls of isLearningEnabled --- src/js/background.js | 4 ++-- src/js/heuristicblocking.js | 7 +------ src/js/webrequest.js | 6 +++--- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/js/background.js b/src/js/background.js index 6cdee4c602..262da65abf 100644 --- a/src/js/background.js +++ b/src/js/background.js @@ -930,10 +930,10 @@ Badger.prototype = { * and if tab_id is for an incognito window, * is learning in incognito windows enabled? */ - isLearningEnabled(tab_id) { + isLearningEnabled(tab_id, tab_host) { return ( this.getSettings().getItem("learnLocally") && - incognito.learningEnabled(tab_id) + incognito.learningEnabled(tab_id, tab_host) ); }, diff --git a/src/js/heuristicblocking.js b/src/js/heuristicblocking.js index f56a2057e7..818ba3a2ac 100644 --- a/src/js/heuristicblocking.js +++ b/src/js/heuristicblocking.js @@ -105,7 +105,7 @@ HeuristicBlocker.prototype = { */ heuristicBlockingAccounting: function (details, check_for_cookie_share) { // ignore requests that are outside a tabbed window - if (details.tabId < 0 || !badger.isLearningEnabled(details.tabId)) { + if (details.tabId < 0 || !badger.isLearningEnabled(details.tabId, details.url)) { return {}; } @@ -122,11 +122,6 @@ HeuristicBlocker.prototype = { let tab_origin = self.tabOrigins[details.tabId]; - // ignore localhosts - if (window.isPrivateDomain(tab_origin)) { - return {}; - } - // ignore first-party requests if (!tab_origin || !utils.isThirdPartyDomain(request_origin, tab_origin)) { return {}; diff --git a/src/js/webrequest.js b/src/js/webrequest.js index bb7469bf38..edc49d61d4 100644 --- a/src/js/webrequest.js +++ b/src/js/webrequest.js @@ -110,7 +110,7 @@ function onBeforeRequest(details) { }); // if this is a heuristically- (not user-) blocked domain - if (action == constants.BLOCK && incognito.learningEnabled(tab_id)) { + if (action == constants.BLOCK && incognito.learningEnabled(tab_id, tab_host)) { // check for DNT policy asynchronously setTimeout(function () { badger.checkForDNTPolicy(request_host); @@ -966,7 +966,7 @@ function dispatcher(request, sender, sendResponse) { frame_host = window.extractHostFromURL(request.frameUrl); sendResponse(frame_host && - badger.isLearningEnabled(sender.tab.id) && + badger.isLearningEnabled(sender.tab.id, tab_host) && badger.isPrivacyBadgerEnabled(tab_host) && utils.isThirdPartyDomain(frame_host, tab_host)); @@ -977,7 +977,7 @@ function dispatcher(request, sender, sendResponse) { let tab_host = window.extractHostFromURL(sender.tab.url); sendResponse( - badger.isLearningEnabled(sender.tab.id) && + badger.isLearningEnabled(sender.tab.id, tab_host) && badger.isPrivacyBadgerEnabled(tab_host)); break; From c987989c1f9ac39c72447104234b66704f778e1c Mon Sep 17 00:00:00 2001 From: ablanathtanalba Date: Fri, 2 Oct 2020 18:00:50 -0700 Subject: [PATCH 4/4] add basic test to check that learning is disabled on localhost --- src/tests/tests/tabData.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tests/tests/tabData.js b/src/tests/tests/tabData.js index c578cd1282..cef8c8a389 100644 --- a/src/tests/tests/tabData.js +++ b/src/tests/tests/tabData.js @@ -38,6 +38,14 @@ function() { }, }); + QUnit.test("learning is disabled on localhost", function (assert) { + const LOCALSITE = "localhost"; + + assert.notOk( + badger.isLearningEnabled(this.tabId, LOCALSITE), "learning is disabled on localhost site" + ); + }); + QUnit.test("logging blocked domain", function (assert) { const DOMAIN = "example.com";