@whotracksme/reporting 5.1.25 → 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/tests.yml +3 -1
- package/CHANGELOG.md +16 -0
- package/package.json +3 -2
- package/reporting/karma.conf.cjs +2 -0
- package/reporting/package.json +2 -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 +28 -28
- 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 +2 -1
- 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 +6 -0
- 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/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/utils/url.spec.js +1 -26
- package/reporting/test/webrequest-pipeline/index.test.js +85 -0
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* file, You can obtain one at http://mozilla.org/MPL/2.0
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
import RequestMonitor from './request/index';
|
|
13
|
-
import Config from './request/config';
|
|
14
|
-
import Database from './request/database';
|
|
12
|
+
import RequestMonitor from './request/index.js';
|
|
13
|
+
import Config from './request/config.js';
|
|
14
|
+
import Database from './request/database.js';
|
|
15
15
|
|
|
16
16
|
export default class RequestReporter {
|
|
17
17
|
constructor(
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
import logger from './logger';
|
|
13
13
|
import { isHash } from './hash-detector';
|
|
14
|
-
//import { isHash } from './hash-detector-new';
|
|
15
14
|
|
|
16
15
|
function isCharNumber(char) {
|
|
17
16
|
const code = char.charCodeAt(0);
|
|
@@ -221,11 +220,17 @@ function tryParseUrl(url) {
|
|
|
221
220
|
}
|
|
222
221
|
}
|
|
223
222
|
|
|
224
|
-
function
|
|
223
|
+
function isPrivateHostname(hostname) {
|
|
225
224
|
// TODO: this could be extended to detect more cases
|
|
226
225
|
return hostname === 'localhost' || hostname === '127.0.0.1';
|
|
227
226
|
}
|
|
228
227
|
|
|
228
|
+
// Note: This is a conservative implementation that detects all valid IPv4 addresses.
|
|
229
|
+
// It may produce false-positives, so consider this if using for other purposes.
|
|
230
|
+
function looksLikeIPv4Address(hostname) {
|
|
231
|
+
return /^[0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}[.][0-9]{1,3}$/.test(hostname);
|
|
232
|
+
}
|
|
233
|
+
|
|
229
234
|
function looksLikeSafeUrlParameter(key, value) {
|
|
230
235
|
return value.length < 18 || /^[a-z-_]+$/.test(value);
|
|
231
236
|
}
|
|
@@ -346,9 +351,12 @@ export function sanitizeUrl(url, options = {}) {
|
|
|
346
351
|
if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
|
|
347
352
|
return drop('URL has uncommon protocol');
|
|
348
353
|
}
|
|
349
|
-
if (
|
|
354
|
+
if (isPrivateHostname(parsedUrl.hostname)) {
|
|
350
355
|
return drop('URL is not public');
|
|
351
356
|
}
|
|
357
|
+
if (looksLikeIPv4Address(parsedUrl.hostname)) {
|
|
358
|
+
return drop('hostname is an ipv4 address');
|
|
359
|
+
}
|
|
352
360
|
if (urlLeaksExtensionId(url)) {
|
|
353
361
|
return drop('URL leaks extension ID');
|
|
354
362
|
}
|
|
@@ -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
|
// Pacemaker is a service which allows to schedule tasks (either as intervals or
|
|
15
15
|
// timeouts) while doing its best to not wake-up the browser too often. To this
|
|
@@ -68,35 +68,6 @@ function tryDecode(fn) {
|
|
|
68
68
|
|
|
69
69
|
export const tryDecodeURIComponent = tryDecode(decodeURIComponent);
|
|
70
70
|
|
|
71
|
-
export function isPrivateIP(ip) {
|
|
72
|
-
// Need to check for ipv6.
|
|
73
|
-
if (ip.indexOf(':') !== -1) {
|
|
74
|
-
// ipv6
|
|
75
|
-
if (ip === '::1') {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
const ipParts = ip.split(':');
|
|
79
|
-
return (
|
|
80
|
-
ipParts[0].startsWith('fd') ||
|
|
81
|
-
ipParts.every((d, i) => {
|
|
82
|
-
if (i === ipParts.length - 1) {
|
|
83
|
-
// last group of address
|
|
84
|
-
return d === '1';
|
|
85
|
-
}
|
|
86
|
-
return d === '0' || !d;
|
|
87
|
-
})
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
const ipParts = ip.split('.').map((d) => parseInt(d, 10));
|
|
91
|
-
return (
|
|
92
|
-
ipParts[0] === 10 ||
|
|
93
|
-
(ipParts[0] === 192 && ipParts[1] === 168) ||
|
|
94
|
-
(ipParts[0] === 172 && ipParts[1] >= 16 && ipParts[1] < 32) ||
|
|
95
|
-
ipParts[0] === 127 ||
|
|
96
|
-
ipParts[0] === 0
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
71
|
export function getName(url) {
|
|
101
72
|
if (url === null) {
|
|
102
73
|
return null;
|
|
@@ -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) => {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
import * as chai from 'chai';
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import { getName, parse } from '../../src/utils/url';
|
|
15
15
|
|
|
16
16
|
const plainUrls = [
|
|
17
17
|
{
|
|
@@ -521,31 +521,6 @@ function fillInSpec(spec) {
|
|
|
521
521
|
}
|
|
522
522
|
|
|
523
523
|
describe('utils/url', function () {
|
|
524
|
-
describe('#isPrivateIP', function () {
|
|
525
|
-
it('should detect private ipv4 subnets', function () {
|
|
526
|
-
chai.expect(isPrivateIP('127.0.0.1')).to.be.true;
|
|
527
|
-
chai.expect(isPrivateIP('192.168.2.107')).to.be.true;
|
|
528
|
-
chai.expect(isPrivateIP('192.168.1.41')).to.be.true;
|
|
529
|
-
chai.expect(isPrivateIP('10.0.5.250')).to.be.true;
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
it('should detect public ipv4 subnets', function () {
|
|
533
|
-
chai.expect(isPrivateIP('93.184.216.34')).to.be.false;
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
// once we add support for ipv6, this test is expected to pass
|
|
537
|
-
it('should detect private ipv6 subnets', function () {
|
|
538
|
-
chai.expect(isPrivateIP('::1')).to.be.true;
|
|
539
|
-
chai.expect(isPrivateIP('0:0:0:0:0:0:0:1')).to.be.true;
|
|
540
|
-
chai.expect(isPrivateIP('fd12:3456:789a:1::1')).to.be.true;
|
|
541
|
-
});
|
|
542
|
-
|
|
543
|
-
it('should detect public ipv6 address', function () {
|
|
544
|
-
chai.expect(isPrivateIP('2001:0db8:85a3:0000:0000:8a2e:0370:7334')).to.be
|
|
545
|
-
.false;
|
|
546
|
-
});
|
|
547
|
-
});
|
|
548
|
-
|
|
549
524
|
describe('#getName', () => {
|
|
550
525
|
it('return "null" for invalid URL', () => {
|
|
551
526
|
chai.expect(getName(parse('foo'))).to.equal(null);
|
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
import chrome from 'sinon-chrome';
|
|
13
13
|
import { expect } from 'chai';
|
|
14
14
|
|
|
15
|
+
import { playScenario } from '../helpers/scenarios.js';
|
|
16
|
+
|
|
15
17
|
import WebRequestPipeline from '../../src/webrequest-pipeline/index.js';
|
|
16
18
|
|
|
17
19
|
describe('WebRequestPipeline', function () {
|
|
@@ -58,5 +60,88 @@ describe('WebRequestPipeline', function () {
|
|
|
58
60
|
});
|
|
59
61
|
});
|
|
60
62
|
});
|
|
63
|
+
|
|
64
|
+
context('with pre-recorded events', function () {
|
|
65
|
+
let pipeline;
|
|
66
|
+
|
|
67
|
+
beforeEach(function () {
|
|
68
|
+
pipeline = new WebRequestPipeline();
|
|
69
|
+
pipeline.init();
|
|
70
|
+
[
|
|
71
|
+
'onBeforeRequest',
|
|
72
|
+
'onBeforeSendHeaders',
|
|
73
|
+
'onHeadersReceived',
|
|
74
|
+
'onAuthRequired',
|
|
75
|
+
'onBeforeRedirect',
|
|
76
|
+
'onCompleted',
|
|
77
|
+
'onErrorOccurred',
|
|
78
|
+
].forEach((step) => {
|
|
79
|
+
pipeline.addPipelineStep(step, {
|
|
80
|
+
name: 'test',
|
|
81
|
+
spec: 'annotate',
|
|
82
|
+
fn: () => {},
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
afterEach(function () {
|
|
88
|
+
pipeline.unload();
|
|
89
|
+
pipeline = undefined;
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
context('0001-quick-close', function () {
|
|
93
|
+
it('runs without a crash', async function () {
|
|
94
|
+
await playScenario(chrome, {
|
|
95
|
+
scenarioName: '0001-quick-close',
|
|
96
|
+
scenarioRelease: '2024-09-27',
|
|
97
|
+
});
|
|
98
|
+
expect(pipeline.pageStore.tabs.countNonExpiredKeys()).to.be.equal(1);
|
|
99
|
+
const [tabId] = pipeline.pageStore.tabs.keys().toArray();
|
|
100
|
+
const tab = pipeline.pageStore.tabs.get(tabId);
|
|
101
|
+
expect(tab).to.deep.include({
|
|
102
|
+
url: 'https://ghosterysearch.com/',
|
|
103
|
+
});
|
|
104
|
+
expect(tab.previous).to.deep.include({
|
|
105
|
+
url: 'about:blank',
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
context('0002-quick-navigation', function () {
|
|
111
|
+
it('runs without a crash', async function () {
|
|
112
|
+
await playScenario(chrome, {
|
|
113
|
+
scenarioName: '0002-quick-navigation',
|
|
114
|
+
scenarioRelease: '2024-09-27',
|
|
115
|
+
});
|
|
116
|
+
expect(pipeline.pageStore.tabs.countNonExpiredKeys()).to.be.equal(1);
|
|
117
|
+
const [tabId] = pipeline.pageStore.tabs.keys().toArray();
|
|
118
|
+
const tab = pipeline.pageStore.tabs.get(tabId);
|
|
119
|
+
expect(tab).to.deep.include({
|
|
120
|
+
url: 'https://www.facebook.com/login/?next=https%3A%2F%2Fwww.facebook.com%2F',
|
|
121
|
+
});
|
|
122
|
+
expect(tab.previous).to.deep.include({
|
|
123
|
+
url: 'https://ghosterysearch.com/',
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
context('0003-prefetch', function () {
|
|
129
|
+
it('runs without a crash', async function () {
|
|
130
|
+
await playScenario(chrome, {
|
|
131
|
+
scenarioName: '0003-prefetch',
|
|
132
|
+
scenarioRelease: '2024-09-27',
|
|
133
|
+
});
|
|
134
|
+
expect(pipeline.pageStore.tabs.countNonExpiredKeys()).to.be.equal(1);
|
|
135
|
+
const [tabId] = pipeline.pageStore.tabs.keys().toArray();
|
|
136
|
+
const tab = pipeline.pageStore.tabs.get(tabId);
|
|
137
|
+
expect(tab).to.deep.include({
|
|
138
|
+
url: 'http://localhost:8080/',
|
|
139
|
+
});
|
|
140
|
+
expect(tab.previous).to.deep.include({
|
|
141
|
+
url: 'about:blank',
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|
|
61
146
|
});
|
|
62
147
|
});
|