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

GH-1621: Site-Specific Whitelisting for Unknown Trackers via Anti-Tracking #416

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d17e342
Add anonymized data points to donut graph
Eden12345 Jun 4, 2019
3ec01dc
Half of original implementation complete
Eden12345 Jun 5, 2019
1f80f91
Copy icons to original branch
Eden12345 Jun 10, 2019
c2002a5
Finish rebuilding feature in original branch with cleaner code
Eden12345 Jun 10, 2019
3dcfa15
Rendering is working properly for the detailed view list, holding off…
Eden12345 Jun 12, 2019
f07a901
update npm dependencies. refactor webpack, babel, eslint
christophertino Jun 27, 2019
43e7683
apply new eslint rules and fix errors
christophertino Jun 27, 2019
ce2518c
fix formatting of if statements after lint auto-fix
christophertino Jul 1, 2019
95267e9
fix proptype errors in hub
christophertino Jul 1, 2019
e70fcd7
update codeowners and readme
christophertino Jul 1, 2019
4bad7bb
Shorten and correct the russian translations for cookies, fingerprint…
wlycdgr Jul 2, 2019
22236a6
Fix layout in Summary condensed view on Page Not Scanned pages (#404)
wlycdgr Jul 2, 2019
14973e6
bump browser core version
christophertino Jul 2, 2019
9a88931
updated donut number tooltip
tdtnguyen Jul 3, 2019
3cea1c7
fix tracker counting to include ad-block data
christophertino Jul 8, 2019
c610b08
Merge master into branch to access CliqzFeature component
Eden12345 Jul 9, 2019
82cb4bb
Get Anti-Tracking button working in category header
Eden12345 Jul 9, 2019
d57dc3d
Finish styling header
Eden12345 Jul 10, 2019
df763d6
Header styling and functionality complete, SVG buttons styled
Eden12345 Jul 11, 2019
0fdb21f
Resolve merge conflicts with Tino's changes to CliqzModuleData
Eden12345 Jul 11, 2019
6896ad7
Saving (relatively) working code)
Eden12345 Jul 17, 2019
8a88239
Complete core functionality, UI needs to be completed and refactored
Eden12345 Jul 18, 2019
45a97be
Finish styling
Eden12345 Jul 18, 2019
File filter
Filter file types
Jump to
Jump to file
Failed to load files.

Always

Just for now

fix tracker counting to include ad-block data
  • Loading branch information
christophertino committed Jul 8, 2019
commit 3cea1c7b1a899a0d8e4e5a9af55249d156ea7b8a
@@ -49,7 +49,7 @@ import * as common from './utils/common';
import * as utils from './utils/utils';
import { _getJSONAPIErrorsObject } from './utils/api';
import { importCliqzSettings } from './utils/cliqzSettingImport';
import { sendCliqzModulesData } from './utils/cliqzModulesData';
import { sendCliqzModuleCounts } from './utils/cliqzModulesData';

// For debug purposes, provide Access to the internals of `browser-core`
// module from Developer Tools Console.
@@ -841,12 +841,12 @@ function onMessageHandler(request, sender, callback) {
callback();
return false;
}
if (name === 'getCliqzModuleData') {
if (name === 'getCliqzModuleData') { // panel-android only
if (message && message.tabId) {
sendCliqzModulesData(message.tabId, callback);
sendCliqzModuleCounts(message.tabId, callback);
} else {
utils.getActiveTab((tab) => {
sendCliqzModulesData(tab.id, callback);
sendCliqzModuleCounts(tab.id, callback);
});
}
return true;
@@ -17,7 +17,7 @@ import conf from './Conf';
import foundBugs from './FoundBugs';
import rewards from './Rewards';
import Policy from './Policy';
import { getCliqzAntitrackingData, getCliqzAdblockingData } from '../utils/cliqzModulesData';
import { getCliqzAntiTrackingCount, getCliqzAdBlockingCount } from '../utils/cliqzModulesData';
import { getTab } from '../utils/utils';
import { log } from '../utils/common';
import globals from './Globals';
@@ -144,20 +144,19 @@ class BrowserButton {
return;
}

getCliqzAntitrackingData(tabId).then((antitrackingData) => {
const { appsCount, appsAlertCount } = this._getTrackerCount(tabId);
const adBlockingCount = getCliqzAdblockingData(tabId).totalCount;
const { appsCount, appsAlertCount } = this._getTrackerCount(tabId);
const adBlockingCount = getCliqzAdBlockingCount(tabId).totalCount;
const antiTrackingCount = getCliqzAntiTrackingCount(tabId).totalUnsafeCount;

alert = (appsAlertCount > 0);
trackerCount = (appsCount + antitrackingData.totalUnsafeCount + adBlockingCount).toString();
alert = (appsAlertCount > 0);
trackerCount = (appsCount + antiTrackingCount + adBlockingCount).toString();

// gray-out the icon when blocking has been disabled for whatever reason
if (trackerCount === '') {
this._setIcon(false, tabId, trackerCount, alert);
} else {
this._setIcon(!globals.SESSION.paused_blocking && !this.policy.whitelisted(tab.url), tabId, trackerCount, alert);
}
});
// gray-out the icon when blocking has been disabled for whatever reason
if (trackerCount === '') {
this._setIcon(false, tabId, trackerCount, alert);
} else {
this._setIcon(!globals.SESSION.paused_blocking && !this.policy.whitelisted(tab.url), tabId, trackerCount, alert);
}
}

/**
@@ -26,7 +26,7 @@ import tabInfo from './TabInfo';
import rewards from './Rewards';
import account from './Account';
import dispatcher from './Dispatcher';
import { getCliqzGhosteryStats, sendCliqzModulesData } from '../utils/cliqzModulesData';
import { getCliqzGhosteryBugs, sendCliqzModuleCounts } from '../utils/cliqzModulesData';
import { getActiveTab, flushChromeMemoryCache, processUrl } from '../utils/utils';
import { objectEntries, log } from '../utils/common';

@@ -206,7 +206,7 @@ class PanelData {
}

/**
* Wrapper helper passed as callback to utils/cliqzModuleData#sendCliqzModulesData
* Wrapper helper passed as callback to utils/cliqzModuleData#sendCliqzModuleCounts
*/
postMessageToSummary = ((message) => {
this._postMessage('summary', message);
@@ -545,12 +545,12 @@ class PanelData {
}

/**
* Retrieves antitracking and adblock Cliqz data and sends it to the panel
* Retrieves antitracking and adblock counts and sends it to the panel
*/
_postCliqzModulesData() {
if (!this._panelPort || !this._activeTab) { return; }

sendCliqzModulesData(this._activeTab.id, this.postMessageToSummary);
sendCliqzModuleCounts(this._activeTab.id, this.postMessageToSummary);
}

/**
@@ -830,23 +830,23 @@ class PanelData {

this._trackerList = foundBugs.getApps(id, false, url) || [];

const ghosteryStats = getCliqzGhosteryStats(id);
const ghosteryBugs = getCliqzGhosteryBugs(id);

if (ghosteryStats && ghosteryStats.bugs) {
const gsBugs = ghosteryStats.bugs;
const bugsIds = Object.keys(gsBugs);
if (ghosteryBugs && ghosteryBugs.bugs) {
const { bugs } = ghosteryBugs;
const bugIds = Object.keys(bugs);
const appsById = foundBugs.getAppsById(id);

bugsIds.forEach((bugsId) => {
bugIds.forEach((bugsId) => {
const trackerId = conf.bugs.bugs[bugsId];
if (!trackerId) return;

const trackerListIndex = appsById[trackerId.aid];
if (!trackerListIndex) return;

this._trackerList[trackerListIndex].cliqzCookieCount = gsBugs[bugsId].cookies;
this._trackerList[trackerListIndex].cliqzFingerprintCount = gsBugs[bugsId].fingerprints;
this._trackerList[trackerListIndex].cliqzAdCount = gsBugs[bugsId].ads;
this._trackerList[trackerListIndex].cliqzCookieCount = bugs[bugsId].cookies;
this._trackerList[trackerListIndex].cliqzFingerprintCount = bugs[bugsId].fingerprints;
this._trackerList[trackerListIndex].cliqzAdCount = bugs[bugsId].ads;
});
}

@@ -12,96 +12,84 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0
*/

import { extend } from 'underscore';
import conf from '../classes/Conf';
import cliqz from '../classes/Cliqz';

const { adblocker, antitracking } = cliqz.modules;

export function getCliqzAntitrackingData(tabId) {
return new Promise((resolve) => {
if (!conf.enable_anti_tracking || !antitracking.background) {
resolve({
totalUnsafeCount: 0
});
}
/**
* Get the totalUnsafeCount of trackers found by Anti-Tracking on this tabId
* @param {int} tabId
* @return {object} totalUnsafeCount
*/
export function getCliqzAntiTrackingCount(tabId) {
let count = 0;
if (!conf.enable_anti_tracking || !antitracking.background) {
return {
totalUnsafeCount: count
};
}

antitracking.background.actions.aggregatedBlockingStats(tabId).then((antitrackingData) => {
let totalUnsafeCount = 0;
for (const category in antitrackingData) {
if (antitrackingData.hasOwnProperty(category)) {
for (const app in antitrackingData[category]) {
if (antitrackingData[category][app] === 'unsafe') {
totalUnsafeCount++;
}
}
}
}
antitrackingData.totalUnsafeCount = totalUnsafeCount;
resolve(antitrackingData);
}).catch(() => {
resolve({
totalUnsafeCount: 0
});
});
});
// Count up number of fingerprints and cookies found
const { bugs, others } = antitracking.background.actions.getGhosteryStats(tabId);
const allStats = Object.assign({}, bugs, others);
const values = Object.values(allStats);

for (const val of values) {
count += val.cookies + val.fingerprints;
}

return {
totalUnsafeCount: count
};
}

export function getCliqzAdblockingData(tabId) {
/**
* Get the totalCount of ads found by the Ad Blocker on this tabId
* @param {int} tabId
* @return {object}
*/
export function getCliqzAdBlockingCount(tabId) {
if (!conf.enable_ad_block || !adblocker.background) {
return {
totalCount: 0
};
}

const adBlocking = adblocker.background.actions.getAdBlockInfoForTab(tabId);
return adBlocking || { totalCount: 0 };
const adBlockInfo = adblocker.background.actions.getAdBlockInfoForTab(tabId);
return {
totalCount: adBlockInfo.totalCount || 0,
};
}

/**
* TODO: Add a test that verifies the following structure so that we automatically know if Cliqz changes it and we need to updated it
The returned object has the following structure:
{
bugs: {
4147: { cookies: 3, fingerprints: 4, ads: 0 },
another_bug_id: { cookies: 2, .....
....
},
others: {
CloudFlare: {
ads: 0,
cat: "cdn",
cookies: 3,
domains: ["cdnjs.cloudlare.com", ...],
fingerprints: 4,
name: "CloudFlare",
wtm: "cloudflare",
},
...
}
}
* Get list of matched bug_ids from Anti-Tracking and Ad-Blocking for this
* tab, along with list of 'other' trackers found that do not match known bug_ids.
* @param {int} tabId
* @return {object}
*/
export function getCliqzGhosteryStats(tabId) {
if (!conf.enable_anti_tracking) {
return {
bugs: {},
others: {},
};
}
export function getCliqzGhosteryBugs(tabId) {
// Merge Ad-Block stats into Anti-Track Stats
const antiTrackingStats = (conf.enable_anti_tracking) ? antitracking.background.actions.getGhosteryStats(tabId) : { bugs: {}, others: {} };
const adBlockingStats = (conf.enable_ad_block) ? adblocker.background.actions.getGhosteryStats(tabId) : { bugs: {}, others: {} };

const ghosteryStats = antitracking.background.actions.getGhosteryStats(tabId);
return ghosteryStats;
return {
bugs: extend({}, antiTrackingStats.bugs, adBlockingStats.bugs),
others: extend({}, antiTrackingStats.others, adBlockingStats.others),
};
}

export function sendCliqzModulesData(tabId, callback) {
/**
* Send `totalCount` of ads found by Ad Blocker and `totalUnsafeCount`
* found by Anti-Tracking
* @param {int} tabId
* @param {Function} callback
*/
export function sendCliqzModuleCounts(tabId, callback) {
const modules = { adblock: {}, antitracking: {} };

modules.adblock = getCliqzAdblockingData(tabId);

// TODO convert to use finally to avoid duplication (does our Babel transpile it?)
getCliqzAntitrackingData(tabId).then((antitrackingData) => {
modules.antitracking = antitrackingData;
callback(modules);
}).catch(() => {
callback(modules);
});
modules.adblock = getCliqzAdBlockingCount(tabId);
modules.antitracking = getCliqzAntiTrackingCount(tabId);
callback(modules);
}
ProTip! Use n and p to navigate between commits in a pull request.