@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,263 @@
|
|
|
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 { expect } from 'chai';
|
|
13
|
+
import sinon from 'sinon';
|
|
14
|
+
|
|
15
|
+
import CountryProvider from '../src/country-provider.js';
|
|
16
|
+
|
|
17
|
+
const SECOND = 1000;
|
|
18
|
+
const MINUTE = 60 * SECOND;
|
|
19
|
+
const HOUR = 60 * MINUTE;
|
|
20
|
+
const DAY = 24 * HOUR;
|
|
21
|
+
const WEEK = 7 * DAY;
|
|
22
|
+
|
|
23
|
+
// Some big value which should be large enough to
|
|
24
|
+
// make sure all cooldowns have expired.
|
|
25
|
+
const SKIP_ALL_COOLDOWNS = WEEK;
|
|
26
|
+
|
|
27
|
+
describe('#CountryProvider', function () {
|
|
28
|
+
const storageKey = 'some-storage-key';
|
|
29
|
+
const apiEndpoint = 'https://some-endpoint.test';
|
|
30
|
+
let uut;
|
|
31
|
+
let config;
|
|
32
|
+
let storage;
|
|
33
|
+
let fetchMock;
|
|
34
|
+
|
|
35
|
+
function mockApi() {
|
|
36
|
+
const mock = async (url) => {
|
|
37
|
+
expect(url).to.eql(apiEndpoint);
|
|
38
|
+
mock.numRequests += 1;
|
|
39
|
+
return fetchMock.response();
|
|
40
|
+
};
|
|
41
|
+
mock.response = () => new Error('Not configured');
|
|
42
|
+
mock.numRequests = 0;
|
|
43
|
+
return mock;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function assumeApiReturns(ctry) {
|
|
47
|
+
fetchMock.response = async () => ({
|
|
48
|
+
ok: true,
|
|
49
|
+
async json() {
|
|
50
|
+
return {
|
|
51
|
+
location: ctry,
|
|
52
|
+
'location.city': '--',
|
|
53
|
+
ts: '20221108',
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function assumeApiIsDown() {
|
|
60
|
+
mockApi(async () => ({
|
|
61
|
+
ok: false,
|
|
62
|
+
statusText: 'Stub server has been configured to fail (this is expected).',
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function newCountryProvider() {
|
|
67
|
+
return new CountryProvider({
|
|
68
|
+
config,
|
|
69
|
+
storage,
|
|
70
|
+
storageKey,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Helper that simulate an event like a restart of the service worker/background script:
|
|
75
|
+
// it keeps the storage but purges everything that was in memory.
|
|
76
|
+
async function simulateRestart() {
|
|
77
|
+
uut = newCountryProvider();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function expectCountryToBe(expectedCountry) {
|
|
81
|
+
expect(uut.getSafeCountryCode({ skipUpdate: true })).to.eql(
|
|
82
|
+
expectedCountry,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
beforeEach(() => {
|
|
87
|
+
config = {
|
|
88
|
+
CONFIG_URL: apiEndpoint,
|
|
89
|
+
ALLOWED_COUNTRY_CODES: ['us', 'de', 'fr'],
|
|
90
|
+
};
|
|
91
|
+
storage = {
|
|
92
|
+
async get(key) {
|
|
93
|
+
expect(key).to.equal(storageKey);
|
|
94
|
+
return this._content;
|
|
95
|
+
},
|
|
96
|
+
async set(key, obj) {
|
|
97
|
+
expect(key).to.equal(storageKey);
|
|
98
|
+
this._content = obj;
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
fetchMock = mockApi();
|
|
102
|
+
sinon.stub(window, 'fetch').callsFake(fetchMock);
|
|
103
|
+
uut = newCountryProvider();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
afterEach(() => {
|
|
107
|
+
window.fetch.restore();
|
|
108
|
+
config = null;
|
|
109
|
+
storage = null;
|
|
110
|
+
fetchMock = null;
|
|
111
|
+
uut = null;
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
describe('on a fresh extension installation', function () {
|
|
115
|
+
it('should ask the API for the country', async function () {
|
|
116
|
+
assumeApiReturns('de');
|
|
117
|
+
expect(fetchMock.numRequests).to.eql(0);
|
|
118
|
+
await uut.init();
|
|
119
|
+
expect(fetchMock.numRequests).to.eql(1);
|
|
120
|
+
expectCountryToBe('de');
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it('should fallback to "--" if the API is down', async function () {
|
|
124
|
+
assumeApiIsDown();
|
|
125
|
+
await uut.init();
|
|
126
|
+
expect(fetchMock.numRequests).to.be.greaterThan(0);
|
|
127
|
+
expectCountryToBe('--');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should fallback to "--" if the country is not in the client allow-list', async function () {
|
|
131
|
+
expect(config.ALLOWED_COUNTRY_CODES).to.not.include('aq');
|
|
132
|
+
assumeApiReturns('aq');
|
|
133
|
+
await uut.init();
|
|
134
|
+
expectCountryToBe('--');
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
for (const invalidInput of [
|
|
138
|
+
'ÄÄ',
|
|
139
|
+
'',
|
|
140
|
+
'1234567890',
|
|
141
|
+
{},
|
|
142
|
+
'{}',
|
|
143
|
+
['foo', 'bar'],
|
|
144
|
+
]) {
|
|
145
|
+
const str = JSON.stringify(invalidInput);
|
|
146
|
+
|
|
147
|
+
describe(`when the API returns the invalid country=<<${str}>>`, function () {
|
|
148
|
+
it('should fallback to "--" if the API returns an unexpected country', async function () {
|
|
149
|
+
assumeApiReturns(invalidInput);
|
|
150
|
+
await uut.init();
|
|
151
|
+
expectCountryToBe('--');
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
describe('if the network is initially down', function () {
|
|
157
|
+
it('should be able to update successfully when the network is back', async function () {
|
|
158
|
+
assumeApiIsDown();
|
|
159
|
+
await uut.init();
|
|
160
|
+
expectCountryToBe('--');
|
|
161
|
+
|
|
162
|
+
let failed = false;
|
|
163
|
+
await uut.update({ force: true }).catch(() => (failed = true));
|
|
164
|
+
expect(failed).to.eql(true);
|
|
165
|
+
expectCountryToBe('--');
|
|
166
|
+
|
|
167
|
+
assumeApiReturns('de');
|
|
168
|
+
await uut.update({ force: true });
|
|
169
|
+
expectCountryToBe('de');
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('should later automatically update when network is back', async function () {
|
|
173
|
+
let now = Date.now();
|
|
174
|
+
assumeApiIsDown();
|
|
175
|
+
await uut.init({ now });
|
|
176
|
+
expectCountryToBe('--');
|
|
177
|
+
|
|
178
|
+
// try unsuccessfully for one hour
|
|
179
|
+
for (let i = 0; i < 60; i += 1) {
|
|
180
|
+
now += 1 * MINUTE;
|
|
181
|
+
expect(uut._pendingUpdate).to.not.exist;
|
|
182
|
+
expect(uut.getSafeCountryCode({ now })).to.eql('--');
|
|
183
|
+
if (uut._pendingUpdate) {
|
|
184
|
+
await uut._pendingUpdate.catch(() => {});
|
|
185
|
+
expect(uut._pendingUpdate).to.not.exist;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
expect(fetchMock.numRequests)
|
|
189
|
+
.to.be.greaterThan(3)
|
|
190
|
+
.and.to.be.lessThan(20);
|
|
191
|
+
|
|
192
|
+
// network is back
|
|
193
|
+
assumeApiReturns('de');
|
|
194
|
+
fetchMock.numRequests = 0;
|
|
195
|
+
|
|
196
|
+
// try for the rest of the day
|
|
197
|
+
for (let i = 0; i < 23 * 60; i += 1) {
|
|
198
|
+
now += 1 * MINUTE;
|
|
199
|
+
expect(uut._pendingUpdate).to.not.exist;
|
|
200
|
+
const ctry = uut.getSafeCountryCode({ now });
|
|
201
|
+
if (ctry === 'de') {
|
|
202
|
+
expect(fetchMock.numRequests).to.eql(1);
|
|
203
|
+
return; // PASSED
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
expect(ctry).to.eql('--');
|
|
207
|
+
if (uut._pendingUpdate) {
|
|
208
|
+
await uut._pendingUpdate.catch(() => {});
|
|
209
|
+
expect(uut._pendingUpdate).to.not.exist;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
expect.fail(
|
|
213
|
+
'Failed to update within one day, even though it would have worked after one hour',
|
|
214
|
+
);
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe('when restarting the extension', function () {
|
|
220
|
+
const oldValue = 'us';
|
|
221
|
+
const newValue = 'de';
|
|
222
|
+
let lastStart;
|
|
223
|
+
|
|
224
|
+
beforeEach(async () => {
|
|
225
|
+
assumeApiReturns(oldValue);
|
|
226
|
+
lastStart = Date.now();
|
|
227
|
+
|
|
228
|
+
expect(fetchMock.numRequests).to.eql(0);
|
|
229
|
+
await uut.init({ now: lastStart });
|
|
230
|
+
expect(fetchMock.numRequests).to.eql(1);
|
|
231
|
+
expectCountryToBe(oldValue);
|
|
232
|
+
|
|
233
|
+
fetchMock.numRequests = 0;
|
|
234
|
+
await simulateRestart();
|
|
235
|
+
assumeApiReturns(newValue);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('should not immediately fetch the country information', async function () {
|
|
239
|
+
expect(fetchMock.numRequests).to.eql(0);
|
|
240
|
+
expect(uut._pendingUpdate).to.not.exist;
|
|
241
|
+
await uut.init({ now: lastStart + 2 * SECOND });
|
|
242
|
+
|
|
243
|
+
expect(uut._pendingUpdate).to.not.exist;
|
|
244
|
+
expect(fetchMock.numRequests).to.eql(0);
|
|
245
|
+
expect(uut.getSafeCountryCode({ skipUpdate: true })).to.eql(oldValue);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('should trigger a background update if the country information is too old', async function () {
|
|
249
|
+
expect(fetchMock.numRequests).to.eql(0);
|
|
250
|
+
expect(uut._pendingUpdate).to.not.exist;
|
|
251
|
+
await uut.init({ now: lastStart + SKIP_ALL_COOLDOWNS });
|
|
252
|
+
|
|
253
|
+
// wait for the background update to finish
|
|
254
|
+
const pending = uut._pendingUpdate;
|
|
255
|
+
expect(pending).to.exist;
|
|
256
|
+
await pending;
|
|
257
|
+
|
|
258
|
+
expect(uut._pendingUpdate).to.not.exist;
|
|
259
|
+
expect(fetchMock.numRequests).to.eql(1);
|
|
260
|
+
expectCountryToBe(newValue);
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|