@whotracksme/reporting 5.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +12 -0
- package/.eslintignore +3 -0
- package/.eslintrc +16 -0
- package/.github/workflows/release.yml +34 -0
- package/.github/workflows/tests.yml +20 -0
- package/.prettierrc +9 -0
- package/.tool-versions +1 -0
- package/CHANGELOG.md +795 -0
- package/LICENSE +373 -0
- package/README.md +1 -0
- package/communication/README.md +11 -0
- package/communication/example/index.js +43 -0
- package/communication/example/manifest.json +16 -0
- package/communication/karma.conf.cjs +19 -0
- package/communication/package.json +52 -0
- package/communication/rollup.common-config.cjs +17 -0
- package/communication/rollup.config.cjs +10 -0
- package/communication/src/encoding.js +54 -0
- package/communication/src/errors.js +84 -0
- package/communication/src/index.js +76 -0
- package/communication/src/logger.js +41 -0
- package/communication/src/padding.js +60 -0
- package/communication/src/proxied-http.js +231 -0
- package/communication/src/server-public-key-accessor.js +123 -0
- package/communication/src/timestamps.js +37 -0
- package/communication/src/trusted-clock.js +58 -0
- package/communication/src/utils.js +28 -0
- package/communication/src/zlib.js +17 -0
- package/communication/test/helpers/in-memory-database.js +43 -0
- package/communication/test/server-public-key-accessor.spec.js +135 -0
- package/communication/test/utils.spec.js +43 -0
- package/package.json +50 -0
- package/reporting/TODO.md +2 -0
- package/reporting/assets/request/bloom_filter.dat +0 -0
- package/reporting/assets/request/update.json +1 -0
- package/reporting/example/content.js +11 -0
- package/reporting/example/index.js +132 -0
- package/reporting/example/inspector/index.html +17 -0
- package/reporting/example/inspector/index.js +27 -0
- package/reporting/example/manifests/chromium.json +37 -0
- package/reporting/example/manifests/firefox.json +35 -0
- package/reporting/example/rules.json +62 -0
- package/reporting/example/setup.js +1 -0
- package/reporting/example/tests/test1.html +10 -0
- package/reporting/karma.conf.cjs +22 -0
- package/reporting/package.json +63 -0
- package/reporting/rollup.common-config.cjs +19 -0
- package/reporting/rollup.config.cjs +20 -0
- package/reporting/src/LRU.js +149 -0
- package/reporting/src/activity-estimator.js +298 -0
- package/reporting/src/alive-check.js +139 -0
- package/reporting/src/alive-message-generator.js +142 -0
- package/reporting/src/bloom-filters.js +345 -0
- package/reporting/src/country-provider.js +295 -0
- package/reporting/src/cyrb53.js +32 -0
- package/reporting/src/digest.js +33 -0
- package/reporting/src/doublefetch-page-handler.js +548 -0
- package/reporting/src/duplicate-detector.js +233 -0
- package/reporting/src/errors.js +84 -0
- package/reporting/src/event-listener-queue.js +121 -0
- package/reporting/src/fixed-size-cache.js +63 -0
- package/reporting/src/hash-detector.js +1526 -0
- package/reporting/src/html-parser.js +17 -0
- package/reporting/src/http.js +265 -0
- package/reporting/src/index.js +14 -0
- package/reporting/src/job-scheduler.js +912 -0
- package/reporting/src/logger.js +121 -0
- package/reporting/src/md5.js +334 -0
- package/reporting/src/message-sender.js +51 -0
- package/reporting/src/network.js +140 -0
- package/reporting/src/new-page-approver.js +119 -0
- package/reporting/src/page-aggregator.js +185 -0
- package/reporting/src/page-quorum-check-handler.js +200 -0
- package/reporting/src/page-structure.js +136 -0
- package/reporting/src/pagedb.js +671 -0
- package/reporting/src/pages.js +1798 -0
- package/reporting/src/patterns-updater.js +310 -0
- package/reporting/src/patterns.js +416 -0
- package/reporting/src/persisted-bitarray.js +265 -0
- package/reporting/src/persisted-hashes.js +189 -0
- package/reporting/src/quorum-checker.js +327 -0
- package/reporting/src/random.js +39 -0
- package/reporting/src/reporting.js +290 -0
- package/reporting/src/request/config.js +116 -0
- package/reporting/src/request/content-script.js +77 -0
- package/reporting/src/request/database.js +147 -0
- package/reporting/src/request/dnt.js +24 -0
- package/reporting/src/request/hash.js +101 -0
- package/reporting/src/request/index.js +874 -0
- package/reporting/src/request/page-telemetry.js +42 -0
- package/reporting/src/request/qs-whitelist2.js +247 -0
- package/reporting/src/request/resources/prob.js +601 -0
- package/reporting/src/request/steps/block-rules.js +40 -0
- package/reporting/src/request/steps/check-context.js +37 -0
- package/reporting/src/request/steps/cookie-context.js +209 -0
- package/reporting/src/request/steps/oauth-detector.js +101 -0
- package/reporting/src/request/steps/page-logger.js +177 -0
- package/reporting/src/request/steps/redirect-tagger.js +75 -0
- package/reporting/src/request/steps/subdomain-check.js +34 -0
- package/reporting/src/request/steps/token-checker/index.js +189 -0
- package/reporting/src/request/steps/token-checker/token-domain.js +129 -0
- package/reporting/src/request/steps/token-examiner.js +182 -0
- package/reporting/src/request/steps/token-telemetry/cached-entry-pipeline.js +210 -0
- package/reporting/src/request/steps/token-telemetry/index.js +234 -0
- package/reporting/src/request/steps/token-telemetry/key-pipeline.js +109 -0
- package/reporting/src/request/steps/token-telemetry/token-pipeline.js +105 -0
- package/reporting/src/request/time.js +73 -0
- package/reporting/src/request/utils/bloom-filter-packed.js +107 -0
- package/reporting/src/request/utils/chrome-storage-map.js +282 -0
- package/reporting/src/request/utils/subject.js +37 -0
- package/reporting/src/request/utils/temp-set.js +56 -0
- package/reporting/src/request/utils/tlds.js +55 -0
- package/reporting/src/request/utils.js +41 -0
- package/reporting/src/request-reporter.js +111 -0
- package/reporting/src/sanitizer.js +519 -0
- package/reporting/src/search-extractor.js +338 -0
- package/reporting/src/self-check.js +105 -0
- package/reporting/src/seq-executor.js +43 -0
- package/reporting/src/session-storage.js +399 -0
- package/reporting/src/url-analyzer.js +161 -0
- package/reporting/src/url-cleaner.js +60 -0
- package/reporting/src/utils/pacemaker.js +279 -0
- package/reporting/src/utils/url.js +114 -0
- package/reporting/src/utils.js +345 -0
- package/reporting/src/webrequest-pipeline/cname-uncloak.js +110 -0
- package/reporting/src/webrequest-pipeline/index.js +287 -0
- package/reporting/src/webrequest-pipeline/logger.js +14 -0
- package/reporting/src/webrequest-pipeline/page-store.js +282 -0
- package/reporting/src/webrequest-pipeline/page.js +140 -0
- package/reporting/src/webrequest-pipeline/pipeline.js +249 -0
- package/reporting/src/webrequest-pipeline/utils/webrequest.js +113 -0
- package/reporting/src/webrequest-pipeline/webrequest-context.js +153 -0
- package/reporting/test/README.md +2 -0
- package/reporting/test/activity-estimator.spec.js +356 -0
- package/reporting/test/alive-check.spec.js +156 -0
- package/reporting/test/alive-message-generator.spec.js +186 -0
- package/reporting/test/country-provider.spec.js +263 -0
- package/reporting/test/doublefetch-page-handler.spec.js +818 -0
- package/reporting/test/duplicate-detector.spec.js +689 -0
- package/reporting/test/helpers/dom-parsers.js +41 -0
- package/reporting/test/helpers/fake-session-storage.js +69 -0
- package/reporting/test/helpers/fast-check-utils.js +28 -0
- package/reporting/test/helpers/fetch-mock.js +57 -0
- package/reporting/test/helpers/in-memory-database.js +14 -0
- package/reporting/test/helpers/memory-map.js +72 -0
- package/reporting/test/helpers/pagedb-mocks.js +41 -0
- package/reporting/test/index.js +47 -0
- package/reporting/test/job-scheduler.spec.js +691 -0
- package/reporting/test/network.spec.js +72 -0
- package/reporting/test/page-aggregator.spec.js +104 -0
- package/reporting/test/page-quorum-check-handler.spec.js +86 -0
- package/reporting/test/pagedb.spec.js +250 -0
- package/reporting/test/pages.spec.js +693 -0
- package/reporting/test/patterns-updater.spec.js +446 -0
- package/reporting/test/patterns.spec.js +751 -0
- package/reporting/test/persisted-hashes.spec.js +169 -0
- package/reporting/test/reporting.spec.js +205 -0
- package/reporting/test/request/database.spec.js +59 -0
- package/reporting/test/request/hash.spec.js +108 -0
- package/reporting/test/request/index.spec.js +378 -0
- package/reporting/test/request/qs-whitelist2.spec.js +189 -0
- package/reporting/test/request/steps/check-context.spec.js +51 -0
- package/reporting/test/request/steps/oauth-detector.spec.js +339 -0
- package/reporting/test/request/test-pages.js +1246 -0
- package/reporting/test/request/utils/bloom-filter-packed.spec.js +37 -0
- package/reporting/test/request/utils/chrome-storage-map.spec.js +28 -0
- package/reporting/test/request/utils/tldts.spec.js +62 -0
- package/reporting/test/request/utils.spec.js +168 -0
- package/reporting/test/sanitizer.spec.js +1087 -0
- package/reporting/test/search-extractor.spec.js +590 -0
- package/reporting/test/seq-executor.spec.js +158 -0
- package/reporting/test/session-storage.spec.js +400 -0
- package/reporting/test/setup.js +24 -0
- package/reporting/test/url-analyzer.spec.js +451 -0
- package/reporting/test/url-cleaner.spec.js +102 -0
- package/reporting/test/utils/pacemaker.spec.js +222 -0
- package/reporting/test/utils/url.spec.js +660 -0
- package/reporting/test/utils.spec.js +299 -0
- package/reporting/test/webrequest-pipeline/pipeline.spec.js +251 -0
|
@@ -0,0 +1,874 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WhoTracks.Me
|
|
3
|
+
* https://whotracks.me/
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2017-present Ghostery GmbH. All rights reserved.
|
|
6
|
+
*
|
|
7
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
8
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
9
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/* eslint-disable no-param-reassign */
|
|
13
|
+
import Pipeline from '../webrequest-pipeline/pipeline';
|
|
14
|
+
import { isPrivateIP } from '../utils/url';
|
|
15
|
+
import pacemaker from '../utils/pacemaker';
|
|
16
|
+
|
|
17
|
+
import { truncatedHash } from '../md5';
|
|
18
|
+
import logger from '../logger';
|
|
19
|
+
|
|
20
|
+
import * as datetime from './time';
|
|
21
|
+
import QSWhitelist2 from './qs-whitelist2';
|
|
22
|
+
import TempSet from './utils/temp-set';
|
|
23
|
+
import { HashProb, shouldCheckToken } from './hash';
|
|
24
|
+
import { VERSION, COOKIE_MODE } from './config';
|
|
25
|
+
import { shuffle } from './utils';
|
|
26
|
+
import buildPageLoadObject from './page-telemetry';
|
|
27
|
+
import getTrackingStatus from './dnt';
|
|
28
|
+
import random from '../random';
|
|
29
|
+
|
|
30
|
+
import BlockRules from './steps/block-rules';
|
|
31
|
+
import CookieContext from './steps/cookie-context';
|
|
32
|
+
import PageLogger from './steps/page-logger';
|
|
33
|
+
import RedirectTagger from './steps/redirect-tagger';
|
|
34
|
+
import TokenChecker from './steps/token-checker/index';
|
|
35
|
+
import TokenExaminer from './steps/token-examiner';
|
|
36
|
+
import TokenTelemetry from './steps/token-telemetry/index';
|
|
37
|
+
import OAuthDetector from './steps/oauth-detector';
|
|
38
|
+
|
|
39
|
+
import {
|
|
40
|
+
checkValidContext,
|
|
41
|
+
checkSameGeneralDomain,
|
|
42
|
+
} from './steps/check-context';
|
|
43
|
+
|
|
44
|
+
const DAY_CHANGE_INTERVAL = 20 * 1000;
|
|
45
|
+
const RECENTLY_MODIFIED_TTL = 30 * 1000;
|
|
46
|
+
|
|
47
|
+
export default class RequestMonitor {
|
|
48
|
+
constructor(
|
|
49
|
+
settings,
|
|
50
|
+
{
|
|
51
|
+
db,
|
|
52
|
+
webRequestPipeline,
|
|
53
|
+
trustedClock,
|
|
54
|
+
countryProvider,
|
|
55
|
+
communication,
|
|
56
|
+
getBrowserInfo,
|
|
57
|
+
onTrackerInteraction = (event, state) => {
|
|
58
|
+
logger.log(`Tracker '${event}' with url: ${state.url}`);
|
|
59
|
+
},
|
|
60
|
+
isRequestAllowed = () => false,
|
|
61
|
+
},
|
|
62
|
+
) {
|
|
63
|
+
this.settings = settings;
|
|
64
|
+
this.communication = communication;
|
|
65
|
+
this.trustedClock = trustedClock;
|
|
66
|
+
this.webRequestPipeline = webRequestPipeline;
|
|
67
|
+
this.countryProvider = countryProvider;
|
|
68
|
+
this.onTrackerInteraction = onTrackerInteraction;
|
|
69
|
+
this.getBrowserInfo = getBrowserInfo;
|
|
70
|
+
this.isRequestAllowed = isRequestAllowed;
|
|
71
|
+
this.db = db;
|
|
72
|
+
this.VERSION = VERSION;
|
|
73
|
+
this.LOG_KEY = 'attrack';
|
|
74
|
+
this.debug = false;
|
|
75
|
+
this.recentlyModified = new TempSet();
|
|
76
|
+
this.whitelistedRequestCache = new Set();
|
|
77
|
+
|
|
78
|
+
// Intervals
|
|
79
|
+
this.dayChangedInterval = null;
|
|
80
|
+
|
|
81
|
+
// Web request pipelines
|
|
82
|
+
this.pipelineSteps = {};
|
|
83
|
+
this.pipelines = {};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
checkIsWhitelisted(state) {
|
|
87
|
+
if (this.whitelistedRequestCache.has(state.requestId)) {
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
if (this.isRequestAllowed(state)) {
|
|
91
|
+
this.whitelistedRequestCache.add(state.requestId);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
obfuscate(s, method) {
|
|
98
|
+
// used when action != 'block'
|
|
99
|
+
// default is a placeholder
|
|
100
|
+
switch (method) {
|
|
101
|
+
case 'empty':
|
|
102
|
+
return '';
|
|
103
|
+
case 'replace':
|
|
104
|
+
return shuffle(s);
|
|
105
|
+
case 'same':
|
|
106
|
+
return s;
|
|
107
|
+
case 'placeholder':
|
|
108
|
+
return this.config.placeHolder;
|
|
109
|
+
default:
|
|
110
|
+
return this.config.placeHolder;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
getDefaultRule() {
|
|
115
|
+
if (this.isForceBlockEnabled()) {
|
|
116
|
+
return 'block';
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return 'placeholder';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
isCookieEnabled() {
|
|
123
|
+
return this.config.cookieEnabled;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
isQSEnabled() {
|
|
127
|
+
return this.config.qsEnabled;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
isFingerprintingEnabled() {
|
|
131
|
+
return this.config.fingerprintEnabled;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
isReferrerEnabled() {
|
|
135
|
+
return this.config.referrerEnabled;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
isForceBlockEnabled() {
|
|
139
|
+
return this.config.forceBlockEnabled;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
async telemetry(message) {
|
|
143
|
+
if (!this.communication) {
|
|
144
|
+
logger.error('No provider provider loaded');
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
message.type = 'wtm.request';
|
|
149
|
+
message.userAgent = (await this.getBrowserInfo()).name;
|
|
150
|
+
message.ts = this.trustedClock.getTimeAsYYYYMMDD();
|
|
151
|
+
message['anti-duplicates'] = Math.floor(random() * 10000000);
|
|
152
|
+
|
|
153
|
+
const data = message.payload;
|
|
154
|
+
message.payload = { data };
|
|
155
|
+
message.payload.ver = VERSION;
|
|
156
|
+
message.payload.day = this.qs_whitelist.getVersion().day;
|
|
157
|
+
message.payload.ts = this.trustedClock.getTimeAsYYYYMMDDHH();
|
|
158
|
+
message.payload.ctry = this.countryProvider.getSafeCountryCode();
|
|
159
|
+
|
|
160
|
+
logger.debug('report', message);
|
|
161
|
+
|
|
162
|
+
this.communication.send(message);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Global module initialisation.
|
|
166
|
+
*/
|
|
167
|
+
async init(config) {
|
|
168
|
+
this.config = config;
|
|
169
|
+
this.hashProb = new HashProb();
|
|
170
|
+
|
|
171
|
+
// load all caches:
|
|
172
|
+
// Large dynamic caches are loaded via the persist module, which will
|
|
173
|
+
// lazily propegate changes back to the browser's sqlite database.
|
|
174
|
+
// Large static caches (e.g. token whitelist) are loaded from sqlite
|
|
175
|
+
// Smaller caches (e.g. update timestamps) are kept in prefs
|
|
176
|
+
this.qs_whitelist = new QSWhitelist2({
|
|
177
|
+
storage: this.db,
|
|
178
|
+
CDN_BASE_URL: this.config.remoteWhitelistUrl,
|
|
179
|
+
LOCAL_BASE_URL: this.config.localWhitelistUrl,
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// load the whitelist async - qs protection will start once it is ready
|
|
183
|
+
this.qs_whitelist.init();
|
|
184
|
+
|
|
185
|
+
this.dayChangedInterval = pacemaker.register(this.dayChanged.bind(this), {
|
|
186
|
+
timeout: DAY_CHANGE_INTERVAL,
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
this.webRequestPipeline.addOnPageStageListener((page) => {
|
|
190
|
+
this.onPageStaged(page);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
await this.initPipeline();
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async initPipeline() {
|
|
197
|
+
this.unloadPipeline();
|
|
198
|
+
|
|
199
|
+
// Initialise classes which are used as steps in listeners
|
|
200
|
+
const steps = {
|
|
201
|
+
pageLogger: new PageLogger(this.config),
|
|
202
|
+
blockRules: new BlockRules(this.config),
|
|
203
|
+
cookieContext: new CookieContext(this.config, this.qs_whitelist),
|
|
204
|
+
redirectTagger: new RedirectTagger(),
|
|
205
|
+
oAuthDetector: new OAuthDetector(),
|
|
206
|
+
};
|
|
207
|
+
steps.tokenTelemetry = new TokenTelemetry(
|
|
208
|
+
this.telemetry.bind(this),
|
|
209
|
+
this.qs_whitelist,
|
|
210
|
+
this.config,
|
|
211
|
+
this.db,
|
|
212
|
+
this.shouldCheckToken.bind(this),
|
|
213
|
+
this.config.tokenTelemetry,
|
|
214
|
+
this.trustedClock,
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
steps.tokenExaminer = new TokenExaminer(
|
|
218
|
+
this.qs_whitelist,
|
|
219
|
+
this.config,
|
|
220
|
+
this.shouldCheckToken.bind(this),
|
|
221
|
+
);
|
|
222
|
+
steps.tokenChecker = new TokenChecker(
|
|
223
|
+
this.qs_whitelist,
|
|
224
|
+
{},
|
|
225
|
+
this.shouldCheckToken.bind(this),
|
|
226
|
+
this.config,
|
|
227
|
+
this.db,
|
|
228
|
+
);
|
|
229
|
+
|
|
230
|
+
this.pipelineSteps = steps;
|
|
231
|
+
|
|
232
|
+
// initialise step objects
|
|
233
|
+
for (const key of Object.keys(steps)) {
|
|
234
|
+
const step = steps[key];
|
|
235
|
+
if (step.init) {
|
|
236
|
+
await step.init();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// ----------------------------------- \\
|
|
241
|
+
// create pipeline for onBeforeRequest \\
|
|
242
|
+
// ----------------------------------- \\
|
|
243
|
+
this.pipelines.onBeforeRequest = new Pipeline(
|
|
244
|
+
'antitracking.onBeforeRequest',
|
|
245
|
+
[
|
|
246
|
+
{
|
|
247
|
+
name: 'checkState',
|
|
248
|
+
spec: 'break',
|
|
249
|
+
fn: checkValidContext,
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
name: 'oAuthDetector.checkMainFrames',
|
|
253
|
+
spec: 'break',
|
|
254
|
+
fn: (state) => steps.oAuthDetector.checkMainFrames(state),
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
name: 'redirectTagger.checkRedirect',
|
|
258
|
+
spec: 'break',
|
|
259
|
+
fn: (state) => steps.redirectTagger.checkRedirect(state),
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
name: 'checkSameGeneralDomain',
|
|
263
|
+
spec: 'break',
|
|
264
|
+
fn: checkSameGeneralDomain,
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
name: 'cancelRecentlyModified',
|
|
268
|
+
spec: 'blocking',
|
|
269
|
+
fn: (state, response) => this.cancelRecentlyModified(state, response),
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
name: 'pageLogger.onBeforeRequest',
|
|
273
|
+
spec: 'annotate',
|
|
274
|
+
fn: (state) => steps.pageLogger.onBeforeRequest(state),
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
name: 'logIsTracker',
|
|
278
|
+
spec: 'collect',
|
|
279
|
+
fn: (state) => {
|
|
280
|
+
if (
|
|
281
|
+
this.qs_whitelist.isTrackerDomain(
|
|
282
|
+
truncatedHash(state.urlParts.generalDomain),
|
|
283
|
+
)
|
|
284
|
+
) {
|
|
285
|
+
this.onTrackerInteraction('observed', state);
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
{
|
|
290
|
+
name: 'checkExternalBlocking',
|
|
291
|
+
spec: 'blocking',
|
|
292
|
+
fn: (state, response) => {
|
|
293
|
+
if (response.cancel === true || response.redirectUrl) {
|
|
294
|
+
state.incrementStat('blocked_external');
|
|
295
|
+
response.shouldIncrementCounter = true;
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
return true;
|
|
299
|
+
},
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
name: 'tokenExaminer.examineTokens',
|
|
303
|
+
spec: 'collect', // TODO - global state
|
|
304
|
+
fn: (state) => steps.tokenExaminer.examineTokens(state),
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
name: 'tokenTelemetry.extractKeyTokens',
|
|
308
|
+
spec: 'collect', // TODO - global state
|
|
309
|
+
fn: (state) =>
|
|
310
|
+
!steps.tokenTelemetry ||
|
|
311
|
+
steps.tokenTelemetry.extractKeyTokens(state),
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
name: 'tokenChecker.findBadTokens',
|
|
315
|
+
spec: 'annotate',
|
|
316
|
+
fn: (state) => steps.tokenChecker.findBadTokens(state),
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
name: 'checkSourceWhitelisted',
|
|
320
|
+
spec: 'break',
|
|
321
|
+
fn: (state) => {
|
|
322
|
+
if (this.checkIsWhitelisted(state)) {
|
|
323
|
+
state.incrementStat('source_whitelisted');
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
return true;
|
|
327
|
+
},
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
name: 'checkShouldBlock',
|
|
331
|
+
spec: 'break',
|
|
332
|
+
fn: (state) =>
|
|
333
|
+
state.badTokens.length > 0 &&
|
|
334
|
+
this.qs_whitelist.isUpToDate() &&
|
|
335
|
+
!this.config.paused,
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
name: 'oAuthDetector.checkIsOAuth',
|
|
339
|
+
spec: 'break',
|
|
340
|
+
fn: (state) => steps.oAuthDetector.checkIsOAuth(state, 'token'),
|
|
341
|
+
},
|
|
342
|
+
{
|
|
343
|
+
name: 'isQSEnabled',
|
|
344
|
+
spec: 'break',
|
|
345
|
+
fn: () => this.isQSEnabled(),
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
name: 'blockRules.applyBlockRules',
|
|
349
|
+
spec: 'blocking',
|
|
350
|
+
fn: (state, response) =>
|
|
351
|
+
steps.blockRules.applyBlockRules(state, response),
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
name: 'logBlockedToken',
|
|
355
|
+
spec: 'collect',
|
|
356
|
+
fn: (state) => {
|
|
357
|
+
this.onTrackerInteraction('fingerprint-removed', state);
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
name: 'applyBlock',
|
|
362
|
+
spec: 'blocking',
|
|
363
|
+
fn: (state, response) => this.applyBlock(state, response),
|
|
364
|
+
},
|
|
365
|
+
],
|
|
366
|
+
);
|
|
367
|
+
|
|
368
|
+
// --------------------------------------- \\
|
|
369
|
+
// create pipeline for onBeforeSendHeaders \\
|
|
370
|
+
// --------------------------------------- \\
|
|
371
|
+
this.pipelines.onBeforeSendHeaders = new Pipeline(
|
|
372
|
+
'antitracking.onBeforeSendHeaders',
|
|
373
|
+
[
|
|
374
|
+
{
|
|
375
|
+
name: 'checkState',
|
|
376
|
+
spec: 'break',
|
|
377
|
+
fn: checkValidContext,
|
|
378
|
+
},
|
|
379
|
+
{
|
|
380
|
+
name: 'cookieContext.assignCookieTrust',
|
|
381
|
+
spec: 'collect', // TODO - global state
|
|
382
|
+
fn: (state) => steps.cookieContext.assignCookieTrust(state),
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
name: 'redirectTagger.confirmRedirect',
|
|
386
|
+
spec: 'break',
|
|
387
|
+
fn: (state) => steps.redirectTagger.confirmRedirect(state),
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
name: 'checkIsMainDocument',
|
|
391
|
+
spec: 'break',
|
|
392
|
+
fn: (state) => !state.isMainFrame,
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
name: 'checkSameGeneralDomain',
|
|
396
|
+
spec: 'break',
|
|
397
|
+
fn: checkSameGeneralDomain,
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
name: 'pageLogger.onBeforeSendHeaders',
|
|
401
|
+
spec: 'annotate',
|
|
402
|
+
fn: (state) => steps.pageLogger.onBeforeSendHeaders(state),
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
name: 'catchMissedOpenListener',
|
|
406
|
+
spec: 'blocking',
|
|
407
|
+
fn: (state, response) => {
|
|
408
|
+
if (
|
|
409
|
+
(state.reqLog && state.reqLog.c === 0) ||
|
|
410
|
+
steps.redirectTagger.isFromRedirect(state.url)
|
|
411
|
+
) {
|
|
412
|
+
// take output from 'open' pipeline and copy into our response object
|
|
413
|
+
this.pipelines.onBeforeRequest.execute(state, response);
|
|
414
|
+
}
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
name: 'overrideUserAgent',
|
|
419
|
+
spec: 'blocking',
|
|
420
|
+
fn: (state, response) => {
|
|
421
|
+
if (this.config.overrideUserAgent === true) {
|
|
422
|
+
const domainHash = truncatedHash(state.urlParts.generalDomain);
|
|
423
|
+
if (this.qs_whitelist.isTrackerDomain(domainHash)) {
|
|
424
|
+
response.modifyHeader('User-Agent', 'CLIQZ');
|
|
425
|
+
state.incrementStat('override_user_agent');
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
name: 'checkHasCookie',
|
|
432
|
+
spec: 'break',
|
|
433
|
+
// hasCookie flag is set by pageLogger.onBeforeSendHeaders
|
|
434
|
+
fn: (state) => state.hasCookie === true,
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
name: 'checkIsCookieWhitelisted',
|
|
438
|
+
spec: 'break',
|
|
439
|
+
fn: (state) => this.checkIsCookieWhitelisted(state),
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
name: 'checkCompatibilityList',
|
|
443
|
+
spec: 'break',
|
|
444
|
+
fn: (state) => this.checkCompatibilityList(state),
|
|
445
|
+
},
|
|
446
|
+
{
|
|
447
|
+
name: 'checkCookieBlockingMode',
|
|
448
|
+
spec: 'break',
|
|
449
|
+
fn: (state) => this.checkCookieBlockingMode(state),
|
|
450
|
+
},
|
|
451
|
+
{
|
|
452
|
+
name: 'cookieContext.checkCookieTrust',
|
|
453
|
+
spec: 'break',
|
|
454
|
+
fn: (state) => steps.cookieContext.checkCookieTrust(state),
|
|
455
|
+
},
|
|
456
|
+
{
|
|
457
|
+
name: 'cookieContext.checkVisitCache',
|
|
458
|
+
spec: 'break',
|
|
459
|
+
fn: (state) => steps.cookieContext.checkVisitCache(state),
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
name: 'cookieContext.checkContextFromEvent',
|
|
463
|
+
spec: 'break',
|
|
464
|
+
fn: (state) => steps.cookieContext.checkContextFromEvent(state),
|
|
465
|
+
},
|
|
466
|
+
{
|
|
467
|
+
name: 'oAuthDetector.checkIsOAuth',
|
|
468
|
+
spec: 'break',
|
|
469
|
+
fn: (state) => steps.oAuthDetector.checkIsOAuth(state, 'cookie'),
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
name: 'shouldBlockCookie',
|
|
473
|
+
spec: 'break',
|
|
474
|
+
fn: (state) => {
|
|
475
|
+
const shouldBlock =
|
|
476
|
+
!this.checkIsWhitelisted(state) &&
|
|
477
|
+
this.isCookieEnabled(state) &&
|
|
478
|
+
!this.config.paused;
|
|
479
|
+
if (!shouldBlock) {
|
|
480
|
+
state.incrementStat('bad_cookie_sent');
|
|
481
|
+
}
|
|
482
|
+
return shouldBlock;
|
|
483
|
+
},
|
|
484
|
+
},
|
|
485
|
+
{
|
|
486
|
+
name: 'logBlockedCookie',
|
|
487
|
+
spec: 'collect',
|
|
488
|
+
fn: (state) => {
|
|
489
|
+
this.onTrackerInteraction('cookie-removed', state);
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
name: 'blockCookie',
|
|
494
|
+
spec: 'blocking',
|
|
495
|
+
fn: (state, response) => {
|
|
496
|
+
state.incrementStat('cookie_blocked');
|
|
497
|
+
state.incrementStat('cookie_block_tp1');
|
|
498
|
+
response.modifyHeader('Cookie', '');
|
|
499
|
+
if (this.config.sendAntiTrackingHeader) {
|
|
500
|
+
response.modifyHeader(this.config.cliqzHeader, ' ');
|
|
501
|
+
}
|
|
502
|
+
state.page.counter += 1;
|
|
503
|
+
},
|
|
504
|
+
},
|
|
505
|
+
],
|
|
506
|
+
);
|
|
507
|
+
|
|
508
|
+
// ------------------------------------- \\
|
|
509
|
+
// create pipeline for onHeadersReceived \\
|
|
510
|
+
// ------------------------------------- \\
|
|
511
|
+
this.pipelines.onHeadersReceived = new Pipeline(
|
|
512
|
+
'antitracking.onHeadersReceived',
|
|
513
|
+
[
|
|
514
|
+
{
|
|
515
|
+
name: 'checkState',
|
|
516
|
+
spec: 'break',
|
|
517
|
+
fn: checkValidContext,
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
name: 'checkMainDocumentRedirects',
|
|
521
|
+
spec: 'break',
|
|
522
|
+
fn: (state) => {
|
|
523
|
+
if (state.isMainFrame) {
|
|
524
|
+
// check for tracking status headers for first party
|
|
525
|
+
const trackingStatus = getTrackingStatus(state);
|
|
526
|
+
if (trackingStatus) {
|
|
527
|
+
state.page.setTrackingStatus(trackingStatus);
|
|
528
|
+
}
|
|
529
|
+
return false;
|
|
530
|
+
}
|
|
531
|
+
return true;
|
|
532
|
+
},
|
|
533
|
+
},
|
|
534
|
+
{
|
|
535
|
+
name: 'checkSameGeneralDomain',
|
|
536
|
+
spec: 'break',
|
|
537
|
+
fn: checkSameGeneralDomain,
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
name: 'redirectTagger.checkRedirectStatus',
|
|
541
|
+
spec: 'break',
|
|
542
|
+
fn: (state) => steps.redirectTagger.checkRedirectStatus(state),
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
name: 'pageLogger.onHeadersReceived',
|
|
546
|
+
spec: 'annotate',
|
|
547
|
+
fn: (state) => steps.pageLogger.onHeadersReceived(state),
|
|
548
|
+
},
|
|
549
|
+
{
|
|
550
|
+
name: 'logResponseStats',
|
|
551
|
+
spec: 'collect',
|
|
552
|
+
fn: (state) => {
|
|
553
|
+
if (state.incrementStat) {
|
|
554
|
+
// TSV stats
|
|
555
|
+
if (
|
|
556
|
+
this.qs_whitelist.isTrackerDomain(
|
|
557
|
+
truncatedHash(state.urlParts.generalDomain),
|
|
558
|
+
)
|
|
559
|
+
) {
|
|
560
|
+
const trackingStatus = getTrackingStatus(state);
|
|
561
|
+
if (trackingStatus) {
|
|
562
|
+
state.incrementStat(`tsv_${trackingStatus.value}`);
|
|
563
|
+
if (trackingStatus.statusId) {
|
|
564
|
+
state.incrementStat('tsv_status');
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
},
|
|
570
|
+
},
|
|
571
|
+
{
|
|
572
|
+
name: 'checkSetCookie',
|
|
573
|
+
spec: 'break',
|
|
574
|
+
fn: (state) => state.hasSetCookie === true,
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
name: 'shouldBlockCookie',
|
|
578
|
+
spec: 'break',
|
|
579
|
+
fn: (state) =>
|
|
580
|
+
!this.checkIsWhitelisted(state) && this.isCookieEnabled(state),
|
|
581
|
+
},
|
|
582
|
+
{
|
|
583
|
+
name: 'checkIsCookieWhitelisted',
|
|
584
|
+
spec: 'break',
|
|
585
|
+
fn: (state) => this.checkIsCookieWhitelisted(state),
|
|
586
|
+
},
|
|
587
|
+
{
|
|
588
|
+
name: 'checkCompatibilityList',
|
|
589
|
+
spec: 'break',
|
|
590
|
+
fn: (state) => this.checkCompatibilityList(state),
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
name: 'checkCookieBlockingMode',
|
|
594
|
+
spec: 'break',
|
|
595
|
+
fn: (state) => this.checkCookieBlockingMode(state),
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
name: 'cookieContext.checkCookieTrust',
|
|
599
|
+
spec: 'break',
|
|
600
|
+
fn: (state) => steps.cookieContext.checkCookieTrust(state),
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
name: 'cookieContext.checkVisitCache',
|
|
604
|
+
spec: 'break',
|
|
605
|
+
fn: (state) => steps.cookieContext.checkVisitCache(state),
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
name: 'cookieContext.checkContextFromEvent',
|
|
609
|
+
spec: 'break',
|
|
610
|
+
fn: (state) => steps.cookieContext.checkContextFromEvent(state),
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
name: 'logSetBlockedCookie',
|
|
614
|
+
spec: 'collect',
|
|
615
|
+
fn: (state) => {
|
|
616
|
+
this.onTrackerInteraction('cookie-removed', state);
|
|
617
|
+
},
|
|
618
|
+
},
|
|
619
|
+
{
|
|
620
|
+
name: 'blockSetCookie',
|
|
621
|
+
spec: 'blocking',
|
|
622
|
+
fn: (state, response) => {
|
|
623
|
+
response.modifyResponseHeader('Set-Cookie', '');
|
|
624
|
+
state.incrementStat('set_cookie_blocked');
|
|
625
|
+
state.page.counter += 1;
|
|
626
|
+
},
|
|
627
|
+
},
|
|
628
|
+
],
|
|
629
|
+
);
|
|
630
|
+
|
|
631
|
+
this.pipelines.onCompleted = new Pipeline('antitracking.onCompleted', [
|
|
632
|
+
{
|
|
633
|
+
name: 'checkState',
|
|
634
|
+
spec: 'break',
|
|
635
|
+
fn: checkValidContext,
|
|
636
|
+
},
|
|
637
|
+
{
|
|
638
|
+
name: 'logPrivateDocument',
|
|
639
|
+
spec: 'break',
|
|
640
|
+
fn: (state) => {
|
|
641
|
+
if (state.isMainFrame && state.ip) {
|
|
642
|
+
if (isPrivateIP(state.ip)) {
|
|
643
|
+
state.page.isPrivateServer = true;
|
|
644
|
+
}
|
|
645
|
+
return false;
|
|
646
|
+
}
|
|
647
|
+
return true;
|
|
648
|
+
},
|
|
649
|
+
},
|
|
650
|
+
{
|
|
651
|
+
name: 'pageLogger.reattachStatCounter',
|
|
652
|
+
spec: 'annotate',
|
|
653
|
+
fn: (state) => steps.pageLogger.reattachStatCounter(state),
|
|
654
|
+
},
|
|
655
|
+
{
|
|
656
|
+
name: 'logIsCached',
|
|
657
|
+
spec: 'collect',
|
|
658
|
+
fn: (state) => {
|
|
659
|
+
this.whitelistedRequestCache.delete(state.requestId);
|
|
660
|
+
state.incrementStat(state.fromCache ? 'cached' : 'not_cached');
|
|
661
|
+
},
|
|
662
|
+
},
|
|
663
|
+
]);
|
|
664
|
+
|
|
665
|
+
this.pipelines.onErrorOccurred = new Pipeline('antitracking.onError', [
|
|
666
|
+
{
|
|
667
|
+
name: 'checkState',
|
|
668
|
+
spec: 'break',
|
|
669
|
+
fn: checkValidContext,
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
name: 'pageLogger.reattachStatCounter',
|
|
673
|
+
spec: 'annotate',
|
|
674
|
+
fn: (state) => steps.pageLogger.reattachStatCounter(state),
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
name: 'logError',
|
|
678
|
+
spec: 'collect',
|
|
679
|
+
fn: (state) => {
|
|
680
|
+
this.whitelistedRequestCache.delete(state.requestId);
|
|
681
|
+
if (state.error && state.error.indexOf('ABORT')) {
|
|
682
|
+
state.incrementStat('error_abort');
|
|
683
|
+
}
|
|
684
|
+
},
|
|
685
|
+
},
|
|
686
|
+
]);
|
|
687
|
+
|
|
688
|
+
Object.keys(this.pipelines).map((stage) =>
|
|
689
|
+
this.webRequestPipeline.addPipelineStep(stage, {
|
|
690
|
+
name: `antitracking.${stage}`,
|
|
691
|
+
spec: 'blocking',
|
|
692
|
+
fn: (...args) => this.pipelines[stage].execute(...args),
|
|
693
|
+
}),
|
|
694
|
+
);
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
unloadPipeline() {
|
|
698
|
+
Object.keys(this.pipelineSteps || {}).forEach((key) => {
|
|
699
|
+
const step = this.pipelineSteps[key];
|
|
700
|
+
if (step.unload) {
|
|
701
|
+
step.unload();
|
|
702
|
+
}
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
Object.keys(this.pipelines).forEach((stage) => {
|
|
706
|
+
this.pipelines[stage].unload();
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
Object.keys(this.pipelines).map((stage) =>
|
|
710
|
+
this.webRequestPipeline.removePipelineStep(
|
|
711
|
+
stage,
|
|
712
|
+
`antitracking.${stage}`,
|
|
713
|
+
),
|
|
714
|
+
);
|
|
715
|
+
this.pipelines = {};
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
unload() {
|
|
719
|
+
// Check is active usage, was sent
|
|
720
|
+
this.qs_whitelist.destroy();
|
|
721
|
+
this.unloadPipeline();
|
|
722
|
+
this.db.unload();
|
|
723
|
+
this.dayChangedInterval = this.dayChangedInterval.stop();
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
async dayChanged() {
|
|
727
|
+
const dayTimestamp = datetime.getTime().slice(0, 8);
|
|
728
|
+
const lastDay = (await this.db.get('dayChangedlastRun')) || dayTimestamp;
|
|
729
|
+
await this.db.set('dayChangedlastRun', dayTimestamp);
|
|
730
|
+
|
|
731
|
+
if (dayTimestamp !== lastDay) {
|
|
732
|
+
if (this.pipelineSteps.tokenChecker) {
|
|
733
|
+
this.pipelineSteps.tokenChecker.tokenDomain.clean();
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
isInWhitelist(domain) {
|
|
739
|
+
if (!this.config.cookieWhitelist) return false;
|
|
740
|
+
const keys = this.config.cookieWhitelist;
|
|
741
|
+
for (let i = 0; i < keys.length; i += 1) {
|
|
742
|
+
const ind = domain.indexOf(keys[i]);
|
|
743
|
+
if (ind >= 0) {
|
|
744
|
+
if (ind + keys[i].length === domain.length) return true;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
return false;
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
cancelRecentlyModified(state, response) {
|
|
751
|
+
const sourceTab = state.tabId;
|
|
752
|
+
const url = state.url;
|
|
753
|
+
if (this.recentlyModified.has(sourceTab + url)) {
|
|
754
|
+
this.recentlyModified.delete(sourceTab + url);
|
|
755
|
+
response.block();
|
|
756
|
+
return false;
|
|
757
|
+
}
|
|
758
|
+
return true;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
applyBlock(state, _response) {
|
|
762
|
+
const response = _response;
|
|
763
|
+
const badTokens = state.badTokens;
|
|
764
|
+
const rule = this.getDefaultRule();
|
|
765
|
+
|
|
766
|
+
if (this.debug) {
|
|
767
|
+
console.log(
|
|
768
|
+
'ATTRACK',
|
|
769
|
+
rule,
|
|
770
|
+
'URL:',
|
|
771
|
+
state.urlParts.hostname,
|
|
772
|
+
state.urlParts.pathname,
|
|
773
|
+
'TOKENS:',
|
|
774
|
+
badTokens,
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
if (rule === 'block') {
|
|
779
|
+
state.incrementStat(`token_blocked_${rule}`);
|
|
780
|
+
response.block();
|
|
781
|
+
response.shouldIncrementCounter = true;
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
let tmpUrl = state.url;
|
|
786
|
+
for (let i = 0; i < badTokens.length; i += 1) {
|
|
787
|
+
tmpUrl = tmpUrl.replace(badTokens[i], this.obfuscate(badTokens[i], rule));
|
|
788
|
+
}
|
|
789
|
+
// In case unsafe tokens were in the hostname, the URI is not valid
|
|
790
|
+
// anymore and we can cancel the request.
|
|
791
|
+
if (!tmpUrl.startsWith(state.urlParts.origin)) {
|
|
792
|
+
response.block();
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
state.incrementStat(`token_blocked_${rule}`);
|
|
797
|
+
|
|
798
|
+
// TODO: do this nicer
|
|
799
|
+
// if (this.pipelineSteps.trackerProxy && this.pipelineSteps.trackerProxy.shouldProxy(tmpUrl)) {
|
|
800
|
+
// state.incrementStat('proxy');
|
|
801
|
+
// }
|
|
802
|
+
this.recentlyModified.add(state.tabId + state.url, RECENTLY_MODIFIED_TTL);
|
|
803
|
+
|
|
804
|
+
response.redirectTo(tmpUrl);
|
|
805
|
+
response.modifyHeader(this.config.cliqzHeader, ' ');
|
|
806
|
+
|
|
807
|
+
state.page.counter += 1;
|
|
808
|
+
return true;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
checkIsCookieWhitelisted(state) {
|
|
812
|
+
if (this.isInWhitelist(state.urlParts.hostname)) {
|
|
813
|
+
const stage = state.statusCode !== undefined ? 'set_cookie' : 'cookie';
|
|
814
|
+
state.incrementStat(`${stage}_allow_whitelisted`);
|
|
815
|
+
return false;
|
|
816
|
+
}
|
|
817
|
+
return true;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
checkCompatibilityList(state) {
|
|
821
|
+
const tpGd = state.urlParts.generalDomain;
|
|
822
|
+
const fpGd = state.tabUrlParts.generalDomain;
|
|
823
|
+
if (
|
|
824
|
+
this.config.compatibilityList &&
|
|
825
|
+
this.config.compatibilityList[tpGd] &&
|
|
826
|
+
this.config.compatibilityList[tpGd].indexOf(fpGd) !== -1
|
|
827
|
+
) {
|
|
828
|
+
return false;
|
|
829
|
+
}
|
|
830
|
+
return true;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
checkCookieBlockingMode(state) {
|
|
834
|
+
const mode = this.config.cookieMode;
|
|
835
|
+
if (
|
|
836
|
+
mode === COOKIE_MODE.TRACKERS &&
|
|
837
|
+
!this.qs_whitelist.isTrackerDomain(
|
|
838
|
+
truncatedHash(state.urlParts.generalDomain),
|
|
839
|
+
)
|
|
840
|
+
) {
|
|
841
|
+
state.incrementStat('cookie_allow_nottracker');
|
|
842
|
+
return false;
|
|
843
|
+
}
|
|
844
|
+
return true;
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
clearCache() {
|
|
848
|
+
if (this.pipelineSteps.tokenExaminer) {
|
|
849
|
+
this.pipelineSteps.tokenExaminer.clearCache();
|
|
850
|
+
}
|
|
851
|
+
if (this.pipelineSteps.tokenChecker) {
|
|
852
|
+
this.pipelineSteps.tokenChecker.tokenDomain.clear();
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
shouldCheckToken(tok) {
|
|
857
|
+
return shouldCheckToken(this.hashProb, this.config.shortTokenLength, tok);
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
onPageStaged(page) {
|
|
861
|
+
if (page.state === 'complete' && !page.isPrivate && !page.isPrivateServer) {
|
|
862
|
+
const payload = buildPageLoadObject(page);
|
|
863
|
+
if (
|
|
864
|
+
payload.scheme.startsWith('http') &&
|
|
865
|
+
Object.keys(payload.tps).length > 0
|
|
866
|
+
) {
|
|
867
|
+
this.telemetry({
|
|
868
|
+
action: 'wtm.attrack.tp_events',
|
|
869
|
+
payload: [payload],
|
|
870
|
+
});
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
}
|