@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,209 @@
|
|
|
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
|
+
import { truncatedHash } from '../../md5';
|
|
13
|
+
import pacemaker from '../../utils/pacemaker';
|
|
14
|
+
import { parse } from '../../utils/url';
|
|
15
|
+
import { sameGeneralDomain, getGeneralDomain } from '../utils/tlds';
|
|
16
|
+
import logger from '../../logger';
|
|
17
|
+
import ChromeStorageMap from '../utils/chrome-storage-map';
|
|
18
|
+
|
|
19
|
+
const TIME_AFTER_LINK = 5 * 1000;
|
|
20
|
+
const TIME_CLEANING_CACHE = 3 * 60 * 1000; // 3 minutes
|
|
21
|
+
const TIME_ACTIVE = 20 * 1000;
|
|
22
|
+
// how long to keep trust entries which have not been triggered
|
|
23
|
+
const UNUSED_TRUST_TIMEOUT = 2 * 60 * 1000; // 2 minutes
|
|
24
|
+
// how long to keep trust entries which have been used
|
|
25
|
+
const USED_TRUST_TIMEOUT = 15 * 50 * 1000; // 15 minutes
|
|
26
|
+
const CLEAN_COOKIE_CACHE_TIMEOUT = 2 * 60 * 1000;
|
|
27
|
+
|
|
28
|
+
export default class CookieContext {
|
|
29
|
+
constructor(config, qsWhitelist) {
|
|
30
|
+
this.config = config;
|
|
31
|
+
this.qsWhitelist = qsWhitelist;
|
|
32
|
+
|
|
33
|
+
this.contextFromEvent = null;
|
|
34
|
+
this.visitCache = new ChromeStorageMap({
|
|
35
|
+
storageKey: 'wtm-request-reporting:cookie-context:visit-cache',
|
|
36
|
+
ttlInMs: TIME_CLEANING_CACHE,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
this.trustedThirdParties = new ChromeStorageMap({
|
|
40
|
+
storageKey: 'wtm-request-reporting:cookie-context:trusted-third-parties',
|
|
41
|
+
ttlInMs: USED_TRUST_TIMEOUT,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async init() {
|
|
46
|
+
await this.visitCache.isReady;
|
|
47
|
+
await this.trustedThirdParties.isReady;
|
|
48
|
+
this.cleanCookieCache();
|
|
49
|
+
this._pmclean = pacemaker.register(this.cleanCookieCache.bind(this), {
|
|
50
|
+
timeout: CLEAN_COOKIE_CACHE_TIMEOUT,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
unload() {
|
|
55
|
+
this._pmclean = pacemaker.clearTimeout(this._pmclean);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
cleanCookieCache() {
|
|
59
|
+
// trusted domain pairs
|
|
60
|
+
const now = Date.now();
|
|
61
|
+
this.trustedThirdParties.forEach((counter, key) => {
|
|
62
|
+
const timeoutAt =
|
|
63
|
+
counter.ts +
|
|
64
|
+
(counter.c > 0 ? USED_TRUST_TIMEOUT : UNUSED_TRUST_TIMEOUT);
|
|
65
|
+
if (now > timeoutAt) {
|
|
66
|
+
this.trustedThirdParties.delete(key);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
_addTrustLink(fromFirstParty, toThirdParty) {
|
|
72
|
+
if (sameGeneralDomain(fromFirstParty, toThirdParty)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
// don't trust trackers
|
|
76
|
+
if (
|
|
77
|
+
this.qsWhitelist.isTrackerDomain(
|
|
78
|
+
truncatedHash(getGeneralDomain(toThirdParty)),
|
|
79
|
+
)
|
|
80
|
+
) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
const key = `${fromFirstParty}:${toThirdParty}`;
|
|
84
|
+
if (!this.trustedThirdParties.has(key)) {
|
|
85
|
+
this.trustedThirdParties.set(key, { c: 0 });
|
|
86
|
+
}
|
|
87
|
+
this.trustedThirdParties.get(key).ts = Date.now();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
assignCookieTrust(state) {
|
|
91
|
+
if (state.isMainFrame && state.getReferrer()) {
|
|
92
|
+
const referrer = parse(state.getReferrer());
|
|
93
|
+
if (!referrer) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
const trustedHost = state.urlParts.hostname;
|
|
97
|
+
const trustedOn = referrer.hostname;
|
|
98
|
+
|
|
99
|
+
// this domain is now trusted by the referrer
|
|
100
|
+
this._addTrustLink(trustedOn, trustedHost);
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
checkCookieTrust(state) {
|
|
106
|
+
const stage = state.statusCode !== undefined ? 'set_cookie' : 'cookie';
|
|
107
|
+
const sourceHost = state.tabUrlParts.hostname;
|
|
108
|
+
const requestHost = state.urlParts.hostname;
|
|
109
|
+
const key = `${sourceHost}:${requestHost}`;
|
|
110
|
+
if (this.config.cookieTrustReferers && this.trustedThirdParties.has(key)) {
|
|
111
|
+
const trustCounter = this.trustedThirdParties.get(key);
|
|
112
|
+
trustCounter.c += 1;
|
|
113
|
+
trustCounter.ts = Date.now();
|
|
114
|
+
|
|
115
|
+
state.incrementStat(`${stage}_allow_trust`);
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
checkVisitCache(state) {
|
|
122
|
+
// check if the response has been received yet
|
|
123
|
+
const stage = state.statusCode !== undefined ? 'set_cookie' : 'cookie';
|
|
124
|
+
const tabId = state.tabId;
|
|
125
|
+
const diff =
|
|
126
|
+
Date.now() - (this.visitCache.get(`${tabId}:${state.hostGD}`) || 0);
|
|
127
|
+
if (
|
|
128
|
+
diff < TIME_ACTIVE &&
|
|
129
|
+
this.visitCache.get(`${tabId}:${state.sourceGD}`)
|
|
130
|
+
) {
|
|
131
|
+
state.incrementStat(`${stage}_allow_visitcache`);
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
checkContextFromEvent(state) {
|
|
138
|
+
if (this.contextFromEvent) {
|
|
139
|
+
const stage = state.statusCode !== undefined ? 'set_cookie' : 'cookie';
|
|
140
|
+
const time = Date.now();
|
|
141
|
+
const url = state.url;
|
|
142
|
+
const tabId = state.tabId;
|
|
143
|
+
const urlParts = state.urlParts;
|
|
144
|
+
const sourceGD = state.tabUrlParts.generalDomain;
|
|
145
|
+
const hostGD = state.urlParts.generalDomain;
|
|
146
|
+
|
|
147
|
+
const diff = time - (this.contextFromEvent.ts || 0);
|
|
148
|
+
if (diff < TIME_AFTER_LINK) {
|
|
149
|
+
if (
|
|
150
|
+
hostGD === this.contextFromEvent.cGD &&
|
|
151
|
+
sourceGD === this.contextFromEvent.pageGD
|
|
152
|
+
) {
|
|
153
|
+
this.visitCache.set(`${tabId}:${hostGD}`, time);
|
|
154
|
+
state.incrementStat(`${stage}_allow_userinit_same_context_gd`);
|
|
155
|
+
return false;
|
|
156
|
+
}
|
|
157
|
+
const pu = url.split(/[?&;]/)[0];
|
|
158
|
+
if (this.contextFromEvent.html.indexOf(pu) !== -1) {
|
|
159
|
+
// the url is in pu
|
|
160
|
+
if (urlParts && urlParts.hostname && urlParts.hostname !== '') {
|
|
161
|
+
this.visitCache.set(`${tabId}:${hostGD}`, time);
|
|
162
|
+
state.incrementStat(`${stage}_allow_userinit_same_gd_link`);
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
// last try, guess the possible domain from script src;
|
|
167
|
+
if (
|
|
168
|
+
!this.contextFromEvent.cGD &&
|
|
169
|
+
this.contextFromEvent.possibleCGD.has(hostGD)
|
|
170
|
+
) {
|
|
171
|
+
this.visitCache.set(`${tabId}:${hostGD}`, time);
|
|
172
|
+
state.incrementStat(`${stage}_allow_userinit_same_script_gd`);
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
extractPossilbeContextGD(links) {
|
|
181
|
+
return new Set(links.map((link) => parse(link).generalDomain));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
setContextFromEvent(ev, contextHTML, herf, sender) {
|
|
185
|
+
let cGD = null;
|
|
186
|
+
let pageGD = null;
|
|
187
|
+
const html = contextHTML || '';
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
pageGD = parse(sender.tab.url).generalDomain;
|
|
191
|
+
cGD = parse(ev.target.baseURI).generalDomain;
|
|
192
|
+
} catch (ee) {
|
|
193
|
+
logger.error('CookieContext could not parse URL', ee);
|
|
194
|
+
// empty
|
|
195
|
+
}
|
|
196
|
+
if (!pageGD || cGD === pageGD) {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
// Try to guess the possible domain from scripts src
|
|
200
|
+
const possibleCGD = this.extractPossilbeContextGD(ev.target.linksSrc);
|
|
201
|
+
this.contextFromEvent = {
|
|
202
|
+
html,
|
|
203
|
+
ts: Date.now(),
|
|
204
|
+
cGD,
|
|
205
|
+
pageGD,
|
|
206
|
+
possibleCGD,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
import { parse } from '../../utils/url';
|
|
13
|
+
import Subject from '../utils/subject';
|
|
14
|
+
import ChromeStorageMap from '../utils/chrome-storage-map';
|
|
15
|
+
|
|
16
|
+
const DEFAULT_OPTIONS = {
|
|
17
|
+
CLICK_TIMEOUT: 5 * 60 * 1000,
|
|
18
|
+
VISIT_TIMEOUT: 4 * 60 * 1000,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default class OAuthDetector {
|
|
22
|
+
constructor(options = DEFAULT_OPTIONS) {
|
|
23
|
+
Object.assign(this, DEFAULT_OPTIONS, options);
|
|
24
|
+
|
|
25
|
+
this.clickActivity = new ChromeStorageMap({
|
|
26
|
+
storageKey: 'wtm-request-reporting:oauth-detector:click-activity',
|
|
27
|
+
ttlInMs: this.CLICK_TIMEOUT,
|
|
28
|
+
});
|
|
29
|
+
this.siteActivitiy = new ChromeStorageMap({
|
|
30
|
+
storageKey: 'wtm-request-reporting:oauth-detector:site-activity',
|
|
31
|
+
ttlInMs: this.VISIT_TIMEOUT,
|
|
32
|
+
});
|
|
33
|
+
this.subjectMainFrames = new Subject();
|
|
34
|
+
this.tabClicks = new Subject();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
recordClick(ev, contextHTML, href, sender) {
|
|
38
|
+
this.tabClicks.pub(sender.tab);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async init() {
|
|
42
|
+
await this.clickActivity.isReady;
|
|
43
|
+
await this.siteActivitiy.isReady;
|
|
44
|
+
this.tabActivitySubscription = this.tabClicks.subscribe((event) => {
|
|
45
|
+
this.clickActivity.set(event.id, event.url);
|
|
46
|
+
});
|
|
47
|
+
this.pageOpenedSubscription = this.subjectMainFrames.subscribe((event) => {
|
|
48
|
+
this.siteActivitiy.set(event.hostname, event.tabId);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
unload() {
|
|
53
|
+
if (this.tabActivitySubscription) {
|
|
54
|
+
this.tabActivitySubscription.unsubscribe();
|
|
55
|
+
}
|
|
56
|
+
if (this.pageOpenedSubscription) {
|
|
57
|
+
this.pageOpenedSubscription.unsubscribe();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
checkMainFrames(state) {
|
|
62
|
+
if (state.isMainFrame) {
|
|
63
|
+
this.subjectMainFrames.pub({
|
|
64
|
+
tabId: state.tabId,
|
|
65
|
+
hostname: state.urlParts.hostname,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Pipeline step to check if this request is part of a OAuth flow. This is done by
|
|
72
|
+
* checking that the following three conditions are met:
|
|
73
|
+
* - The third-party url path contains '/oauth' or '/authorize'
|
|
74
|
+
* - The user has recently clicked in the source tab (i.e. the site wanting to authenticate the
|
|
75
|
+
* user)
|
|
76
|
+
* - The user has recently visited the oauth domain (the authentication provider)
|
|
77
|
+
* @param state
|
|
78
|
+
* @returns false if the request is an oauth request, true otherwise
|
|
79
|
+
*/
|
|
80
|
+
checkIsOAuth(state, type) {
|
|
81
|
+
const isOAuthFlow = ['/oauth', '/authorize'].some((pattern) =>
|
|
82
|
+
state.urlParts.pathname.includes(pattern),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
if (
|
|
86
|
+
isOAuthFlow &&
|
|
87
|
+
this.clickActivity.get(state.tabId) &&
|
|
88
|
+
this.siteActivitiy.get(state.urlParts.hostname)
|
|
89
|
+
) {
|
|
90
|
+
const clickedPage = parse(this.clickActivity.get(state.tabId));
|
|
91
|
+
if (
|
|
92
|
+
clickedPage !== null &&
|
|
93
|
+
clickedPage.hostname === state.tabUrlParts.hostname
|
|
94
|
+
) {
|
|
95
|
+
state.incrementStat(`${type}_allow_oauth`);
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
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 no-param-reassign: 'off' */
|
|
13
|
+
import { truncateDomain } from '../utils';
|
|
14
|
+
|
|
15
|
+
// maps string (web-ext) to int (FF cpt). Anti-tracking still uses these legacy types.
|
|
16
|
+
const TYPE_LOOKUP = {
|
|
17
|
+
other: 1,
|
|
18
|
+
script: 2,
|
|
19
|
+
image: 3,
|
|
20
|
+
stylesheet: 4,
|
|
21
|
+
object: 5,
|
|
22
|
+
main_frame: 6,
|
|
23
|
+
sub_frame: 7,
|
|
24
|
+
xbl: 9,
|
|
25
|
+
ping: 10,
|
|
26
|
+
xmlhttprequest: 11,
|
|
27
|
+
object_subrequest: 12,
|
|
28
|
+
xml_dtd: 13,
|
|
29
|
+
font: 14,
|
|
30
|
+
media: 15,
|
|
31
|
+
websocket: 16,
|
|
32
|
+
csp_report: 17,
|
|
33
|
+
xslt: 18,
|
|
34
|
+
beacon: 19,
|
|
35
|
+
imageset: 21,
|
|
36
|
+
web_manifest: 22,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default class PageLogger {
|
|
40
|
+
constructor(config) {
|
|
41
|
+
this.config = config;
|
|
42
|
+
// maintain the request metadabase between pipeline steps
|
|
43
|
+
this._requestCounters = new Map();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
_attachCounters(state) {
|
|
47
|
+
const stats = state.page.getStatsForDomain(
|
|
48
|
+
truncateDomain(state.urlParts.domainInfo, 2),
|
|
49
|
+
);
|
|
50
|
+
state.reqLog = stats;
|
|
51
|
+
const incrementStat = (statName, c) => {
|
|
52
|
+
stats[statName] = (stats[statName] || 0) + (c || 1);
|
|
53
|
+
};
|
|
54
|
+
const setStat = (statName, value) => {
|
|
55
|
+
stats[statName] = value;
|
|
56
|
+
};
|
|
57
|
+
state.incrementStat = incrementStat;
|
|
58
|
+
state.setStat = setStat;
|
|
59
|
+
|
|
60
|
+
if (state.requestId) {
|
|
61
|
+
this._requestCounters.set(state.requestId, {
|
|
62
|
+
incrementStat,
|
|
63
|
+
setStat,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
_loadStatCounters(state) {
|
|
69
|
+
const meta = this._requestCounters.get(state.requestId);
|
|
70
|
+
Object.keys(meta).forEach((k) => {
|
|
71
|
+
state[k] = meta[k];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
onBeforeRequest(state) {
|
|
76
|
+
this._attachCounters(state);
|
|
77
|
+
const { incrementStat, urlParts } = state;
|
|
78
|
+
|
|
79
|
+
incrementStat('c');
|
|
80
|
+
if (urlParts.search.length > 0) {
|
|
81
|
+
incrementStat('has_qs');
|
|
82
|
+
}
|
|
83
|
+
if (urlParts.hasParameterString() > 0) {
|
|
84
|
+
incrementStat('has_ps');
|
|
85
|
+
}
|
|
86
|
+
if (urlParts.hash.length > 0) {
|
|
87
|
+
incrementStat('has_fragment');
|
|
88
|
+
}
|
|
89
|
+
if (state.method === 'POST') {
|
|
90
|
+
incrementStat('has_post');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
incrementStat(`type_${TYPE_LOOKUP[state.type] || 'unknown'}`);
|
|
94
|
+
|
|
95
|
+
// log protocol (secure or not)
|
|
96
|
+
const isHTTP = (protocol) => protocol === 'http:' || protocol === 'https:';
|
|
97
|
+
const scheme = isHTTP(urlParts.protocol) ? urlParts.scheme : 'other';
|
|
98
|
+
incrementStat(`scheme_${scheme}`);
|
|
99
|
+
|
|
100
|
+
// find frame depth
|
|
101
|
+
incrementStat(`window_depth_${Math.min(state.frameAncestors.length, 2)}`);
|
|
102
|
+
|
|
103
|
+
if (state.url.indexOf(this.config.placeHolder) > -1) {
|
|
104
|
+
incrementStat('hasPlaceHolder');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
onBeforeSendHeaders(state) {
|
|
109
|
+
if (state.requestId && this._requestCounters.has(state.requestId)) {
|
|
110
|
+
this._loadStatCounters(state);
|
|
111
|
+
} else {
|
|
112
|
+
this._attachCounters(state);
|
|
113
|
+
}
|
|
114
|
+
// referer stats
|
|
115
|
+
const referrer = state.getReferrer();
|
|
116
|
+
if (referrer && referrer.indexOf(state.tabUrl) > -1) {
|
|
117
|
+
state.incrementStat('referer_leak_header');
|
|
118
|
+
}
|
|
119
|
+
if (
|
|
120
|
+
state.url.indexOf(state.tabUrlParts.hostname) > -1 ||
|
|
121
|
+
state.url.indexOf(encodeURIComponent(state.tabUrlParts.hostname)) > -1
|
|
122
|
+
) {
|
|
123
|
+
state.incrementStat('referer_leak_site');
|
|
124
|
+
if (
|
|
125
|
+
state.url.indexOf(state.tabUrlParts.pathname) > -1 ||
|
|
126
|
+
state.url.indexOf(encodeURIComponent(state.tabUrlParts.pathname)) > -1
|
|
127
|
+
) {
|
|
128
|
+
state.incrementStat('referer_leak_path');
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// check if the request contains a cookie
|
|
132
|
+
state.cookieData = state.getCookieData();
|
|
133
|
+
const hasCookie = state.cookieData && state.cookieData.length > 5;
|
|
134
|
+
if (hasCookie) {
|
|
135
|
+
state.incrementStat('cookie_set');
|
|
136
|
+
}
|
|
137
|
+
state.hasCookie = hasCookie;
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
onHeadersReceived(state) {
|
|
142
|
+
if (state.requestId && this._requestCounters.has(state.requestId)) {
|
|
143
|
+
this._loadStatCounters(state);
|
|
144
|
+
} else {
|
|
145
|
+
this._attachCounters(state);
|
|
146
|
+
}
|
|
147
|
+
state.incrementStat('resp_ob');
|
|
148
|
+
state.incrementStat(
|
|
149
|
+
'content_length',
|
|
150
|
+
parseInt(state.getResponseHeader('Content-Length'), 10) || 0,
|
|
151
|
+
);
|
|
152
|
+
state.incrementStat(`status_${state.statusCode}`);
|
|
153
|
+
|
|
154
|
+
const setCookie = state.getResponseHeader('Set-Cookie');
|
|
155
|
+
const hasSetCookie = setCookie && setCookie.length > 5;
|
|
156
|
+
if (hasSetCookie) {
|
|
157
|
+
state.incrementStat('set_cookie_set');
|
|
158
|
+
// log samesite=none: explicit cross site cookies
|
|
159
|
+
if (setCookie.toLowerCase().indexOf('samesite=none') !== -1) {
|
|
160
|
+
state.incrementStat('set_cookie_samesite_none');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
state.hasSetCookie = hasSetCookie;
|
|
164
|
+
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
reattachStatCounter(state) {
|
|
169
|
+
const { requestId } = state;
|
|
170
|
+
if (requestId && this._requestCounters.has(requestId)) {
|
|
171
|
+
this._loadStatCounters(state);
|
|
172
|
+
this._requestCounters.delete(requestId);
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
+
import TempSet from '../utils/temp-set';
|
|
13
|
+
|
|
14
|
+
const CACHE_TIMEOUT = 10 * 1000;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Caches 302 redirects so that we can ensure that the resulting request is properly
|
|
18
|
+
* passed through the token logic.
|
|
19
|
+
*/
|
|
20
|
+
export default class RedirectTagger {
|
|
21
|
+
constructor() {
|
|
22
|
+
this.redirectCache = new TempSet();
|
|
23
|
+
this.redirectTaggerCache = new TempSet();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
isFromRedirect(url) {
|
|
27
|
+
return this.redirectCache.has(url);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
checkRedirectStatus(state) {
|
|
31
|
+
if (state.statusCode === 302) {
|
|
32
|
+
const location = state.getResponseHeader('Location');
|
|
33
|
+
if (!location) {
|
|
34
|
+
// 302 without "Location" in header?
|
|
35
|
+
console.log(state, '302 without "Location" in header?');
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
if (location.startsWith('/')) {
|
|
39
|
+
// relative redirect
|
|
40
|
+
const redirectUrl = `${state.urlParts.protocol}://${state.urlParts.hostname}${location}`;
|
|
41
|
+
this.redirectCache.add(redirectUrl, CACHE_TIMEOUT);
|
|
42
|
+
} else if (
|
|
43
|
+
location.startsWith('http://') ||
|
|
44
|
+
location.startsWith('https://')
|
|
45
|
+
) {
|
|
46
|
+
// absolute redirect
|
|
47
|
+
this.redirectCache.add(location, CACHE_TIMEOUT);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
checkRedirect(details) {
|
|
54
|
+
if (details.isRedirect && details.requestId !== undefined) {
|
|
55
|
+
this.redirectTaggerCache.add(details.requestId, CACHE_TIMEOUT);
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
confirmRedirect(details) {
|
|
62
|
+
if (
|
|
63
|
+
details.requestId !== undefined &&
|
|
64
|
+
this.redirectTaggerCache.has(details.requestId)
|
|
65
|
+
) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (details.isMainFrame && details.isRedirect) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
export default class SubdomainCheck {
|
|
13
|
+
constructor(config) {
|
|
14
|
+
this.config = config;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
checkBadSubdomain(state, response) {
|
|
18
|
+
const subdomainRewriteRules = this.config.subdomainRewriteRules || {};
|
|
19
|
+
const requestHost = state.urlParts.hostname;
|
|
20
|
+
const rules = Object.keys(subdomainRewriteRules);
|
|
21
|
+
for (let i = 0; i < rules.length; i += 1) {
|
|
22
|
+
const rule = rules[i];
|
|
23
|
+
if (requestHost.endsWith(rule)) {
|
|
24
|
+
const newUrl = state.url.replace(
|
|
25
|
+
requestHost,
|
|
26
|
+
subdomainRewriteRules[rule],
|
|
27
|
+
);
|
|
28
|
+
response.redirectTo(newUrl);
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|