@whotracksme/reporting 5.1.24 → 5.1.26
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/.github/workflows/release.yml +2 -2
- package/.github/workflows/tests.yml +4 -5
- package/.tool-versions +1 -1
- package/CHANGELOG.md +32 -0
- package/package.json +3 -2
- package/reporting/karma.conf.cjs +2 -0
- package/reporting/package.json +4 -1
- package/reporting/src/bloom-filters.js +4 -4
- package/reporting/src/fixed-size-cache.js +1 -1
- package/reporting/src/logger.js +0 -1
- package/reporting/src/md5.js +1 -1
- package/reporting/src/network.js +1 -1
- package/reporting/src/pages.js +84 -21
- package/reporting/src/persisted-bitarray.js +2 -2
- package/reporting/src/request/config.js +2 -2
- package/reporting/src/request/hash.js +2 -2
- package/reporting/src/request/index.js +30 -29
- package/reporting/src/request/page-telemetry.js +2 -2
- package/reporting/src/request/qs-whitelist2.js +3 -3
- package/reporting/src/request/steps/cookie-context.js +6 -6
- package/reporting/src/request/steps/oauth-detector.js +3 -3
- package/reporting/src/request/steps/page-logger.js +5 -2
- package/reporting/src/request/steps/redirect-tagger.js +1 -1
- package/reporting/src/request/steps/token-checker/index.js +3 -3
- package/reporting/src/request/steps/token-checker/token-domain.js +3 -3
- package/reporting/src/request/steps/token-examiner.js +5 -5
- package/reporting/src/request/steps/token-telemetry/cached-entry-pipeline.js +3 -3
- package/reporting/src/request/steps/token-telemetry/index.js +4 -4
- package/reporting/src/request/steps/token-telemetry/key-pipeline.js +1 -1
- package/reporting/src/request/steps/token-telemetry/token-pipeline.js +1 -1
- package/reporting/src/request/utils/bloom-filter-packed.js +1 -1
- package/reporting/src/request/utils/chrome-storage-map.js +13 -1
- package/reporting/src/request/utils/subject.js +1 -1
- package/reporting/src/request/utils/temp-set.js +1 -1
- package/reporting/src/request-reporter.js +3 -3
- package/reporting/src/sanitizer.js +11 -3
- package/reporting/src/utils/pacemaker.js +1 -1
- package/reporting/src/utils/url.js +0 -29
- package/reporting/src/webrequest-pipeline/cname-uncloak.js +2 -2
- package/reporting/src/webrequest-pipeline/index.js +10 -11
- package/reporting/src/webrequest-pipeline/logger.js +1 -1
- package/reporting/src/webrequest-pipeline/page-store.js +23 -20
- package/reporting/src/webrequest-pipeline/page.js +81 -104
- package/reporting/src/webrequest-pipeline/pipeline.js +1 -1
- package/reporting/src/webrequest-pipeline/utils/webrequest.js +63 -57
- package/reporting/src/webrequest-pipeline/webrequest-context.js +6 -5
- package/reporting/test/helpers/fetch-mock.js +2 -2
- package/reporting/test/helpers/scenarios.js +85 -0
- package/reporting/test/pages.spec.js +52 -4
- package/reporting/test/request-reporter.test.js +251 -0
- package/reporting/test/sanitizer.spec.js +16 -0
- package/reporting/test/setup.unit.js +17 -0
- package/reporting/test/utils/url.spec.js +1 -26
- package/reporting/test/webrequest-pipeline/index.test.js +147 -0
- package/reporting/test/webrequest-pipeline/page-store.test.js +135 -0
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import logger from '../logger';
|
|
12
|
+
import logger from '../logger.js';
|
|
13
13
|
|
|
14
14
|
export const VALID_RESPONSE_PROPERTIES = {
|
|
15
15
|
onBeforeRequest: ['cancel', 'redirectUrl'],
|
|
@@ -21,10 +21,6 @@ export const VALID_RESPONSE_PROPERTIES = {
|
|
|
21
21
|
onErrorOccurred: [],
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
-
const HAS_WEB_REQUEST_BLOCKING = chrome?.runtime
|
|
25
|
-
?.getManifest()
|
|
26
|
-
?.permissions.includes('webRequestBlocking');
|
|
27
|
-
|
|
28
24
|
function getOptionArray(options) {
|
|
29
25
|
if (!options) {
|
|
30
26
|
return [];
|
|
@@ -41,73 +37,83 @@ function getOptionArray(options) {
|
|
|
41
37
|
// options.REQUEST_BODY,
|
|
42
38
|
];
|
|
43
39
|
|
|
44
|
-
if (
|
|
40
|
+
if (
|
|
41
|
+
chrome?.runtime?.getManifest()?.permissions.includes('webRequestBlocking')
|
|
42
|
+
) {
|
|
45
43
|
optionsSubset.push(options.BLOCKING);
|
|
46
44
|
}
|
|
47
45
|
|
|
48
46
|
return optionsSubset.filter((o) => !!o);
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
// build allowed extraInfo options from <Step>Options objects.
|
|
52
|
-
export const EXTRA_INFO_SPEC = {
|
|
53
|
-
onBeforeRequest: getOptionArray(chrome.webRequest.OnBeforeRequestOptions),
|
|
54
|
-
onBeforeSendHeaders: getOptionArray(
|
|
55
|
-
chrome.webRequest.OnBeforeSendHeadersOptions,
|
|
56
|
-
),
|
|
57
|
-
onHeadersReceived: getOptionArray(chrome.webRequest.OnHeadersReceivedOptions),
|
|
58
|
-
onAuthRequired: getOptionArray(chrome.webRequest.OnAuthRequiredOptions),
|
|
59
|
-
onBeforeRedirect: getOptionArray(chrome.webRequest.OnBeforeRedirectOptions),
|
|
60
|
-
onCompleted: getOptionArray(chrome.webRequest.OnCompletedOptions),
|
|
61
|
-
onErrorOccurred: undefined,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const HANDLERS = {};
|
|
65
49
|
const urls = ['http://*/*', 'https://*/*'];
|
|
66
50
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
51
|
+
export default class WebRequestListenersManager {
|
|
52
|
+
constructor() {
|
|
53
|
+
this.HANDLERS = {};
|
|
54
|
+
// build allowed extraInfo options from <Step>Options objects.
|
|
55
|
+
const EXTRA_INFO_SPEC = {
|
|
56
|
+
onBeforeRequest: getOptionArray(chrome.webRequest.OnBeforeRequestOptions),
|
|
57
|
+
onBeforeSendHeaders: getOptionArray(
|
|
58
|
+
chrome.webRequest.OnBeforeSendHeadersOptions,
|
|
59
|
+
),
|
|
60
|
+
onHeadersReceived: getOptionArray(
|
|
61
|
+
chrome.webRequest.OnHeadersReceivedOptions,
|
|
62
|
+
),
|
|
63
|
+
onAuthRequired: getOptionArray(chrome.webRequest.OnAuthRequiredOptions),
|
|
64
|
+
onBeforeRedirect: getOptionArray(
|
|
65
|
+
chrome.webRequest.OnBeforeRedirectOptions,
|
|
66
|
+
),
|
|
67
|
+
onCompleted: getOptionArray(chrome.webRequest.OnCompletedOptions),
|
|
68
|
+
onErrorOccurred: undefined,
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
for (const event of Object.keys(EXTRA_INFO_SPEC)) {
|
|
72
|
+
// It might be that the platform does not support all listeners:
|
|
73
|
+
if (chrome.webRequest[event] === undefined) {
|
|
74
|
+
logger.warn(`chrome.webRequest.${event} is not supported`);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
// Get allowed options for this event (e.g.: 'blocking', 'requestHeaders',
|
|
79
|
+
// etc.)
|
|
80
|
+
const extraInfoSpec = EXTRA_INFO_SPEC[event];
|
|
77
81
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
82
|
+
let firstCall = true;
|
|
83
|
+
const callback = (...args) => {
|
|
84
|
+
if (!this.HANDLERS[event]) {
|
|
85
|
+
if (firstCall) {
|
|
86
|
+
firstCall = false;
|
|
87
|
+
logger.info(
|
|
88
|
+
`webRequest.${event} called without listener being assigned`,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
return this.HANDLERS[event](...args);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
if (extraInfoSpec === undefined) {
|
|
97
|
+
chrome.webRequest[event].addListener(callback, { urls });
|
|
98
|
+
} else {
|
|
99
|
+
chrome.webRequest[event].addListener(callback, { urls }, extraInfoSpec);
|
|
86
100
|
}
|
|
87
|
-
return;
|
|
88
101
|
}
|
|
89
|
-
return HANDLERS[event](...args);
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
if (extraInfoSpec === undefined) {
|
|
93
|
-
chrome.webRequest[event].addListener(callback, { urls });
|
|
94
|
-
} else {
|
|
95
|
-
chrome.webRequest[event].addListener(callback, { urls }, extraInfoSpec);
|
|
96
102
|
}
|
|
97
|
-
}
|
|
98
103
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
+
addListener(event, listener) {
|
|
105
|
+
if (this.HANDLERS[event]) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`webRequest.${event} expects only one listener as this all WebRequestPipeline should need`,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
this.HANDLERS[event] = listener;
|
|
104
111
|
}
|
|
105
|
-
HANDLERS[event] = listener;
|
|
106
|
-
}
|
|
107
112
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
113
|
+
removeListener(event, listener) {
|
|
114
|
+
if (this.HANDLERS[event] !== listener) {
|
|
115
|
+
throw new Error(`webRequest.${event} trying to remove wrong listener`);
|
|
116
|
+
}
|
|
117
|
+
this.HANDLERS[event] = null;
|
|
111
118
|
}
|
|
112
|
-
HANDLERS[event] = null;
|
|
113
119
|
}
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import { parse } from '../utils/url';
|
|
13
|
-
import logger from './logger';
|
|
12
|
+
import { parse } from '../utils/url.js';
|
|
13
|
+
import logger from './logger.js';
|
|
14
|
+
import { getFrameUrl, getFrameAncestors } from './page.js';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* Transform an array of headers (i.e.: `{ name, value }`) into a `Map`.
|
|
@@ -61,13 +62,13 @@ export default class WebRequestContext {
|
|
|
61
62
|
// **Chromium addition**
|
|
62
63
|
// frameAncestors
|
|
63
64
|
if (context.frameAncestors === undefined) {
|
|
64
|
-
context.frameAncestors = page ?
|
|
65
|
+
context.frameAncestors = page ? getFrameAncestors(page, context) : [];
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
// Cliqz-specific extensions to webRequest details
|
|
68
69
|
context.page = page;
|
|
69
|
-
context.tabUrl = context.tabUrl || (page && page.
|
|
70
|
-
context.frameUrl = context.frameUrl || (page &&
|
|
70
|
+
context.tabUrl = context.tabUrl || (page && page.url);
|
|
71
|
+
context.frameUrl = context.frameUrl || (page && getFrameUrl(page, context));
|
|
71
72
|
context.isPrivate = page ? page.isPrivate : null;
|
|
72
73
|
context.isMainFrame = context.type === 'main_frame';
|
|
73
74
|
context.isRedirect = page && context.isMainFrame && page.isRedirect;
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
// source https://stackoverflow.com/a/21797381
|
|
13
|
-
function base64ToArrayBuffer(base64) {
|
|
14
|
-
var binary_string =
|
|
13
|
+
export function base64ToArrayBuffer(base64) {
|
|
14
|
+
var binary_string = atob(base64);
|
|
15
15
|
var len = binary_string.length;
|
|
16
16
|
var bytes = new Uint8Array(len);
|
|
17
17
|
for (var i = 0; i < len; i++) {
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WhoTracks.Me
|
|
3
|
+
* https://ghostery.com/whotracksme
|
|
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 fs from 'node:fs';
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { brotliDecompressSync } from 'zlib';
|
|
15
|
+
|
|
16
|
+
async function download(release, scenario, browser) {
|
|
17
|
+
const scenartioFileName = `events_${scenario}_${browser}.log`;
|
|
18
|
+
|
|
19
|
+
const scenariosPath = path.join(
|
|
20
|
+
import.meta.dirname,
|
|
21
|
+
'..',
|
|
22
|
+
'..',
|
|
23
|
+
'scenarios',
|
|
24
|
+
release,
|
|
25
|
+
);
|
|
26
|
+
if (!fs.existsSync(scenariosPath)) {
|
|
27
|
+
fs.mkdirSync(scenariosPath, { recursive: true });
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const scenarioPath = path.join(scenariosPath, scenartioFileName);
|
|
31
|
+
if (fs.existsSync(scenarioPath)) {
|
|
32
|
+
return scenarioPath;
|
|
33
|
+
}
|
|
34
|
+
const downloadUrl = `https://github.com/ghostery/webextension-event-recorder/releases/download/${release}/${scenartioFileName}.br`;
|
|
35
|
+
const response = await fetch(downloadUrl);
|
|
36
|
+
|
|
37
|
+
if (!response.ok) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
`Cound not download scenario "${scenartioFileName}" from "${downloadUrl}: ${response.status} - ${response.statusText}`,
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
const compressedBuffer = await response.arrayBuffer();
|
|
43
|
+
const decompressedBuffer = brotliDecompressSync(
|
|
44
|
+
new Uint8Array(compressedBuffer),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
fs.writeFileSync(scenarioPath, decompressedBuffer);
|
|
48
|
+
return scenarioPath;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function loadScenario(scenarioPath) {
|
|
52
|
+
return fs
|
|
53
|
+
.readFileSync(scenarioPath, { encoding: 'utf-8' })
|
|
54
|
+
.split('\n')
|
|
55
|
+
.filter(Boolean)
|
|
56
|
+
.map(JSON.parse);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function rewriteIp(event) {
|
|
60
|
+
// prerecorded scenarios have local IPs, which will be ignored by the request monitor
|
|
61
|
+
if (event.ip) {
|
|
62
|
+
event.ip = '198.51.100.1';
|
|
63
|
+
}
|
|
64
|
+
return event;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export async function playScenario(
|
|
68
|
+
chrome,
|
|
69
|
+
{ scenarioRelease, scenarioName, browser = 'chrome' },
|
|
70
|
+
) {
|
|
71
|
+
if (!scenarioRelease) {
|
|
72
|
+
throw new Error('specify scenario release');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const scenarioPath = await download(scenarioRelease, scenarioName, browser);
|
|
76
|
+
const events = loadScenario(scenarioPath);
|
|
77
|
+
for (const event of events) {
|
|
78
|
+
try {
|
|
79
|
+
const args = event.args.map(rewriteIp);
|
|
80
|
+
chrome[event.api][event.event].dispatch(...args);
|
|
81
|
+
} catch (e) {
|
|
82
|
+
console.error(`Could not dispatch event`, event, e);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -112,8 +112,56 @@ class ChromeApiMock {
|
|
|
112
112
|
if (initialState.openTabs) {
|
|
113
113
|
uut.openTabs = new Map(initialState.openTabs);
|
|
114
114
|
}
|
|
115
|
-
|
|
115
|
+
|
|
116
|
+
// eslint-disable-next-line no-undef
|
|
117
|
+
const verbose = __karma__.config.VERBOSE_REPLAY;
|
|
118
|
+
// eslint-disable-next-line no-undef
|
|
119
|
+
const runSelfChecks = __karma__.config.ENABLE_SELF_CHECKS;
|
|
120
|
+
|
|
121
|
+
const history = [];
|
|
122
|
+
for (let step = 0; step < recordedEvents.length; step += 1) {
|
|
123
|
+
const { startedAt, api, event, args } = recordedEvents[step];
|
|
124
|
+
|
|
125
|
+
// (optional) build a log of the intermediate states
|
|
126
|
+
const stateBeforeAction = verbose
|
|
127
|
+
? uut.describe(startedAt)
|
|
128
|
+
: '<unavailable: set VERBOSE_REPLAY to enable>';
|
|
129
|
+
history.push({
|
|
130
|
+
stateBeforeAction,
|
|
131
|
+
step,
|
|
132
|
+
...recordedEvents[step],
|
|
133
|
+
});
|
|
134
|
+
if (history.length > 100) {
|
|
135
|
+
history.shift();
|
|
136
|
+
}
|
|
137
|
+
if (verbose) {
|
|
138
|
+
console.log(`--- Executing step: ${step} ---`);
|
|
139
|
+
console.log(JSON.stringify(history.at(-1), null, 2));
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// execute the next step (modifies the state)
|
|
116
143
|
this[api][event].dispatch(...args);
|
|
144
|
+
|
|
145
|
+
// (optional) run self-checks
|
|
146
|
+
// Warning: this is async, so it may change the observation!
|
|
147
|
+
if (runSelfChecks) {
|
|
148
|
+
const check = await uut.selfChecks();
|
|
149
|
+
const { status, overview, log } = check.report();
|
|
150
|
+
|
|
151
|
+
if (status === 'FAILED') {
|
|
152
|
+
const ppOverview = JSON.stringify(overview, null, 2);
|
|
153
|
+
console.error(
|
|
154
|
+
`*** self checks failed after step=${step}:\n`,
|
|
155
|
+
ppOverview,
|
|
156
|
+
'\n--- begin details ---:\n',
|
|
157
|
+
JSON.stringify(log, null, 2),
|
|
158
|
+
'\n--- end details ---',
|
|
159
|
+
);
|
|
160
|
+
throw new Error(
|
|
161
|
+
`self checks failed after step=${step} (for details, see logs)`,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
117
165
|
}
|
|
118
166
|
}
|
|
119
167
|
}
|
|
@@ -173,7 +221,7 @@ describe('#Pages', function () {
|
|
|
173
221
|
let chromeApiMock;
|
|
174
222
|
let urlAnalyzer;
|
|
175
223
|
|
|
176
|
-
function runScenario(name, { notes, expectations, events }) {
|
|
224
|
+
async function runScenario(name, { notes, expectations, events }) {
|
|
177
225
|
const { initialState, recorded } = events || {};
|
|
178
226
|
try {
|
|
179
227
|
expect(notes, '<notes>').to.be.a('string');
|
|
@@ -186,7 +234,7 @@ describe('#Pages', function () {
|
|
|
186
234
|
throw e;
|
|
187
235
|
}
|
|
188
236
|
|
|
189
|
-
chromeApiMock.replay(uut, initialState, recorded);
|
|
237
|
+
await chromeApiMock.replay(uut, initialState, recorded);
|
|
190
238
|
const state = uut.describe();
|
|
191
239
|
try {
|
|
192
240
|
const { expectedTabs, activeTab } = expectations;
|
|
@@ -499,7 +547,7 @@ describe('#Pages', function () {
|
|
|
499
547
|
'Broken test setup: expected a "scenario" field',
|
|
500
548
|
);
|
|
501
549
|
}
|
|
502
|
-
runScenario(name, fixture.scenario);
|
|
550
|
+
await runScenario(name, fixture.scenario);
|
|
503
551
|
testsPassed.push(name);
|
|
504
552
|
console.log(`test ${name}: PASSED`);
|
|
505
553
|
} catch (e) {
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/* eslint-disable prettier/prettier */
|
|
2
|
+
/**
|
|
3
|
+
* WhoTracks.Me
|
|
4
|
+
* https://ghostery.com/whotracksme
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2017-present Ghostery GmbH. All rights reserved.
|
|
7
|
+
*
|
|
8
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
9
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
10
|
+
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import 'fake-indexeddb/auto';
|
|
14
|
+
import { IDBFactory } from 'fake-indexeddb';
|
|
15
|
+
import chrome from 'sinon-chrome';
|
|
16
|
+
import sinon from 'sinon';
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import EventEmitter from 'node:events';
|
|
19
|
+
|
|
20
|
+
import { playScenario } from './helpers/scenarios.js';
|
|
21
|
+
import { base64ToArrayBuffer } from './helpers/fetch-mock.js';
|
|
22
|
+
|
|
23
|
+
import { setLogLevel } from '../src/logger.js';
|
|
24
|
+
import RequestReporter from '../src/request-reporter.js';
|
|
25
|
+
import WebRequestPipeline from '../src/webrequest-pipeline/index.js';
|
|
26
|
+
|
|
27
|
+
const config = {
|
|
28
|
+
configUrl: 'config',
|
|
29
|
+
remoteWhitelistUrl: 'whitelist',
|
|
30
|
+
localWhitelistUrl: 'local',
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
describe('RequestReporter', function () {
|
|
34
|
+
before(function () {
|
|
35
|
+
setLogLevel('error');
|
|
36
|
+
chrome.storage.session = chrome.storage.local;
|
|
37
|
+
globalThis.chrome = chrome;
|
|
38
|
+
const oldFetch = globalThis.fetch;
|
|
39
|
+
sinon.stub(globalThis, 'fetch').callsFake((...args) => {
|
|
40
|
+
const url = args[0];
|
|
41
|
+
if (url.startsWith(config.configUrl)) {
|
|
42
|
+
return Promise.resolve({
|
|
43
|
+
ok: true,
|
|
44
|
+
async json() {
|
|
45
|
+
return {};
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (url.startsWith(config.remoteWhitelistUrl)) {
|
|
51
|
+
return Promise.resolve({
|
|
52
|
+
ok: true,
|
|
53
|
+
async json() {
|
|
54
|
+
return {
|
|
55
|
+
version: '2018-10-11',
|
|
56
|
+
useDiff: false,
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
async arrayBuffer() {
|
|
60
|
+
// empty bloom filter
|
|
61
|
+
return base64ToArrayBuffer('AAAAAgrdwUcnN1113w==');
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return oldFetch(...args);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
beforeEach(function () {
|
|
71
|
+
chrome.flush();
|
|
72
|
+
chrome.storage.session.get.yields({});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
after(function () {
|
|
76
|
+
chrome.flush();
|
|
77
|
+
delete globalThis.chrome;
|
|
78
|
+
globalThis.fetch.restore();
|
|
79
|
+
setLogLevel('info');
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
context('with pre-recorded events', function () {
|
|
83
|
+
let reporter;
|
|
84
|
+
let clock;
|
|
85
|
+
const communicationEmiter = new EventEmitter();
|
|
86
|
+
|
|
87
|
+
beforeEach(async function () {
|
|
88
|
+
globalThis.indexedDB = new IDBFactory();
|
|
89
|
+
clock = sinon.useFakeTimers({ shouldAdvanceTime: true });
|
|
90
|
+
const trustedClock = {
|
|
91
|
+
getTimeAsYYYYMMDD() {
|
|
92
|
+
return '';
|
|
93
|
+
},
|
|
94
|
+
getTimeAsYYYYMMDDHH() {
|
|
95
|
+
return '';
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
communicationEmiter.removeAllListeners();
|
|
99
|
+
const communication = {
|
|
100
|
+
send(msg) {
|
|
101
|
+
communicationEmiter.emit('send', msg)
|
|
102
|
+
},
|
|
103
|
+
sendInstant(msg) {
|
|
104
|
+
communicationEmiter.emit('sendInstant', msg)
|
|
105
|
+
},
|
|
106
|
+
trustedClock,
|
|
107
|
+
};
|
|
108
|
+
const webRequestPipeline = new WebRequestPipeline();
|
|
109
|
+
await webRequestPipeline.init();
|
|
110
|
+
reporter = new RequestReporter(config, {
|
|
111
|
+
communication,
|
|
112
|
+
webRequestPipeline,
|
|
113
|
+
trustedClock,
|
|
114
|
+
getBrowserInfo: () => ({ name: 'xx' }),
|
|
115
|
+
countryProvider: { getSafeCountryCode: () => 'en' },
|
|
116
|
+
});
|
|
117
|
+
await reporter.init();
|
|
118
|
+
await reporter.requestMonitor.qs_whitelist.initPromise;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
afterEach(function () {
|
|
122
|
+
reporter.unload();
|
|
123
|
+
reporter.webRequestPipeline.unload();
|
|
124
|
+
reporter = undefined;
|
|
125
|
+
clock.restore();
|
|
126
|
+
delete globalThis.indexedDB;
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
context('0001-empty-page', function () {
|
|
130
|
+
it('detects no 3rd parties', async function () {
|
|
131
|
+
await playScenario(chrome, {
|
|
132
|
+
scenarioName: this.test.parent.title,
|
|
133
|
+
scenarioRelease: '2024-08-02',
|
|
134
|
+
});
|
|
135
|
+
await clock.runToLast();
|
|
136
|
+
expect(
|
|
137
|
+
reporter.webRequestPipeline.pageStore.tabs.countNonExpiredKeys(),
|
|
138
|
+
).to.be.equal(1);
|
|
139
|
+
const [tab] = reporter.webRequestPipeline.pageStore.tabs.values();
|
|
140
|
+
expect(tab.requestStats).to.be.empty;
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
context('0002-3rd-party', function () {
|
|
145
|
+
it('detects 3rd parties', async function () {
|
|
146
|
+
await playScenario(chrome, {
|
|
147
|
+
scenarioName: this.test.parent.title,
|
|
148
|
+
scenarioRelease: '2024-08-02',
|
|
149
|
+
});
|
|
150
|
+
await clock.runToLast();
|
|
151
|
+
expect(
|
|
152
|
+
reporter.webRequestPipeline.pageStore.tabs.countNonExpiredKeys(),
|
|
153
|
+
).to.be.equal(1);
|
|
154
|
+
const [tab] = reporter.webRequestPipeline.pageStore.tabs.values();
|
|
155
|
+
expect(tab.requestStats).to.have.keys([
|
|
156
|
+
'script.localhost',
|
|
157
|
+
]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('reports 3rd parties', async function () {
|
|
161
|
+
await playScenario(chrome, {
|
|
162
|
+
scenarioName: this.test.parent.title,
|
|
163
|
+
scenarioRelease: '2024-08-02',
|
|
164
|
+
});
|
|
165
|
+
await clock.runToLast();
|
|
166
|
+
const eventPromise = new Promise((resolve) => communicationEmiter.once('send', resolve));
|
|
167
|
+
// force stage all pages
|
|
168
|
+
reporter.webRequestPipeline.pageStore.tabs.forEach((page) => reporter.webRequestPipeline.pageStore.stagePage(page));
|
|
169
|
+
await clock.runToLast();
|
|
170
|
+
const event = await eventPromise;
|
|
171
|
+
expect(event).to.deep.include({
|
|
172
|
+
action: 'wtm.attrack.tp_events',
|
|
173
|
+
});
|
|
174
|
+
expect(event.payload.data[0].tps).to.have.keys([
|
|
175
|
+
'script.localhost',
|
|
176
|
+
])
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
context('0004-ping', function () {
|
|
181
|
+
it('reports pings', async function () {
|
|
182
|
+
const eventPromise = new Promise((resolve) => communicationEmiter.once('send', resolve));
|
|
183
|
+
await playScenario(chrome, {
|
|
184
|
+
scenarioName: this.test.parent.title,
|
|
185
|
+
scenarioRelease: '2024-08-02-1',
|
|
186
|
+
});
|
|
187
|
+
await clock.runToLast();
|
|
188
|
+
// first tp_event from the page that sent ping
|
|
189
|
+
const event = await eventPromise;
|
|
190
|
+
expect(event).to.deep.include({
|
|
191
|
+
action: 'wtm.attrack.tp_events',
|
|
192
|
+
});
|
|
193
|
+
expect(event.payload.data[0].tps).to.have.keys([
|
|
194
|
+
'ping.localhost',
|
|
195
|
+
])
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
context('0005-preload', function () {
|
|
200
|
+
it('reports 3rd parties', async function () {
|
|
201
|
+
await playScenario(chrome, {
|
|
202
|
+
scenarioName: this.test.parent.title,
|
|
203
|
+
scenarioRelease: '2024-08-02',
|
|
204
|
+
});
|
|
205
|
+
await clock.runToLast();
|
|
206
|
+
const eventPromise = new Promise((resolve) => communicationEmiter.once('send', resolve));
|
|
207
|
+
// force stage all pages
|
|
208
|
+
reporter.webRequestPipeline.pageStore.tabs.forEach((page) => reporter.webRequestPipeline.pageStore.stagePage(page));
|
|
209
|
+
await clock.runToLast();
|
|
210
|
+
const event = await eventPromise;
|
|
211
|
+
expect(event).to.deep.include({
|
|
212
|
+
action: 'wtm.attrack.tp_events',
|
|
213
|
+
});
|
|
214
|
+
expect(event.payload.data[0].tps).to.have.keys([
|
|
215
|
+
'preload.localhost',
|
|
216
|
+
]);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
context('0008-navigation', function () {
|
|
221
|
+
it('reports 3rd parties', async function () {
|
|
222
|
+
const eventPromise1 = new Promise((resolve) => communicationEmiter.once('send', resolve));
|
|
223
|
+
await playScenario(chrome, {
|
|
224
|
+
scenarioName: this.test.parent.title,
|
|
225
|
+
scenarioRelease: '2024-08-02-2',
|
|
226
|
+
});
|
|
227
|
+
await clock.runToLast();
|
|
228
|
+
const event1 = await eventPromise1;
|
|
229
|
+
expect(event1).to.deep.include({
|
|
230
|
+
action: 'wtm.attrack.tp_events',
|
|
231
|
+
});
|
|
232
|
+
expect(event1.payload.data[0].tps).to.have.keys([
|
|
233
|
+
'script1.localhost',
|
|
234
|
+
]);
|
|
235
|
+
const eventPromise2 = new Promise((resolve) => communicationEmiter.once('send', resolve));
|
|
236
|
+
// force stage all pages
|
|
237
|
+
reporter.webRequestPipeline.pageStore.tabs.forEach((page) => reporter.webRequestPipeline.pageStore.stagePage(page));
|
|
238
|
+
await clock.runToLast();
|
|
239
|
+
const event2 = await eventPromise2;
|
|
240
|
+
expect(event2).to.deep.include({
|
|
241
|
+
action: 'wtm.attrack.tp_events',
|
|
242
|
+
});
|
|
243
|
+
expect(event2.payload.data[0].tps).to.have.keys([
|
|
244
|
+
'script2.localhost',
|
|
245
|
+
]);
|
|
246
|
+
// reports should belong to different pages
|
|
247
|
+
expect(event1.payload.data[0].hostname).to.not.be.equal(event2.payload.data[0].hostname);
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
});
|
|
@@ -383,6 +383,22 @@ describe('#sanitizeUrl', function () {
|
|
|
383
383
|
});
|
|
384
384
|
});
|
|
385
385
|
|
|
386
|
+
describe('should drop URls where IP addresses are used as hostnames', function () {
|
|
387
|
+
[
|
|
388
|
+
'http://182.180.189.84/',
|
|
389
|
+
'http://192.168.0.119/',
|
|
390
|
+
'http://85.11.187.84/saff/index.php?topic=3221141.0',
|
|
391
|
+
'http://10.234.0.1/',
|
|
392
|
+
'https://10.234.0.1/',
|
|
393
|
+
'http://0.0.0.0/',
|
|
394
|
+
'http://1.1.1.1/',
|
|
395
|
+
].forEach((url) => {
|
|
396
|
+
it(`should drop URL: ${url}`, function () {
|
|
397
|
+
shouldBeDropped(url);
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
|
|
386
402
|
describe('should drop URLs with non-standard HTTP ports', function () {
|
|
387
403
|
['http://myserver.test:1234/', 'https://www.myserver.test:5678/'].forEach(
|
|
388
404
|
(url) => {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WhoTracks.Me
|
|
3
|
+
* https://ghostery.com/whotracksme
|
|
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 * as chai from 'chai';
|
|
13
|
+
import sinonChai from 'sinon-chai';
|
|
14
|
+
import chaiAsPromised from 'chai-as-promised';
|
|
15
|
+
|
|
16
|
+
chai.use(chaiAsPromised);
|
|
17
|
+
chai.use(sinonChai);
|