@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
@@ -9,7 +9,7 @@
9
9
  * file, You can obtain one at http://mozilla.org/MPL/2.0
10
10
  */
11
11
 
12
- import TempSet from '../utils/temp-set';
12
+ import TempSet from '../utils/temp-set.js';
13
13
 
14
14
  const CACHE_TIMEOUT = 10 * 1000;
15
15
 
@@ -20,7 +20,6 @@ const CACHE_TIMEOUT = 10 * 1000;
20
20
  export default class RedirectTagger {
21
21
  constructor() {
22
22
  this.redirectCache = new TempSet();
23
- this.redirectTaggerCache = new TempSet();
24
23
  }
25
24
 
26
25
  isFromRedirect(url) {
@@ -49,27 +48,4 @@ export default class RedirectTagger {
49
48
  }
50
49
  return true;
51
50
  }
52
-
53
- checkRedirect(details) {
54
- if (details.isRedirect && details.requestId !== undefined) {
55
- this.redirectTaggerCache.add(details.requestId, CACHE_TIMEOUT);
56
- return false;
57
- }
58
- return true;
59
- }
60
-
61
- confirmRedirect(details) {
62
- if (
63
- details.requestId !== undefined &&
64
- this.redirectTaggerCache.has(details.requestId)
65
- ) {
66
- return false;
67
- }
68
-
69
- if (details.isMainFrame && details.isRedirect) {
70
- return false;
71
- }
72
-
73
- return true;
74
- }
75
51
  }
@@ -11,9 +11,9 @@
11
11
 
12
12
  /* eslint no-param-reassign: 'off' */
13
13
 
14
- import md5, { truncatedHash } from '../../../md5';
15
- import { tryDecodeURIComponent } from '../../../utils/url';
16
- import TokenDomain from './token-domain';
14
+ import md5, { truncatedHash } from '../../../md5.js';
15
+ import { tryDecodeURIComponent } from '../../../utils/url.js';
16
+ import TokenDomain from './token-domain.js';
17
17
 
18
18
  function decodeToken(token) {
19
19
  let decodedToken = tryDecodeURIComponent(token);
@@ -9,9 +9,9 @@
9
9
  * file, You can obtain one at http://mozilla.org/MPL/2.0
10
10
  */
11
11
 
12
- import * as datetime from '../../time';
13
- import logger from '../../../logger';
14
- import ChromeStorageMap from '../../utils/chrome-storage-map';
12
+ import * as datetime from '../../time.js';
13
+ import logger from '../../../logger.js';
14
+ import ChromeStorageMap from '../../utils/chrome-storage-map.js';
15
15
 
16
16
  const DAYS_EXPIRE = 7;
17
17
  const STAGED_TOKEN_EXPIRY = 1000 * 60 * 60 * 24 * 2; // 2 days
@@ -11,11 +11,11 @@
11
11
 
12
12
  /* eslint no-param-reassign: 'off' */
13
13
 
14
- import * as datetime from '../time';
15
- import md5, { truncatedHash } from '../../md5';
16
- import pacemaker from '../../utils/pacemaker';
17
- import ChromeStorageMap from '../utils/chrome-storage-map';
18
- import logger from '../../logger';
14
+ import * as datetime from '../time.js';
15
+ import md5, { truncatedHash } from '../../md5.js';
16
+ import pacemaker from '../../utils/pacemaker.js';
17
+ import ChromeStorageMap from '../utils/chrome-storage-map.js';
18
+ import logger from '../../logger.js';
19
19
 
20
20
  const SYNC_DB_INTERVAL = 20 * 1000;
21
21
 
@@ -9,9 +9,9 @@
9
9
  * file, You can obtain one at http://mozilla.org/MPL/2.0
10
10
  */
11
11
 
12
- import logger from '../../../logger';
13
- import Subject from '../../utils/subject';
14
- import ChromeStorageMap from '../../utils/chrome-storage-map';
12
+ import logger from '../../../logger.js';
13
+ import Subject from '../../utils/subject.js';
14
+ import ChromeStorageMap from '../../utils/chrome-storage-map.js';
15
15
 
16
16
  const CACHE_TTL = 2 * 24 * 60 * 60 * 1000; // 2 days
17
17
 
@@ -9,10 +9,10 @@
9
9
  * file, You can obtain one at http://mozilla.org/MPL/2.0
10
10
  */
11
11
 
12
- import md5, { truncatedHash } from '../../../md5';
13
- import Subject from '../../utils/subject';
14
- import KeyPipeline, { getSiteTokensMap } from './key-pipeline';
15
- import TokenPipeline from './token-pipeline';
12
+ import md5, { truncatedHash } from '../../../md5.js';
13
+ import Subject from '../../utils/subject.js';
14
+ import KeyPipeline, { getSiteTokensMap } from './key-pipeline.js';
15
+ import TokenPipeline from './token-pipeline.js';
16
16
 
17
17
  const DEFAULT_CONFIG = {
18
18
  // token batchs, max 720 messages/hour
@@ -9,7 +9,7 @@
9
9
  * file, You can obtain one at http://mozilla.org/MPL/2.0
10
10
  */
11
11
 
12
- import CachedEntryPipeline from './cached-entry-pipeline';
12
+ import CachedEntryPipeline from './cached-entry-pipeline.js';
13
13
 
14
14
  export function getSiteTokensMap(siteTokens, key) {
15
15
  let siteTokensMap = siteTokens[key];
@@ -9,7 +9,7 @@
9
9
  * file, You can obtain one at http://mozilla.org/MPL/2.0
10
10
  */
11
11
 
12
- import CachedEntryPipeline from './cached-entry-pipeline';
12
+ import CachedEntryPipeline from './cached-entry-pipeline.js';
13
13
 
14
14
  export default class TokenPipeline extends CachedEntryPipeline {
15
15
  constructor({ db, trustedClock, options, name }) {
@@ -10,7 +10,7 @@
10
10
  */
11
11
 
12
12
  /* eslint no-bitwise: 'off' */
13
- import md5 from '../../md5';
13
+ import md5 from '../../md5.js';
14
14
 
15
15
  /**
16
16
  * Re-implementation of core/bloom-filter using a packed ArrayBuffer to hold
@@ -109,6 +109,12 @@ export default class ChromeStorageMap {
109
109
  return this._inMemoryMap.entries();
110
110
  }
111
111
 
112
+ keys() {
113
+ this._warnIfOutOfSync();
114
+ this._expireOldEntries();
115
+ return this._inMemoryMap.keys();
116
+ }
117
+
112
118
  values() {
113
119
  this._warnIfOutOfSync();
114
120
  this._expireOldEntries();
@@ -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
  export default class Subject {
15
15
  constructor() {
@@ -12,7 +12,7 @@
12
12
  /* eslint func-names: 'off' */
13
13
  /* eslint prefer-arrow-callback: 'off' */
14
14
 
15
- import pacemaker from '../../utils/pacemaker';
15
+ import pacemaker from '../../utils/pacemaker.js';
16
16
 
17
17
  /** Set like class whose members are removed after a specific amount of time
18
18
  */
@@ -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 checkForInternalIp(hostname) {
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 (checkForInternalIp(parsedUrl.hostname)) {
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;