@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,43 @@
|
|
|
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
|
+
/**
|
|
13
|
+
* Implements the IndexedDBKeyValueStore interface.
|
|
14
|
+
*/
|
|
15
|
+
export default class InMemoryDatabase {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.db = new Map();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async open() {}
|
|
21
|
+
|
|
22
|
+
async close() {}
|
|
23
|
+
|
|
24
|
+
async get(key) {
|
|
25
|
+
return this.db.get(key);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async set(key, value) {
|
|
29
|
+
this.db.set(key, value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async remove(key) {
|
|
33
|
+
return this.db.delete(key);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async clear() {
|
|
37
|
+
this.db.clear();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async keys() {
|
|
41
|
+
return [...this.db.keys()];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
import { Buffer } from 'buffer';
|
|
15
|
+
|
|
16
|
+
import InMemoryDatabase from './helpers/in-memory-database.js';
|
|
17
|
+
|
|
18
|
+
import ServerPublicKeyAccessor from '../src/server-public-key-accessor.js';
|
|
19
|
+
import logger from '../src/logger.js';
|
|
20
|
+
|
|
21
|
+
logger.disable();
|
|
22
|
+
|
|
23
|
+
async function mockedResponse({ body = '', error = false } = {}) {
|
|
24
|
+
return {
|
|
25
|
+
ok: !error,
|
|
26
|
+
statusText: error ? 500 : 200,
|
|
27
|
+
async json() {
|
|
28
|
+
return JSON.parse(body);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const MOCKS = {
|
|
34
|
+
reset() {
|
|
35
|
+
this.dates = ['20200101', '20200102', '20200103', '20200104'];
|
|
36
|
+
this.today = '20200102';
|
|
37
|
+
this.fakeKey =
|
|
38
|
+
'BARClm1SExH0+0gDAVZzuo0h13y433m5aiLcOdD0EZ5Gpvh1MNqQO86NncHM75pQiosg4629b2Pqst5VG6jAY6M=';
|
|
39
|
+
this.fakeImportedKey = 'faked-imported-key';
|
|
40
|
+
this.fetch = async () => {
|
|
41
|
+
this.fetch._numCalls += 1;
|
|
42
|
+
const pubKeys = {};
|
|
43
|
+
this.dates.forEach((d) => {
|
|
44
|
+
pubKeys[d] = this.fakeKey;
|
|
45
|
+
});
|
|
46
|
+
const body = JSON.stringify({ pubKeys });
|
|
47
|
+
return mockedResponse({ body });
|
|
48
|
+
};
|
|
49
|
+
this.fetch._numCalls = 0;
|
|
50
|
+
this.importKey = async () => this.fakeImportedKey;
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
describe('#ServerPublicKeyAccessor', function () {
|
|
55
|
+
let database;
|
|
56
|
+
let uut;
|
|
57
|
+
|
|
58
|
+
const assumeKeysOnDisk = async (storedKeys) => {
|
|
59
|
+
const entry = storedKeys.map(({ date, key }) => [
|
|
60
|
+
date,
|
|
61
|
+
Buffer.from(key, 'base64'),
|
|
62
|
+
]);
|
|
63
|
+
await database.set(uut.storageKey, entry);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
beforeEach(async function () {
|
|
67
|
+
database = new InMemoryDatabase();
|
|
68
|
+
const config = {
|
|
69
|
+
COLLECTOR_DIRECT_URL: '192.0.2.0', // TEST-NET-1 address
|
|
70
|
+
};
|
|
71
|
+
uut = new ServerPublicKeyAccessor({
|
|
72
|
+
config,
|
|
73
|
+
database,
|
|
74
|
+
});
|
|
75
|
+
MOCKS.reset();
|
|
76
|
+
sinon.stub(window, 'fetch').callsFake(MOCKS.fetch);
|
|
77
|
+
sinon.stub(crypto.subtle, 'importKey').callsFake(MOCKS.importKey);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
afterEach(function () {
|
|
81
|
+
window.fetch.restore();
|
|
82
|
+
crypto.subtle.importKey.restore();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should be able to retrieve a key and cache it (happy path)', async function () {
|
|
86
|
+
expect(await uut.getKey(MOCKS.today)).to.deep.equal({
|
|
87
|
+
date: MOCKS.today,
|
|
88
|
+
publicKey: MOCKS.fakeImportedKey,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should be able to retrieve a key and cache it (race during initialization)', async function () {
|
|
93
|
+
const results = await Promise.all([
|
|
94
|
+
uut.getKey(MOCKS.today),
|
|
95
|
+
uut.getKey(MOCKS.today),
|
|
96
|
+
Promise.resolve().then(() => uut.getKey(MOCKS.today)),
|
|
97
|
+
uut.getKey(MOCKS.today),
|
|
98
|
+
]);
|
|
99
|
+
|
|
100
|
+
for (const result of results) {
|
|
101
|
+
expect(result).to.deep.equal({
|
|
102
|
+
date: MOCKS.today,
|
|
103
|
+
publicKey: MOCKS.fakeImportedKey,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
expect(MOCKS.fetch._numCalls).to.equal(1);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('should persist loaded keys to disk', async function () {
|
|
110
|
+
await assumeKeysOnDisk([{ date: MOCKS.today, key: MOCKS.fakeKey }]);
|
|
111
|
+
expect(await uut.getKey(MOCKS.today)).to.deep.equal({
|
|
112
|
+
date: MOCKS.today,
|
|
113
|
+
publicKey: MOCKS.fakeImportedKey,
|
|
114
|
+
});
|
|
115
|
+
expect(MOCKS.fetch._numCalls).to.equal(0);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should fetch newer keys if the cached ones are outdated', async function () {
|
|
119
|
+
const oneYearAgo = (MOCKS.today - '00010000').toString();
|
|
120
|
+
await assumeKeysOnDisk([{ date: oneYearAgo, key: MOCKS.fakeKey }]);
|
|
121
|
+
expect(await uut.getKey(MOCKS.today)).to.deep.equal({
|
|
122
|
+
date: MOCKS.today,
|
|
123
|
+
publicKey: MOCKS.fakeImportedKey,
|
|
124
|
+
});
|
|
125
|
+
expect(MOCKS.fetch._numCalls).to.equal(1);
|
|
126
|
+
|
|
127
|
+
// also check that the new keys were properly cached
|
|
128
|
+
MOCKS.fetch._numCalls = 0;
|
|
129
|
+
expect(await uut.getKey(MOCKS.today)).to.deep.equal({
|
|
130
|
+
date: MOCKS.today,
|
|
131
|
+
publicKey: MOCKS.fakeImportedKey,
|
|
132
|
+
});
|
|
133
|
+
expect(MOCKS.fetch._numCalls).to.equal(0);
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
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 * as fc from 'fast-check';
|
|
13
|
+
import { expect } from 'chai';
|
|
14
|
+
import { sortObjectKeys } from '../src/utils.js';
|
|
15
|
+
|
|
16
|
+
describe('#sortObjectKeys', function () {
|
|
17
|
+
it('should ignore the creation order of keys', function () {
|
|
18
|
+
const obj1 = {
|
|
19
|
+
one: 'eins',
|
|
20
|
+
two: 'zwei',
|
|
21
|
+
three: 'drei',
|
|
22
|
+
};
|
|
23
|
+
const obj2 = {
|
|
24
|
+
two: 'zwei',
|
|
25
|
+
three: 'drei',
|
|
26
|
+
one: 'eins',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const obj1Json = JSON.stringify(sortObjectKeys(obj1));
|
|
30
|
+
const obj2Json = JSON.stringify(sortObjectKeys(obj2));
|
|
31
|
+
expect(obj1Json).to.eql(obj2Json);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should be idempotent', function () {
|
|
35
|
+
fc.assert(
|
|
36
|
+
fc.property(fc.object(), (obj) => {
|
|
37
|
+
const once = sortObjectKeys(obj);
|
|
38
|
+
const twice = sortObjectKeys(once);
|
|
39
|
+
expect(JSON.stringify(once)).to.eql(JSON.stringify(twice));
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@whotracksme/reporting",
|
|
3
|
+
"version": "5.1.17",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"lint": "eslint reporting/ communication/",
|
|
8
|
+
"lint.fix": "eslint --fix reporting/ communication/",
|
|
9
|
+
"test": "npm run lint && npm run test --workspaces --if-present",
|
|
10
|
+
"release": "auto shipit"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/whotracksme/webextension-packages.git"
|
|
18
|
+
},
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/whotracksme/webextension-packages/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/whotracksme/webextension-packages#readme",
|
|
23
|
+
"author": "Ghostery GmbH",
|
|
24
|
+
"license": "MPL-2.0",
|
|
25
|
+
"auto": {
|
|
26
|
+
"baseBranch": "main",
|
|
27
|
+
"plugins": [
|
|
28
|
+
"npm"
|
|
29
|
+
]
|
|
30
|
+
},
|
|
31
|
+
"workspaces": [
|
|
32
|
+
"reporting",
|
|
33
|
+
"communication"
|
|
34
|
+
],
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"auto": "^11.1.1",
|
|
37
|
+
"eslint": "^8.8.0",
|
|
38
|
+
"eslint-config-prettier": "^8.3.0",
|
|
39
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
40
|
+
"prettier": "2.5.1"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@cliqz/url-parser": "^1.1.5",
|
|
44
|
+
"date-fns": "^2.29.3",
|
|
45
|
+
"idb": "^7.1.1",
|
|
46
|
+
"linkedom": "^0.16.11",
|
|
47
|
+
"pako": "^2.1.0",
|
|
48
|
+
"tldts-experimental": "^6.0.11"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":"2020-12-14","useDiff":false}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { recordMouseDown } from '../src/request/content-script.js';
|
|
2
|
+
|
|
3
|
+
window.addEventListener('mousedown', (ev) => {
|
|
4
|
+
const { event, context, href } = recordMouseDown(ev);
|
|
5
|
+
chrome.runtime.sendMessage({
|
|
6
|
+
action: 'mousedown',
|
|
7
|
+
event,
|
|
8
|
+
context,
|
|
9
|
+
href,
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
import './setup.js';
|
|
12
|
+
import {
|
|
13
|
+
UrlReporter,
|
|
14
|
+
RequestReporter,
|
|
15
|
+
WebRequestPipeline,
|
|
16
|
+
setLogLevel,
|
|
17
|
+
} from '../src/index.js';
|
|
18
|
+
import rules from './rules.json';
|
|
19
|
+
|
|
20
|
+
(chrome.action || chrome.browserAction).onClicked.addListener(() => {
|
|
21
|
+
chrome.tabs.create({
|
|
22
|
+
active: true,
|
|
23
|
+
url: chrome.runtime.getURL('inspector/index.html'),
|
|
24
|
+
});
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
setLogLevel('debug');
|
|
28
|
+
|
|
29
|
+
function createStorage() {
|
|
30
|
+
const storage = {
|
|
31
|
+
storage: {},
|
|
32
|
+
async get(key) {
|
|
33
|
+
return this.storage[key];
|
|
34
|
+
},
|
|
35
|
+
async set(key, value) {
|
|
36
|
+
this.storage[key] = value;
|
|
37
|
+
},
|
|
38
|
+
async remove(key) {
|
|
39
|
+
delete this.storage[key];
|
|
40
|
+
},
|
|
41
|
+
async clear() {
|
|
42
|
+
this.storage = {};
|
|
43
|
+
},
|
|
44
|
+
async keys() {
|
|
45
|
+
return Object.keys(this.storage);
|
|
46
|
+
},
|
|
47
|
+
open() {},
|
|
48
|
+
close() {},
|
|
49
|
+
};
|
|
50
|
+
return storage;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const communication = {
|
|
54
|
+
send(msg) {
|
|
55
|
+
console.warn('[Communication]', msg);
|
|
56
|
+
},
|
|
57
|
+
// TODO: use actuall anonymous-communication to access quorum
|
|
58
|
+
sendInstant(msg) {
|
|
59
|
+
console.warn('[Communication instant]', msg);
|
|
60
|
+
return Promise.resolve({
|
|
61
|
+
ok: true,
|
|
62
|
+
json: () => Promise.resolve({ result: true }),
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
trustedClock: {
|
|
66
|
+
getTimeAsYYYYMMDD() {
|
|
67
|
+
return '';
|
|
68
|
+
},
|
|
69
|
+
getTimeAsYYYYMMDDHH() {
|
|
70
|
+
return '';
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const config = {
|
|
76
|
+
url: {
|
|
77
|
+
ALLOWED_COUNTRY_CODES: ['de'],
|
|
78
|
+
PATTERNS_URL: '',
|
|
79
|
+
CONFIG_URL: 'https://api.ghostery.net/api/v1/config',
|
|
80
|
+
},
|
|
81
|
+
request: {
|
|
82
|
+
configUrl: 'https://cdn.ghostery.com/antitracking/config.json',
|
|
83
|
+
remoteWhitelistUrl: 'https://cdn.ghostery.com/antitracking/whitelist/2',
|
|
84
|
+
localWhitelistUrl: '/base/assets/request',
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const webRequestPipeline = new WebRequestPipeline();
|
|
89
|
+
|
|
90
|
+
const urlReporter = new UrlReporter({
|
|
91
|
+
config: config.url,
|
|
92
|
+
storage: createStorage(),
|
|
93
|
+
connectDatabase: createStorage,
|
|
94
|
+
communication,
|
|
95
|
+
browserInfoProvider: async () => ({ browser: 'test' }),
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const requestReporter = new RequestReporter(config.request, {
|
|
99
|
+
communication,
|
|
100
|
+
webRequestPipeline,
|
|
101
|
+
countryProvider: urlReporter.countryProvider,
|
|
102
|
+
trustedClock: communication.trustedClock,
|
|
103
|
+
getBrowserInfo: () => ({ name: 'xx' }),
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
107
|
+
if (request.action === 'mousedown') {
|
|
108
|
+
requestReporter.recordClick(
|
|
109
|
+
request.event,
|
|
110
|
+
request.context,
|
|
111
|
+
request.href,
|
|
112
|
+
sender,
|
|
113
|
+
);
|
|
114
|
+
} else if (request.action === 'debug') {
|
|
115
|
+
sendResponse({
|
|
116
|
+
tabs: [...webRequestPipeline.pageStore.tabs._inMemoryMap.values()],
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
(async function () {
|
|
122
|
+
await webRequestPipeline.init();
|
|
123
|
+
await urlReporter.init();
|
|
124
|
+
await urlReporter.patterns.updatePatterns(rules);
|
|
125
|
+
await urlReporter.analyzeUrl('https://www.google.com/search?q=shoes');
|
|
126
|
+
await urlReporter.processPendingJobs();
|
|
127
|
+
await requestReporter.init();
|
|
128
|
+
})();
|
|
129
|
+
|
|
130
|
+
globalThis.webRequestPipeline = webRequestPipeline;
|
|
131
|
+
globalThis.urlReporter = urlReporter;
|
|
132
|
+
globalThis.requestReporter = requestReporter;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>wtm/reporting inspector</title>
|
|
6
|
+
<script type="module" src="./index.js"></script>
|
|
7
|
+
</head>
|
|
8
|
+
<body>
|
|
9
|
+
<h1>WTM Reporting Inspector</h1>
|
|
10
|
+
<label for="filter">Filter:</label><input id="filter" type="text"/>
|
|
11
|
+
<section>
|
|
12
|
+
<h2>Page Store</h2>
|
|
13
|
+
<pre id="page-store"></pre>
|
|
14
|
+
</section>
|
|
15
|
+
|
|
16
|
+
</body>
|
|
17
|
+
</html>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const browser = globalThis.browser || globalThis.chrome;
|
|
2
|
+
const $container = document.querySelector('#page-store');
|
|
3
|
+
const $filter = document.querySelector('#filter');
|
|
4
|
+
|
|
5
|
+
$filter.value = localStorage.filter || '';
|
|
6
|
+
$filter.addEventListener('input', () => {
|
|
7
|
+
localStorage.filter = $filter.value;
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
async function render() {
|
|
11
|
+
let { tabs } = await browser.runtime.sendMessage({ action: 'debug' });
|
|
12
|
+
|
|
13
|
+
if (localStorage.filter) {
|
|
14
|
+
const matchById = tabs.find(
|
|
15
|
+
(tab) => tab.id === Number(localStorage.filter),
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
tabs = matchById
|
|
19
|
+
? [matchById]
|
|
20
|
+
: tabs.filter((tab) => tab.url.includes(localStorage.filter));
|
|
21
|
+
}
|
|
22
|
+
$container.innerHTML = JSON.stringify(tabs, null, 2);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
await render();
|
|
26
|
+
|
|
27
|
+
setInterval(render, 500);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifest_version": 3,
|
|
3
|
+
"author": "Ghostery",
|
|
4
|
+
"name": "WhoTracks.Me Reporting",
|
|
5
|
+
"short_name": "communication",
|
|
6
|
+
"version": "1.0.0",
|
|
7
|
+
"version_name": "1.0.0",
|
|
8
|
+
"description": "",
|
|
9
|
+
"permissions": [
|
|
10
|
+
"webNavigation",
|
|
11
|
+
"webRequest",
|
|
12
|
+
"tabs",
|
|
13
|
+
"storage",
|
|
14
|
+
"scripting",
|
|
15
|
+
"windows"
|
|
16
|
+
],
|
|
17
|
+
"action": {
|
|
18
|
+
"default_title": "WTM/Reporting Inspector"
|
|
19
|
+
},
|
|
20
|
+
"background": {
|
|
21
|
+
"service_worker": "index.bundle.js",
|
|
22
|
+
"type": "module"
|
|
23
|
+
},
|
|
24
|
+
"content_scripts": [
|
|
25
|
+
{
|
|
26
|
+
"matches": ["http://*/*", "https://*/*"],
|
|
27
|
+
"js": ["content.bundle.js"],
|
|
28
|
+
"all_frames": true
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"host_permissions": [
|
|
32
|
+
"https://collector-hpn.ghostery.net/*",
|
|
33
|
+
"http://localhost:3001/*",
|
|
34
|
+
"http://*/*",
|
|
35
|
+
"https://*/*"
|
|
36
|
+
]
|
|
37
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"manifest_version": 2,
|
|
3
|
+
"author": "Ghostery",
|
|
4
|
+
"name": "WhoTracks.Me Reporting",
|
|
5
|
+
"short_name": "communication",
|
|
6
|
+
"version": "1.0.0",
|
|
7
|
+
"description": "",
|
|
8
|
+
"permissions": [
|
|
9
|
+
"webNavigation",
|
|
10
|
+
"webRequest",
|
|
11
|
+
"webRequestBlocking",
|
|
12
|
+
"tabs",
|
|
13
|
+
"storage",
|
|
14
|
+
"scripting",
|
|
15
|
+
"http://*/*",
|
|
16
|
+
"https://*/*",
|
|
17
|
+
"ws://*/*",
|
|
18
|
+
"wss://*/*"
|
|
19
|
+
],
|
|
20
|
+
"browser_action": {
|
|
21
|
+
"default_title": "WTM/Reporting Inspector",
|
|
22
|
+
"default_area": "navbar"
|
|
23
|
+
},
|
|
24
|
+
"content_scripts": [
|
|
25
|
+
{
|
|
26
|
+
"matches": ["http://*/*", "https://*/*"],
|
|
27
|
+
"js": ["content.bundle.js"],
|
|
28
|
+
"all_frames": true
|
|
29
|
+
}
|
|
30
|
+
],
|
|
31
|
+
"background": {
|
|
32
|
+
"scripts": ["index.bundle.js"],
|
|
33
|
+
"persistent": false
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"search-go": {
|
|
3
|
+
"doublefetch": {
|
|
4
|
+
"headers": {
|
|
5
|
+
"Cookie": "CONSENT=YES+cb-m.20220301-1-p0.de+FX+1;"
|
|
6
|
+
},
|
|
7
|
+
"followRedirects": true
|
|
8
|
+
},
|
|
9
|
+
"input": {
|
|
10
|
+
"#main div[data-text-ad=\"1\"]": {
|
|
11
|
+
"all": {
|
|
12
|
+
"u": {
|
|
13
|
+
"select": "a div[role=\"link\"]",
|
|
14
|
+
"attr": "aria-label"
|
|
15
|
+
},
|
|
16
|
+
"t": {
|
|
17
|
+
"select": "a div[role=\"heading\"] > span",
|
|
18
|
+
"attr": "textContent"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"output": {
|
|
24
|
+
"hwlite.query0": {
|
|
25
|
+
"fields": [
|
|
26
|
+
{
|
|
27
|
+
"key": "q"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"key": "qurl"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"key": "ctry"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"deduplicateBy": "q"
|
|
37
|
+
},
|
|
38
|
+
"hwlite.ads_A": {
|
|
39
|
+
"fields": [
|
|
40
|
+
{
|
|
41
|
+
"key": "r",
|
|
42
|
+
"source": "#main div[data-text-ad=\"1\"]",
|
|
43
|
+
"requiredKeys": [
|
|
44
|
+
"t",
|
|
45
|
+
"u"
|
|
46
|
+
]
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"key": "q"
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
"key": "qurl"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"key": "ctry"
|
|
56
|
+
}
|
|
57
|
+
],
|
|
58
|
+
"deduplicateBy": "q"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
globalThis.chrome = browser || chrome;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const rollupPreprocessor = require('./rollup.common-config.cjs');
|
|
2
|
+
|
|
3
|
+
module.exports = function (config) {
|
|
4
|
+
config.set({
|
|
5
|
+
frameworks: ['mocha', 'chai', 'sinon'],
|
|
6
|
+
files: [{ pattern: 'test/index.js', watched: false }],
|
|
7
|
+
preprocessors: {
|
|
8
|
+
'test/index.js': ['rollup'],
|
|
9
|
+
},
|
|
10
|
+
reporters: ['mocha'],
|
|
11
|
+
port: 9876,
|
|
12
|
+
colors: true,
|
|
13
|
+
logLevel: config.LOG_INFO,
|
|
14
|
+
autoWatch: false,
|
|
15
|
+
concurrency: 0,
|
|
16
|
+
rollupPreprocessor,
|
|
17
|
+
client: {
|
|
18
|
+
TEST_FIXTURES_URL: process.env.TEST_FIXTURES_URL, // for test/search-extractor.spec.js
|
|
19
|
+
REPLAY_FIXTURES_URL: process.env.REPLAY_FIXTURES_URL, // for test/pages.spec.js
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
};
|