@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.
Files changed (55) hide show
  1. package/.github/workflows/release.yml +2 -2
  2. package/.github/workflows/tests.yml +4 -5
  3. package/.tool-versions +1 -1
  4. package/CHANGELOG.md +32 -0
  5. package/package.json +3 -2
  6. package/reporting/karma.conf.cjs +2 -0
  7. package/reporting/package.json +4 -1
  8. package/reporting/src/bloom-filters.js +4 -4
  9. package/reporting/src/fixed-size-cache.js +1 -1
  10. package/reporting/src/logger.js +0 -1
  11. package/reporting/src/md5.js +1 -1
  12. package/reporting/src/network.js +1 -1
  13. package/reporting/src/pages.js +84 -21
  14. package/reporting/src/persisted-bitarray.js +2 -2
  15. package/reporting/src/request/config.js +2 -2
  16. package/reporting/src/request/hash.js +2 -2
  17. package/reporting/src/request/index.js +30 -29
  18. package/reporting/src/request/page-telemetry.js +2 -2
  19. package/reporting/src/request/qs-whitelist2.js +3 -3
  20. package/reporting/src/request/steps/cookie-context.js +6 -6
  21. package/reporting/src/request/steps/oauth-detector.js +3 -3
  22. package/reporting/src/request/steps/page-logger.js +5 -2
  23. package/reporting/src/request/steps/redirect-tagger.js +1 -1
  24. package/reporting/src/request/steps/token-checker/index.js +3 -3
  25. package/reporting/src/request/steps/token-checker/token-domain.js +3 -3
  26. package/reporting/src/request/steps/token-examiner.js +5 -5
  27. package/reporting/src/request/steps/token-telemetry/cached-entry-pipeline.js +3 -3
  28. package/reporting/src/request/steps/token-telemetry/index.js +4 -4
  29. package/reporting/src/request/steps/token-telemetry/key-pipeline.js +1 -1
  30. package/reporting/src/request/steps/token-telemetry/token-pipeline.js +1 -1
  31. package/reporting/src/request/utils/bloom-filter-packed.js +1 -1
  32. package/reporting/src/request/utils/chrome-storage-map.js +13 -1
  33. package/reporting/src/request/utils/subject.js +1 -1
  34. package/reporting/src/request/utils/temp-set.js +1 -1
  35. package/reporting/src/request-reporter.js +3 -3
  36. package/reporting/src/sanitizer.js +11 -3
  37. package/reporting/src/utils/pacemaker.js +1 -1
  38. package/reporting/src/utils/url.js +0 -29
  39. package/reporting/src/webrequest-pipeline/cname-uncloak.js +2 -2
  40. package/reporting/src/webrequest-pipeline/index.js +10 -11
  41. package/reporting/src/webrequest-pipeline/logger.js +1 -1
  42. package/reporting/src/webrequest-pipeline/page-store.js +23 -20
  43. package/reporting/src/webrequest-pipeline/page.js +81 -104
  44. package/reporting/src/webrequest-pipeline/pipeline.js +1 -1
  45. package/reporting/src/webrequest-pipeline/utils/webrequest.js +63 -57
  46. package/reporting/src/webrequest-pipeline/webrequest-context.js +6 -5
  47. package/reporting/test/helpers/fetch-mock.js +2 -2
  48. package/reporting/test/helpers/scenarios.js +85 -0
  49. package/reporting/test/pages.spec.js +52 -4
  50. package/reporting/test/request-reporter.test.js +251 -0
  51. package/reporting/test/sanitizer.spec.js +16 -0
  52. package/reporting/test/setup.unit.js +17 -0
  53. package/reporting/test/utils/url.spec.js +1 -26
  54. package/reporting/test/webrequest-pipeline/index.test.js +147 -0
  55. package/reporting/test/webrequest-pipeline/page-store.test.js +135 -0
@@ -11,7 +11,7 @@
11
11
 
12
12
  import * as chai from 'chai';
13
13
 
14
- import { isPrivateIP, getName, parse } from '../../src/utils/url';
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);
@@ -0,0 +1,147 @@
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 chrome from 'sinon-chrome';
13
+ import { expect } from 'chai';
14
+
15
+ import { playScenario } from '../helpers/scenarios.js';
16
+
17
+ import WebRequestPipeline from '../../src/webrequest-pipeline/index.js';
18
+
19
+ describe('WebRequestPipeline', function () {
20
+ before(function () {
21
+ chrome.storage.session = chrome.storage.local;
22
+ globalThis.chrome = chrome;
23
+ });
24
+
25
+ beforeEach(function () {
26
+ chrome.flush();
27
+ chrome.storage.session.get.yields({});
28
+ });
29
+
30
+ after(function () {
31
+ chrome.flush();
32
+ delete globalThis.chrome;
33
+ });
34
+
35
+ context('PageStore', function () {
36
+ it('starts empty', function () {
37
+ const pipeline = new WebRequestPipeline();
38
+ pipeline.init();
39
+ expect(pipeline.pageStore.tabs.countNonExpiredKeys()).to.be.equal(0);
40
+ });
41
+
42
+ context('on webRequest.onBeforeRequest', function () {
43
+ it('creates a page', function () {
44
+ const pipeline = new WebRequestPipeline();
45
+ pipeline.init();
46
+ pipeline.addPipelineStep('onBeforeRequest', {
47
+ name: 'test',
48
+ spec: 'annotate',
49
+ fn: () => {},
50
+ });
51
+ const details = {
52
+ tabId: 1,
53
+ url: 'https://example.com',
54
+ type: 'main_frame',
55
+ };
56
+ chrome.webRequest.onBeforeRequest.dispatch(details);
57
+ expect(pipeline.pageStore.tabs.has(details.tabId)).to.be.true;
58
+ expect(pipeline.pageStore.tabs.get(details.tabId)).to.deep.include({
59
+ url: details.url,
60
+ });
61
+ });
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
+ });
146
+ });
147
+ });
@@ -0,0 +1,135 @@
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 chrome from 'sinon-chrome';
13
+ import { mock } from 'sinon';
14
+ import { expect } from 'chai';
15
+
16
+ import PageStore from '../../src/webrequest-pipeline/page-store.js';
17
+ import { PAGE_LOADING_STATE } from '../../src/webrequest-pipeline/page.js';
18
+
19
+ describe('PageStore', function () {
20
+ before(function () {
21
+ chrome.storage.session = chrome.storage.local;
22
+ globalThis.chrome = chrome;
23
+ });
24
+
25
+ beforeEach(function () {
26
+ chrome.flush();
27
+ chrome.storage.session.get.yields({});
28
+ });
29
+
30
+ after(function () {
31
+ chrome.flush();
32
+ delete globalThis.chrome;
33
+ });
34
+
35
+ it('starts with empty tabs', async function () {
36
+ const store = new PageStore({});
37
+ await store.init();
38
+ expect(store.tabs.countNonExpiredKeys()).to.be.equal(0);
39
+ });
40
+
41
+ context('on chrome.tabs.onCreated', function () {
42
+ it('creates a page', async function () {
43
+ const store = new PageStore({});
44
+ await store.init();
45
+ const tab = { id: 1 };
46
+ chrome.tabs.onCreated.dispatch(tab);
47
+ expect(store.tabs.has(tab.id)).to.be.true;
48
+ expect(store.tabs.get(tab.id)).to.deep.include({
49
+ id: tab.id,
50
+ });
51
+ });
52
+ });
53
+
54
+ context('on chrome.tabs.onUpdated', function () {
55
+ it('creates a page', async function () {
56
+ const store = new PageStore({});
57
+ await store.init();
58
+ const tab = { id: 1 };
59
+ chrome.tabs.onUpdated.dispatch(tab.id, {}, tab);
60
+ expect(store.tabs.has(tab.id)).to.be.true;
61
+ expect(store.tabs.get(tab.id)).to.deep.include({
62
+ id: tab.id,
63
+ });
64
+ });
65
+
66
+ it('updates a page', async function () {
67
+ const store = new PageStore({});
68
+ await store.init();
69
+ const tab = { id: 1 };
70
+ chrome.tabs.onCreated.dispatch(tab);
71
+ expect(store.tabs.has(tab.id)).to.be.true;
72
+ expect(store.tabs.get(tab.id)).to.deep.include({
73
+ id: tab.id,
74
+ });
75
+ expect(store.tabs.get(tab.id)).to.have.property('url', undefined);
76
+ chrome.tabs.onUpdated.dispatch(tab.id, { url: 'about:blank' }, tab);
77
+ expect(store.tabs.get(tab.id)).to.have.property('url', 'about:blank');
78
+ });
79
+ });
80
+
81
+ context('on chrome.webNavigation.onBeforeNavigate', function () {
82
+ it('creates a page', async function () {
83
+ const store = new PageStore({});
84
+ await store.init();
85
+ const details = { tabId: 1, frameId: 0, url: 'about:blank' };
86
+ chrome.webNavigation.onBeforeNavigate.dispatch(details);
87
+ expect(store.tabs.has(details.tabId)).to.be.true;
88
+ expect(store.tabs.get(details.tabId)).to.deep.include({
89
+ id: details.tabId,
90
+ url: details.url,
91
+ });
92
+ });
93
+
94
+ it('stages the page', async function () {
95
+ const listener = mock();
96
+ const store = new PageStore({ notifyPageStageListeners: listener });
97
+ await store.init();
98
+ const details = {
99
+ tabId: 1,
100
+ frameId: 0,
101
+ url: 'about:blank',
102
+ timeStamp: Date.now(),
103
+ };
104
+ chrome.webNavigation.onBeforeNavigate.dispatch(details);
105
+ expect(listener).to.not.have.been.called;
106
+ const page = store.tabs.get(details.tabId);
107
+ page.state = PAGE_LOADING_STATE.COMPLETE;
108
+ chrome.webNavigation.onBeforeNavigate.dispatch({
109
+ ...details,
110
+ timeStamp: details.timeStamp + 300,
111
+ });
112
+ expect(listener).to.have.been.calledWith(page);
113
+ });
114
+
115
+ it('ignore duplicates', async function () {
116
+ const listener = mock();
117
+ const store = new PageStore({ notifyPageStageListeners: listener });
118
+ await store.init();
119
+ const details = {
120
+ tabId: 1,
121
+ frameId: 0,
122
+ url: 'about:blank',
123
+ timeStamp: Date.now(),
124
+ };
125
+ chrome.webNavigation.onBeforeNavigate.dispatch(details);
126
+ expect(listener).to.not.have.been.called;
127
+ store.tabs.get(details.tabId).state = PAGE_LOADING_STATE.COMPLETE;
128
+ chrome.webNavigation.onBeforeNavigate.dispatch({
129
+ ...details,
130
+ timeStamp: details.timeStamp + 1,
131
+ });
132
+ expect(listener).to.not.have.been.called;
133
+ });
134
+ });
135
+ });