@whotracksme/reporting 5.1.25 → 5.1.27

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 (51) hide show
  1. package/.github/workflows/tests.yml +3 -1
  2. package/CHANGELOG.md +34 -0
  3. package/package.json +3 -2
  4. package/reporting/example/index.js +14 -3
  5. package/reporting/example/manifests/chromium.json +1 -2
  6. package/reporting/karma.conf.cjs +2 -0
  7. package/reporting/package.json +2 -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 +31 -70
  18. package/reporting/src/request/page-telemetry.js +4 -4
  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 +3 -7
  23. package/reporting/src/request/steps/redirect-tagger.js +1 -25
  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 +6 -0
  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/page-store.js +219 -150
  40. package/reporting/src/webrequest-pipeline/webrequest-context.js +1 -33
  41. package/reporting/test/helpers/fetch-mock.js +2 -2
  42. package/reporting/test/helpers/scenarios.js +104 -0
  43. package/reporting/test/pages.spec.js +52 -4
  44. package/reporting/test/request/index.spec.js +2 -9
  45. package/reporting/test/request-reporter.test.js +255 -0
  46. package/reporting/test/sanitizer.spec.js +16 -0
  47. package/reporting/test/utils/url.spec.js +1 -26
  48. package/reporting/test/webrequest-pipeline/index.test.js +101 -3
  49. package/reporting/test/webrequest-pipeline/page-store.test.js +36 -17
  50. package/reporting/src/request/dnt.js +0 -24
  51. package/reporting/src/webrequest-pipeline/page.js +0 -117
@@ -10,11 +10,10 @@
10
10
  */
11
11
 
12
12
  import chrome from 'sinon-chrome';
13
- import { mock } from 'sinon';
13
+ import { mock, match } from 'sinon';
14
14
  import { expect } from 'chai';
15
15
 
16
16
  import PageStore from '../../src/webrequest-pipeline/page-store.js';
17
- import { PAGE_LOADING_STATE } from '../../src/webrequest-pipeline/page.js';
18
17
 
19
18
  describe('PageStore', function () {
20
19
  before(function () {
@@ -25,6 +24,7 @@ describe('PageStore', function () {
25
24
  beforeEach(function () {
26
25
  chrome.flush();
27
26
  chrome.storage.session.get.yields({});
27
+ chrome.tabs.query.returns([]);
28
28
  });
29
29
 
30
30
  after(function () {
@@ -35,7 +35,7 @@ describe('PageStore', function () {
35
35
  it('starts with empty tabs', async function () {
36
36
  const store = new PageStore({});
37
37
  await store.init();
38
- expect(store.tabs.countNonExpiredKeys()).to.be.equal(0);
38
+ expect(store.checkIfEmpty()).to.be.true;
39
39
  });
40
40
 
41
41
  context('on chrome.tabs.onCreated', function () {
@@ -44,8 +44,10 @@ describe('PageStore', function () {
44
44
  await store.init();
45
45
  const tab = { id: 1 };
46
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({
47
+
48
+ expect(
49
+ store.getPageForRequest({ tabId: tab.id, frameId: 0 }),
50
+ ).to.deep.include({
49
51
  id: tab.id,
50
52
  });
51
53
  });
@@ -57,8 +59,9 @@ describe('PageStore', function () {
57
59
  await store.init();
58
60
  const tab = { id: 1 };
59
61
  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
+ expect(
63
+ store.getPageForRequest({ tabId: tab.id, frameId: 0 }),
64
+ ).to.deep.include({
62
65
  id: tab.id,
63
66
  });
64
67
  });
@@ -68,13 +71,18 @@ describe('PageStore', function () {
68
71
  await store.init();
69
72
  const tab = { id: 1 };
70
73
  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({
74
+ expect(
75
+ store.getPageForRequest({ tabId: tab.id, frameId: 0 }),
76
+ ).to.deep.include({
73
77
  id: tab.id,
74
78
  });
75
- expect(store.tabs.get(tab.id)).to.have.property('url', undefined);
79
+ expect(
80
+ store.getPageForRequest({ tabId: tab.id, frameId: 0 }),
81
+ ).to.have.property('url', undefined);
76
82
  chrome.tabs.onUpdated.dispatch(tab.id, { url: 'about:blank' }, tab);
77
- expect(store.tabs.get(tab.id)).to.have.property('url', 'about:blank');
83
+ expect(
84
+ store.getPageForRequest({ tabId: tab.id, frameId: 0 }),
85
+ ).to.have.property('url', 'about:blank');
78
86
  });
79
87
  });
80
88
 
@@ -84,8 +92,7 @@ describe('PageStore', function () {
84
92
  await store.init();
85
93
  const details = { tabId: 1, frameId: 0, url: 'about:blank' };
86
94
  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({
95
+ expect(store.getPageForRequest(details)).to.deep.include({
89
96
  id: details.tabId,
90
97
  url: details.url,
91
98
  });
@@ -103,13 +110,22 @@ describe('PageStore', function () {
103
110
  };
104
111
  chrome.webNavigation.onBeforeNavigate.dispatch(details);
105
112
  expect(listener).to.not.have.been.called;
106
- const page = store.tabs.get(details.tabId);
107
- page.state = PAGE_LOADING_STATE.COMPLETE;
113
+ const page = store.getPageForRequest(details);
114
+
115
+ // sets PAGE_LOADING_STATE.COMPLETE;
116
+ chrome.webNavigation.onCompleted.dispatch(details);
117
+
108
118
  chrome.webNavigation.onBeforeNavigate.dispatch({
109
119
  ...details,
110
120
  timeStamp: details.timeStamp + 300,
111
121
  });
112
- expect(listener).to.have.been.calledWith(page);
122
+ expect(listener).to.have.been.calledWith(
123
+ match({
124
+ id: page.id,
125
+ url: details.url,
126
+ created: details.timeStamp,
127
+ }),
128
+ );
113
129
  });
114
130
 
115
131
  it('ignore duplicates', async function () {
@@ -124,7 +140,10 @@ describe('PageStore', function () {
124
140
  };
125
141
  chrome.webNavigation.onBeforeNavigate.dispatch(details);
126
142
  expect(listener).to.not.have.been.called;
127
- store.tabs.get(details.tabId).state = PAGE_LOADING_STATE.COMPLETE;
143
+
144
+ // sets PAGE_LOADING_STATE.COMPLETE;
145
+ chrome.webNavigation.onCompleted.dispatch(details);
146
+
128
147
  chrome.webNavigation.onBeforeNavigate.dispatch({
129
148
  ...details,
130
149
  timeStamp: details.timeStamp + 1,
@@ -1,24 +0,0 @@
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
- * Extacts values from the DNT Tk header, given a list of response headers for a request
14
- * https://www.w3.org/TR/tracking-dnt/#dfn-tk
15
- * @param responseHeaders
16
- */
17
- export default function getTrackingStatus(state) {
18
- const status = state.getResponseHeader('tk');
19
- if (status) {
20
- const [value, statusId] = status.split(';');
21
- return { value, statusId };
22
- }
23
- return null;
24
- }
@@ -1,117 +0,0 @@
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
- export const PAGE_LOADING_STATE = {
13
- CREATED: 'created',
14
- NAVIGATING: 'navigating',
15
- COMMITTED: 'committed',
16
- COMPLETE: 'complete',
17
- };
18
-
19
- export function create({ id, active, url, incognito, created }) {
20
- const page = {};
21
- page.id = id || 0;
22
- page.url = url;
23
- page.isRedirect = false;
24
- page.isPrivate = incognito;
25
- page.isPrivateServer = false;
26
- page.created = created || Date.now();
27
- page.destroyed = null;
28
- page.lastRequestId = null;
29
- page.frames = {
30
- 0: {
31
- parentFrameId: -1,
32
- url,
33
- },
34
- };
35
- page.state = PAGE_LOADING_STATE.CREATED;
36
-
37
- page.activeTime = 0;
38
- page.activeFrom = active ? Date.now() : 0;
39
-
40
- page.requestStats = {};
41
- page.annotations = {};
42
- page.counter = 0;
43
-
44
- page.tsv = '';
45
- page.tsvId = undefined;
46
- return page;
47
- }
48
-
49
- export function setActive(page, active) {
50
- if (active && page.activeFrom === 0) {
51
- page.activeFrom = Date.now();
52
- } else if (!active && page.activeFrom > 0) {
53
- page.activeTime += Date.now() - page.activeFrom;
54
- page.activeFrom = 0;
55
- }
56
- }
57
-
58
- export function getStatsForDomain(page, domain) {
59
- let stats = page.requestStats[domain];
60
- if (!stats) {
61
- stats = {};
62
- page.requestStats[domain] = stats;
63
- }
64
- return stats;
65
- }
66
-
67
- export function getFrameAncestors(page, { parentFrameId }) {
68
- const ancestors = [];
69
-
70
- // Reconstruct frame ancestors
71
- let currentFrameId = parentFrameId;
72
- while (currentFrameId !== -1) {
73
- const frame = page.frames[currentFrameId];
74
-
75
- // If `frame` if undefined, this means we do not have any information
76
- // about the frame associated with `currentFrameId`. This can happen if
77
- // the event for `main_frame` or `sub_frame` was not emitted from the
78
- // webRequest API for this frame; this can happen when Service Workers
79
- // are used. In this case, we consider that the parent frame is the main
80
- // frame (which is very likely the case).
81
- if (frame === undefined) {
82
- ancestors.push({
83
- frameId: 0,
84
- url: page.url,
85
- });
86
- break;
87
- }
88
-
89
- // Continue going up the ancestors chain
90
- ancestors.push({
91
- frameId: currentFrameId,
92
- url: frame.url,
93
- });
94
- currentFrameId = frame.parentFrameId;
95
- }
96
-
97
- return ancestors;
98
- }
99
-
100
- /**
101
- * Return the URL of the frame.
102
- */
103
- export function getFrameUrl(page, context) {
104
- const { frameId } = context;
105
-
106
- const frame = page.frames[frameId];
107
-
108
- // In some cases, frame creation does not trigger a webRequest event (e.g.:
109
- // if the iframe is specified in the HTML of the page directly). In this
110
- // case we try to fall-back to something else: documentUrl, originUrl,
111
- // initiator.
112
- if (frame === undefined) {
113
- return context.documentUrl || context.originUrl || context.initiator;
114
- }
115
-
116
- return frame.url;
117
- }