@whotracksme/reporting 11.1.1 → 12.1.0

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 (40) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/package.json +1 -1
  3. package/reporting/README.md +13 -0
  4. package/reporting/example/README.md +4 -0
  5. package/reporting/example/e2e/README.md +265 -0
  6. package/reporting/example/e2e/console-capture.js +67 -0
  7. package/reporting/example/e2e/control.js +449 -0
  8. package/reporting/example/e2e/hub.mjs +380 -0
  9. package/reporting/example/e2e/launch.mjs +92 -0
  10. package/reporting/example/e2e/mock-extension.mjs +106 -0
  11. package/reporting/example/e2e/pages/private-fixture.html +16 -0
  12. package/reporting/example/e2e/run.mjs +226 -0
  13. package/reporting/example/e2e/scenarios/privacy-guards.json +26 -0
  14. package/reporting/example/e2e/scenarios/smoke.json +15 -0
  15. package/reporting/example/e2e/verify.mjs +159 -0
  16. package/reporting/example/index.js +55 -46
  17. package/reporting/example/manifests/chromium.json +1 -0
  18. package/reporting/example/storage.js +65 -0
  19. package/reporting/package.json +5 -1
  20. package/reporting/rollup.config.cjs +1 -1
  21. package/reporting/snapshots/0001/snapshot.json +13 -13
  22. package/reporting/snapshots/0003/snapshot.json +5 -5
  23. package/reporting/snapshots/0005/snapshot.json +13 -13
  24. package/reporting/src/doublefetch-page-handler.js +30 -20
  25. package/reporting/src/doublefetch-unbreak.js +186 -0
  26. package/reporting/src/http.js +197 -19
  27. package/reporting/src/index.js +1 -0
  28. package/reporting/src/offscreen/doublefetch/capture.js +90 -0
  29. package/reporting/src/patterns.js +142 -2
  30. package/reporting/src/request/index.js +6 -0
  31. package/reporting/src/request/page-store.js +1 -0
  32. package/reporting/src/request/support.js +29 -0
  33. package/reporting/src/search-extractor.js +8 -2
  34. package/reporting/src/utils.js +19 -0
  35. package/reporting/test/doublefetch-unbreak.spec.js +133 -0
  36. package/reporting/test/http.spec.js +113 -0
  37. package/reporting/test/index.js +1 -0
  38. package/reporting/test/patterns.spec.js +239 -0
  39. package/reporting/test/search-extractor.spec.js +19 -1
  40. package/reporting/test/setup.unit.js +9 -0
@@ -1631,7 +1631,7 @@
1631
1631
  },
1632
1632
  "ts": "",
1633
1633
  "type": "wtm.request",
1634
- "userAgent": ""
1634
+ "userAgent": "chrome"
1635
1635
  },
1636
1636
  {
1637
1637
  "action": "wtm.attrack.tp_events",
@@ -3275,7 +3275,7 @@
3275
3275
  },
3276
3276
  "ts": "",
3277
3277
  "type": "wtm.request",
3278
- "userAgent": ""
3278
+ "userAgent": "chrome"
3279
3279
  },
3280
3280
  {
3281
3281
  "action": "wtm.attrack.tokensv2",
@@ -3296,7 +3296,7 @@
3296
3296
  },
3297
3297
  "ts": "",
3298
3298
  "type": "wtm.request",
3299
- "userAgent": ""
3299
+ "userAgent": "chrome"
3300
3300
  },
3301
3301
  {
3302
3302
  "action": "wtm.attrack.keysv2",
@@ -3486,7 +3486,7 @@
3486
3486
  },
3487
3487
  "ts": "",
3488
3488
  "type": "wtm.request",
3489
- "userAgent": ""
3489
+ "userAgent": "chrome"
3490
3490
  },
3491
3491
  {
3492
3492
  "action": "wtm.attrack.keysv2",
@@ -3676,7 +3676,7 @@
3676
3676
  },
3677
3677
  "ts": "",
3678
3678
  "type": "wtm.request",
3679
- "userAgent": ""
3679
+ "userAgent": "chrome"
3680
3680
  },
3681
3681
  {
3682
3682
  "action": "wtm.attrack.keysv2",
@@ -3702,7 +3702,7 @@
3702
3702
  },
3703
3703
  "ts": "",
3704
3704
  "type": "wtm.request",
3705
- "userAgent": ""
3705
+ "userAgent": "chrome"
3706
3706
  },
3707
3707
  {
3708
3708
  "action": "wtm.attrack.keysv2",
@@ -3728,7 +3728,7 @@
3728
3728
  },
3729
3729
  "ts": "",
3730
3730
  "type": "wtm.request",
3731
- "userAgent": ""
3731
+ "userAgent": "chrome"
3732
3732
  },
3733
3733
  {
3734
3734
  "action": "wtm.attrack.keysv2",
@@ -3754,7 +3754,7 @@
3754
3754
  },
3755
3755
  "ts": "",
3756
3756
  "type": "wtm.request",
3757
- "userAgent": ""
3757
+ "userAgent": "chrome"
3758
3758
  },
3759
3759
  {
3760
3760
  "action": "wtm.attrack.keysv2",
@@ -3780,7 +3780,7 @@
3780
3780
  },
3781
3781
  "ts": "",
3782
3782
  "type": "wtm.request",
3783
- "userAgent": ""
3783
+ "userAgent": "chrome"
3784
3784
  },
3785
3785
  {
3786
3786
  "action": "wtm.attrack.keysv2",
@@ -3806,7 +3806,7 @@
3806
3806
  },
3807
3807
  "ts": "",
3808
3808
  "type": "wtm.request",
3809
- "userAgent": ""
3809
+ "userAgent": "chrome"
3810
3810
  },
3811
3811
  {
3812
3812
  "action": "wtm.attrack.keysv2",
@@ -3832,7 +3832,7 @@
3832
3832
  },
3833
3833
  "ts": "",
3834
3834
  "type": "wtm.request",
3835
- "userAgent": ""
3835
+ "userAgent": "chrome"
3836
3836
  },
3837
3837
  {
3838
3838
  "action": "wtm.attrack.keysv2",
@@ -3858,7 +3858,7 @@
3858
3858
  },
3859
3859
  "ts": "",
3860
3860
  "type": "wtm.request",
3861
- "userAgent": ""
3861
+ "userAgent": "chrome"
3862
3862
  },
3863
3863
  {
3864
3864
  "action": "wtm.attrack.keysv2",
@@ -3884,6 +3884,6 @@
3884
3884
  },
3885
3885
  "ts": "",
3886
3886
  "type": "wtm.request",
3887
- "userAgent": ""
3887
+ "userAgent": "chrome"
3888
3888
  }
3889
3889
  ]
@@ -196,7 +196,7 @@
196
196
  },
197
197
  "ts": "",
198
198
  "type": "wtm.request",
199
- "userAgent": ""
199
+ "userAgent": "chrome"
200
200
  },
201
201
  {
202
202
  "action": "wtm.attrack.tp_events",
@@ -398,7 +398,7 @@
398
398
  },
399
399
  "ts": "",
400
400
  "type": "wtm.request",
401
- "userAgent": ""
401
+ "userAgent": "chrome"
402
402
  },
403
403
  {
404
404
  "action": "wtm.attrack.tokensv2",
@@ -419,7 +419,7 @@
419
419
  },
420
420
  "ts": "",
421
421
  "type": "wtm.request",
422
- "userAgent": ""
422
+ "userAgent": "chrome"
423
423
  },
424
424
  {
425
425
  "action": "wtm.attrack.keysv2",
@@ -609,7 +609,7 @@
609
609
  },
610
610
  "ts": "",
611
611
  "type": "wtm.request",
612
- "userAgent": ""
612
+ "userAgent": "chrome"
613
613
  },
614
614
  {
615
615
  "action": "wtm.attrack.keysv2",
@@ -799,6 +799,6 @@
799
799
  },
800
800
  "ts": "",
801
801
  "type": "wtm.request",
802
- "userAgent": ""
802
+ "userAgent": "chrome"
803
803
  }
804
804
  ]
@@ -130,7 +130,7 @@
130
130
  },
131
131
  "ts": "",
132
132
  "type": "wtm.request",
133
- "userAgent": ""
133
+ "userAgent": "chrome"
134
134
  },
135
135
  {
136
136
  "action": "wtm.attrack.tp_events",
@@ -243,7 +243,7 @@
243
243
  },
244
244
  "ts": "",
245
245
  "type": "wtm.request",
246
- "userAgent": ""
246
+ "userAgent": "chrome"
247
247
  },
248
248
  {
249
249
  "action": "wtm.attrack.tp_events",
@@ -684,7 +684,7 @@
684
684
  },
685
685
  "ts": "",
686
686
  "type": "wtm.request",
687
- "userAgent": ""
687
+ "userAgent": "chrome"
688
688
  },
689
689
  {
690
690
  "action": "wtm.attrack.tp_events",
@@ -1146,7 +1146,7 @@
1146
1146
  },
1147
1147
  "ts": "",
1148
1148
  "type": "wtm.request",
1149
- "userAgent": ""
1149
+ "userAgent": "chrome"
1150
1150
  },
1151
1151
  {
1152
1152
  "action": "wtm.attrack.tp_events",
@@ -1279,7 +1279,7 @@
1279
1279
  },
1280
1280
  "ts": "",
1281
1281
  "type": "wtm.request",
1282
- "userAgent": ""
1282
+ "userAgent": "chrome"
1283
1283
  },
1284
1284
  {
1285
1285
  "action": "wtm.attrack.tp_events",
@@ -1392,7 +1392,7 @@
1392
1392
  },
1393
1393
  "ts": "",
1394
1394
  "type": "wtm.request",
1395
- "userAgent": ""
1395
+ "userAgent": "chrome"
1396
1396
  },
1397
1397
  {
1398
1398
  "action": "wtm.attrack.tp_events",
@@ -1833,7 +1833,7 @@
1833
1833
  },
1834
1834
  "ts": "",
1835
1835
  "type": "wtm.request",
1836
- "userAgent": ""
1836
+ "userAgent": "chrome"
1837
1837
  },
1838
1838
  {
1839
1839
  "action": "wtm.attrack.tp_events",
@@ -2295,7 +2295,7 @@
2295
2295
  },
2296
2296
  "ts": "",
2297
2297
  "type": "wtm.request",
2298
- "userAgent": ""
2298
+ "userAgent": "chrome"
2299
2299
  },
2300
2300
  {
2301
2301
  "action": "wtm.attrack.tokensv2",
@@ -2316,7 +2316,7 @@
2316
2316
  },
2317
2317
  "ts": "",
2318
2318
  "type": "wtm.request",
2319
- "userAgent": ""
2319
+ "userAgent": "chrome"
2320
2320
  },
2321
2321
  {
2322
2322
  "action": "wtm.attrack.keysv2",
@@ -4602,7 +4602,7 @@
4602
4602
  },
4603
4603
  "ts": "",
4604
4604
  "type": "wtm.request",
4605
- "userAgent": ""
4605
+ "userAgent": "chrome"
4606
4606
  },
4607
4607
  {
4608
4608
  "action": "wtm.attrack.keysv2",
@@ -6892,7 +6892,7 @@
6892
6892
  },
6893
6893
  "ts": "",
6894
6894
  "type": "wtm.request",
6895
- "userAgent": ""
6895
+ "userAgent": "chrome"
6896
6896
  },
6897
6897
  {
6898
6898
  "action": "wtm.attrack.keysv2",
@@ -6918,7 +6918,7 @@
6918
6918
  },
6919
6919
  "ts": "",
6920
6920
  "type": "wtm.request",
6921
- "userAgent": ""
6921
+ "userAgent": "chrome"
6922
6922
  },
6923
6923
  {
6924
6924
  "action": "wtm.attrack.keysv2",
@@ -6944,6 +6944,6 @@
6944
6944
  },
6945
6945
  "ts": "",
6946
6946
  "type": "wtm.request",
6947
- "userAgent": ""
6947
+ "userAgent": "chrome"
6948
6948
  }
6949
6949
  ]
@@ -10,10 +10,16 @@
10
10
  */
11
11
 
12
12
  import logger from './logger';
13
- import { requireParam, requireInt, lazyInitAsync } from './utils';
13
+ import {
14
+ requireParam,
15
+ requireInt,
16
+ lazyInitAsync,
17
+ isSubSequence,
18
+ } from './utils';
14
19
  import { randomBetween } from './random';
15
20
  import { BadJobError } from './errors';
16
21
  import { anonymousHttpGet } from './http';
22
+ import { findSafeCookies } from './doublefetch-unbreak';
17
23
  import parseHtml from './html-parser';
18
24
  import { analyzePageStructure } from './page-structure';
19
25
  import { sanitizeUrl } from './sanitizer';
@@ -27,25 +33,6 @@ const ALLOW_HTML_AND_TEXT = [
27
33
  'application/xhtml+xml', // legacy format
28
34
  ];
29
35
 
30
- /**
31
- * Checks if one string (subsequence) can be derived from another string (sequence)
32
- * by only removing characters. This means that the subsequence appears in the
33
- * sequence in the same relative order but not necessarily consecutively.
34
- *
35
- * Example: "anana" is a subsequence of "banana", but "ab" is not.
36
- */
37
- function isSubSequence({ sequence, subsequence }) {
38
- let i = 0;
39
- let j = 0;
40
- while (i < subsequence.length && j < sequence.length) {
41
- if (subsequence[i] === sequence[j]) {
42
- i++;
43
- }
44
- j++;
45
- }
46
- return i === subsequence.length;
47
- }
48
-
49
36
  export function toTrustedUrl(url, { baseUrl, log, logWarn }) {
50
37
  if (!url) {
51
38
  return null;
@@ -311,6 +298,19 @@ export function sanitizeActivity(activity) {
311
298
  return noisyActivity.toFixed(4);
312
299
  }
313
300
 
301
+ // Compatibility layer to deal with known website breakage.
302
+ //
303
+ // TODO: This should come from patterns. For now, start with a hard-coded list.
304
+ function unbreakConfig(url) {
305
+ const { hostname } = new URL(url);
306
+ if (hostname === 'imdb.com' || hostname.endsWith('.imdb.com')) {
307
+ return {
308
+ headers: { Cookie: 'aws-waf-token={{safecookie:aws-waf-token}}' },
309
+ };
310
+ }
311
+ return null;
312
+ }
313
+
314
314
  class CachedPageFetcher {
315
315
  constructor() {
316
316
  this.urlToAsyncPageStructure = new Map();
@@ -332,6 +332,15 @@ class CachedPageFetcher {
332
332
  return from.origin === to.origin && from.pathname === to.pathname;
333
333
  };
334
334
 
335
+ let unbreak = unbreakConfig(url);
336
+ if (unbreak) {
337
+ logger.debug('[double-fetch] fixes found:', url, '->', unbreak);
338
+ unbreak = {
339
+ ...unbreak,
340
+ safecookie: await findSafeCookies(url, unbreak),
341
+ };
342
+ }
343
+
335
344
  let html;
336
345
  try {
337
346
  html = await anonymousHttpGet(url, {
@@ -340,6 +349,7 @@ class CachedPageFetcher {
340
349
  treat429AsPermanentError: true,
341
350
  downloadLimit: this.downloadLimit,
342
351
  allowedContentTypes: ALLOW_HTML_AND_TEXT,
352
+ ...unbreak,
343
353
  });
344
354
  } catch (e) {
345
355
  if (e.isPermanentError) {
@@ -0,0 +1,186 @@
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 logger from './logger';
13
+ import { findPlaceholders } from './http';
14
+
15
+ /**
16
+ * The goal of double-fetch is to reject content that only a logged-in user
17
+ * could see, because such content may leak private information; that is why it
18
+ * loads a page as anonymously as possible: no credentials, no cookies. In
19
+ * practice that is too limiting: a site behind AWS WAF, for instance, may be
20
+ * configured to require its token.
21
+ *
22
+ * Since it is infeasible to detect login-related cookies, we use an allowlist
23
+ * approach. The only rule is that an entry must not unlock non-public content,
24
+ * which rules out anything session-like (e.g. "oauth_token", "api_token").
25
+ *
26
+ * Note: being on this list is necessary but not sufficient. A cookie is read
27
+ * only if a double-fetch configuration names it, and only if it is scoped to
28
+ * the site being fetched - exactly as the browser would scope it.
29
+ */
30
+ const TRUSTED_COOKIES = new Set([
31
+ '_abck',
32
+ 'acw_tc',
33
+ 'addtl_consent',
34
+ 'AEC',
35
+ 'ak_bmsc',
36
+ 'aws-waf-token',
37
+ 'AWSALB',
38
+ 'AWSALBCORS',
39
+ 'axeptio_authorized_vendors',
40
+ 'axeptio_cookies',
41
+ 'bm_sv',
42
+ 'bm_sz',
43
+ 'borlabs-cookie',
44
+ '__cf_bm',
45
+ 'cf_clearance',
46
+ '__cfduid',
47
+ '__cflb',
48
+ '_cfuvid',
49
+ 'cky-consent',
50
+ '__cmpcc',
51
+ '__cmpconsent',
52
+ 'cmphitorder',
53
+ '__cmpiab',
54
+ 'cmplz_banner-status',
55
+ 'cmplz_consented_services',
56
+ 'cmpsessid',
57
+ 'CONSENT',
58
+ 'consent-policy',
59
+ 'consentUUID',
60
+ 'CookieConsentBulkTicket',
61
+ 'cookie_consent',
62
+ 'CookieConsent',
63
+ 'CookieConsentPolicy',
64
+ 'cookieconsent_seen',
65
+ 'cookieconsent_status',
66
+ 'cookiefirst-consent',
67
+ 'cookielawinfo-checkbox-necessary',
68
+ 'CookieLawInfoConsent',
69
+ 'cookieyes-consent',
70
+ 'datadome',
71
+ 'didomi_token',
72
+ 'disable-cmp',
73
+ 'euconsent',
74
+ 'euconsent-v2',
75
+ 'f5_cspm',
76
+ 'FCCDCF',
77
+ 'FCNEC',
78
+ 'GOOGLE_ABUSE_EXEMPTION',
79
+ 'gdpr_popup',
80
+ 'gpp',
81
+ 'gpp_sid',
82
+ 'gpp-string',
83
+ 'https_waf_cookie',
84
+ 'KP_UIDz',
85
+ 'NID',
86
+ 'OptanonAlertBoxClosed',
87
+ 'OptanonConsent',
88
+ 'OptanonControl',
89
+ 'osano_consentmanager',
90
+ 'pow_challenge',
91
+ 'pow_nonce',
92
+ '_px3',
93
+ 'pxcts',
94
+ '_pxhd',
95
+ '_pxvid',
96
+ 'rbzid',
97
+ 'reese84',
98
+ 'ROUTEID',
99
+ '__Secure-ENID',
100
+ 'SOCS',
101
+ 'sp_consent',
102
+ '_sp_enable_dfp_personalized_ads',
103
+ '_sp_v1_consent',
104
+ '__tlbcpv',
105
+ 'usercentrics',
106
+ 'usprivacy',
107
+ 'viewed_cookie_policy',
108
+ 'waf_captcha_marker',
109
+ 'x-amz-continuous-deployment-state',
110
+ ]);
111
+
112
+ /**
113
+ * Finds the cookies that the given double-fetch configuration is allowed to
114
+ * borrow from the user: on the trusted list, asked for by the configuration,
115
+ * and scoped to the URL that is about to be fetched.
116
+ *
117
+ * The lookup passes no "storeId", so it sees only the cookie store of the
118
+ * extension's own background context, which is the user's normal profile.
119
+ * Private windows and Firefox containers are separate stores, so their cookies
120
+ * are never even visible here - they are excluded by not asking for them,
121
+ * rather than by filtering them out afterwards.
122
+ */
123
+ export async function findSafeCookies(url, params) {
124
+ const requested = requestedCookies(params);
125
+ if (requested.size === 0) {
126
+ return new Map();
127
+ }
128
+ if (!chrome?.cookies?.getAll) {
129
+ logger.debug('cookie API unavailable: no safe cookie');
130
+ return new Map();
131
+ }
132
+
133
+ const found = new Map();
134
+ await Promise.all(
135
+ [...requested].map(async (name) => {
136
+ try {
137
+ // The first match is the most specific one, i.e. the one that the
138
+ // browser itself would send first.
139
+ const cookies = await chrome.cookies.getAll({ url, name });
140
+ const value = cookies?.[0]?.value;
141
+ if (value) {
142
+ found.set(name, value);
143
+ }
144
+ } catch (e) {
145
+ logger.warn('Unable to look up cookie:', name, e);
146
+ }
147
+ }),
148
+ );
149
+ return found;
150
+ }
151
+
152
+ /**
153
+ * Collects the names of all trusted cookies that the given configuration
154
+ * references. Placeholders can occur in headers and in "requires" entries,
155
+ * both in the shared configuration and in each step; the "onError"
156
+ * configuration is scanned recursively.
157
+ */
158
+ function requestedCookies(params, requested = new Set()) {
159
+ for (const { headers = {}, requires = [] } of [
160
+ params || {},
161
+ ...(params?.steps || []),
162
+ ]) {
163
+ for (const template of [...Object.values(headers), ...requires]) {
164
+ collectSafeCookies(template, requested);
165
+ }
166
+ }
167
+ if (params?.onError) {
168
+ requestedCookies(params.onError, requested);
169
+ }
170
+ return requested;
171
+ }
172
+
173
+ function collectSafeCookies(template, requested) {
174
+ for (const expression of findPlaceholders(template)) {
175
+ for (const placeholder of expression.split('||')) {
176
+ if (placeholder.startsWith('safecookie:')) {
177
+ const name = placeholder.slice('safecookie:'.length);
178
+ if (TRUSTED_COOKIES.has(name)) {
179
+ requested.add(name);
180
+ } else {
181
+ logger.warn('Ignoring', placeholder, '(not a trusted cookie)');
182
+ }
183
+ }
184
+ }
185
+ }
186
+ }