@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.
Files changed (179) hide show
  1. package/.editorconfig +12 -0
  2. package/.eslintignore +3 -0
  3. package/.eslintrc +16 -0
  4. package/.github/workflows/release.yml +34 -0
  5. package/.github/workflows/tests.yml +20 -0
  6. package/.prettierrc +9 -0
  7. package/.tool-versions +1 -0
  8. package/CHANGELOG.md +795 -0
  9. package/LICENSE +373 -0
  10. package/README.md +1 -0
  11. package/communication/README.md +11 -0
  12. package/communication/example/index.js +43 -0
  13. package/communication/example/manifest.json +16 -0
  14. package/communication/karma.conf.cjs +19 -0
  15. package/communication/package.json +52 -0
  16. package/communication/rollup.common-config.cjs +17 -0
  17. package/communication/rollup.config.cjs +10 -0
  18. package/communication/src/encoding.js +54 -0
  19. package/communication/src/errors.js +84 -0
  20. package/communication/src/index.js +76 -0
  21. package/communication/src/logger.js +41 -0
  22. package/communication/src/padding.js +60 -0
  23. package/communication/src/proxied-http.js +231 -0
  24. package/communication/src/server-public-key-accessor.js +123 -0
  25. package/communication/src/timestamps.js +37 -0
  26. package/communication/src/trusted-clock.js +58 -0
  27. package/communication/src/utils.js +28 -0
  28. package/communication/src/zlib.js +17 -0
  29. package/communication/test/helpers/in-memory-database.js +43 -0
  30. package/communication/test/server-public-key-accessor.spec.js +135 -0
  31. package/communication/test/utils.spec.js +43 -0
  32. package/package.json +50 -0
  33. package/reporting/TODO.md +2 -0
  34. package/reporting/assets/request/bloom_filter.dat +0 -0
  35. package/reporting/assets/request/update.json +1 -0
  36. package/reporting/example/content.js +11 -0
  37. package/reporting/example/index.js +132 -0
  38. package/reporting/example/inspector/index.html +17 -0
  39. package/reporting/example/inspector/index.js +27 -0
  40. package/reporting/example/manifests/chromium.json +37 -0
  41. package/reporting/example/manifests/firefox.json +35 -0
  42. package/reporting/example/rules.json +62 -0
  43. package/reporting/example/setup.js +1 -0
  44. package/reporting/example/tests/test1.html +10 -0
  45. package/reporting/karma.conf.cjs +22 -0
  46. package/reporting/package.json +63 -0
  47. package/reporting/rollup.common-config.cjs +19 -0
  48. package/reporting/rollup.config.cjs +20 -0
  49. package/reporting/src/LRU.js +149 -0
  50. package/reporting/src/activity-estimator.js +298 -0
  51. package/reporting/src/alive-check.js +139 -0
  52. package/reporting/src/alive-message-generator.js +142 -0
  53. package/reporting/src/bloom-filters.js +345 -0
  54. package/reporting/src/country-provider.js +295 -0
  55. package/reporting/src/cyrb53.js +32 -0
  56. package/reporting/src/digest.js +33 -0
  57. package/reporting/src/doublefetch-page-handler.js +548 -0
  58. package/reporting/src/duplicate-detector.js +233 -0
  59. package/reporting/src/errors.js +84 -0
  60. package/reporting/src/event-listener-queue.js +121 -0
  61. package/reporting/src/fixed-size-cache.js +63 -0
  62. package/reporting/src/hash-detector.js +1526 -0
  63. package/reporting/src/html-parser.js +17 -0
  64. package/reporting/src/http.js +265 -0
  65. package/reporting/src/index.js +14 -0
  66. package/reporting/src/job-scheduler.js +912 -0
  67. package/reporting/src/logger.js +121 -0
  68. package/reporting/src/md5.js +334 -0
  69. package/reporting/src/message-sender.js +51 -0
  70. package/reporting/src/network.js +140 -0
  71. package/reporting/src/new-page-approver.js +119 -0
  72. package/reporting/src/page-aggregator.js +185 -0
  73. package/reporting/src/page-quorum-check-handler.js +200 -0
  74. package/reporting/src/page-structure.js +136 -0
  75. package/reporting/src/pagedb.js +671 -0
  76. package/reporting/src/pages.js +1798 -0
  77. package/reporting/src/patterns-updater.js +310 -0
  78. package/reporting/src/patterns.js +416 -0
  79. package/reporting/src/persisted-bitarray.js +265 -0
  80. package/reporting/src/persisted-hashes.js +189 -0
  81. package/reporting/src/quorum-checker.js +327 -0
  82. package/reporting/src/random.js +39 -0
  83. package/reporting/src/reporting.js +290 -0
  84. package/reporting/src/request/config.js +116 -0
  85. package/reporting/src/request/content-script.js +77 -0
  86. package/reporting/src/request/database.js +147 -0
  87. package/reporting/src/request/dnt.js +24 -0
  88. package/reporting/src/request/hash.js +101 -0
  89. package/reporting/src/request/index.js +874 -0
  90. package/reporting/src/request/page-telemetry.js +42 -0
  91. package/reporting/src/request/qs-whitelist2.js +247 -0
  92. package/reporting/src/request/resources/prob.js +601 -0
  93. package/reporting/src/request/steps/block-rules.js +40 -0
  94. package/reporting/src/request/steps/check-context.js +37 -0
  95. package/reporting/src/request/steps/cookie-context.js +209 -0
  96. package/reporting/src/request/steps/oauth-detector.js +101 -0
  97. package/reporting/src/request/steps/page-logger.js +177 -0
  98. package/reporting/src/request/steps/redirect-tagger.js +75 -0
  99. package/reporting/src/request/steps/subdomain-check.js +34 -0
  100. package/reporting/src/request/steps/token-checker/index.js +189 -0
  101. package/reporting/src/request/steps/token-checker/token-domain.js +129 -0
  102. package/reporting/src/request/steps/token-examiner.js +182 -0
  103. package/reporting/src/request/steps/token-telemetry/cached-entry-pipeline.js +210 -0
  104. package/reporting/src/request/steps/token-telemetry/index.js +234 -0
  105. package/reporting/src/request/steps/token-telemetry/key-pipeline.js +109 -0
  106. package/reporting/src/request/steps/token-telemetry/token-pipeline.js +105 -0
  107. package/reporting/src/request/time.js +73 -0
  108. package/reporting/src/request/utils/bloom-filter-packed.js +107 -0
  109. package/reporting/src/request/utils/chrome-storage-map.js +282 -0
  110. package/reporting/src/request/utils/subject.js +37 -0
  111. package/reporting/src/request/utils/temp-set.js +56 -0
  112. package/reporting/src/request/utils/tlds.js +55 -0
  113. package/reporting/src/request/utils.js +41 -0
  114. package/reporting/src/request-reporter.js +111 -0
  115. package/reporting/src/sanitizer.js +519 -0
  116. package/reporting/src/search-extractor.js +338 -0
  117. package/reporting/src/self-check.js +105 -0
  118. package/reporting/src/seq-executor.js +43 -0
  119. package/reporting/src/session-storage.js +399 -0
  120. package/reporting/src/url-analyzer.js +161 -0
  121. package/reporting/src/url-cleaner.js +60 -0
  122. package/reporting/src/utils/pacemaker.js +279 -0
  123. package/reporting/src/utils/url.js +114 -0
  124. package/reporting/src/utils.js +345 -0
  125. package/reporting/src/webrequest-pipeline/cname-uncloak.js +110 -0
  126. package/reporting/src/webrequest-pipeline/index.js +287 -0
  127. package/reporting/src/webrequest-pipeline/logger.js +14 -0
  128. package/reporting/src/webrequest-pipeline/page-store.js +282 -0
  129. package/reporting/src/webrequest-pipeline/page.js +140 -0
  130. package/reporting/src/webrequest-pipeline/pipeline.js +249 -0
  131. package/reporting/src/webrequest-pipeline/utils/webrequest.js +113 -0
  132. package/reporting/src/webrequest-pipeline/webrequest-context.js +153 -0
  133. package/reporting/test/README.md +2 -0
  134. package/reporting/test/activity-estimator.spec.js +356 -0
  135. package/reporting/test/alive-check.spec.js +156 -0
  136. package/reporting/test/alive-message-generator.spec.js +186 -0
  137. package/reporting/test/country-provider.spec.js +263 -0
  138. package/reporting/test/doublefetch-page-handler.spec.js +818 -0
  139. package/reporting/test/duplicate-detector.spec.js +689 -0
  140. package/reporting/test/helpers/dom-parsers.js +41 -0
  141. package/reporting/test/helpers/fake-session-storage.js +69 -0
  142. package/reporting/test/helpers/fast-check-utils.js +28 -0
  143. package/reporting/test/helpers/fetch-mock.js +57 -0
  144. package/reporting/test/helpers/in-memory-database.js +14 -0
  145. package/reporting/test/helpers/memory-map.js +72 -0
  146. package/reporting/test/helpers/pagedb-mocks.js +41 -0
  147. package/reporting/test/index.js +47 -0
  148. package/reporting/test/job-scheduler.spec.js +691 -0
  149. package/reporting/test/network.spec.js +72 -0
  150. package/reporting/test/page-aggregator.spec.js +104 -0
  151. package/reporting/test/page-quorum-check-handler.spec.js +86 -0
  152. package/reporting/test/pagedb.spec.js +250 -0
  153. package/reporting/test/pages.spec.js +693 -0
  154. package/reporting/test/patterns-updater.spec.js +446 -0
  155. package/reporting/test/patterns.spec.js +751 -0
  156. package/reporting/test/persisted-hashes.spec.js +169 -0
  157. package/reporting/test/reporting.spec.js +205 -0
  158. package/reporting/test/request/database.spec.js +59 -0
  159. package/reporting/test/request/hash.spec.js +108 -0
  160. package/reporting/test/request/index.spec.js +378 -0
  161. package/reporting/test/request/qs-whitelist2.spec.js +189 -0
  162. package/reporting/test/request/steps/check-context.spec.js +51 -0
  163. package/reporting/test/request/steps/oauth-detector.spec.js +339 -0
  164. package/reporting/test/request/test-pages.js +1246 -0
  165. package/reporting/test/request/utils/bloom-filter-packed.spec.js +37 -0
  166. package/reporting/test/request/utils/chrome-storage-map.spec.js +28 -0
  167. package/reporting/test/request/utils/tldts.spec.js +62 -0
  168. package/reporting/test/request/utils.spec.js +168 -0
  169. package/reporting/test/sanitizer.spec.js +1087 -0
  170. package/reporting/test/search-extractor.spec.js +590 -0
  171. package/reporting/test/seq-executor.spec.js +158 -0
  172. package/reporting/test/session-storage.spec.js +400 -0
  173. package/reporting/test/setup.js +24 -0
  174. package/reporting/test/url-analyzer.spec.js +451 -0
  175. package/reporting/test/url-cleaner.spec.js +102 -0
  176. package/reporting/test/utils/pacemaker.spec.js +222 -0
  177. package/reporting/test/utils/url.spec.js +660 -0
  178. package/reporting/test/utils.spec.js +299 -0
  179. package/reporting/test/webrequest-pipeline/pipeline.spec.js +251 -0
@@ -0,0 +1,279 @@
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
+
14
+ // Pacemaker is a service which allows to schedule tasks (either as intervals or
15
+ // timeouts) while doing its best to not wake-up the browser too often. To this
16
+ // end, it offers a few common intervals (e.g.: every minute, every hour,
17
+ // etc.) and makes sure that all the tasks are triggered at the same time. It
18
+ // also tries to adapt its own frequency depending on registered tasks to
19
+ // trigger as rarely as possible while respecting the contract. As a
20
+ // consequence, if there is no task registered, the pacemaker will do nothing.
21
+ //
22
+ // It is possible to schedule tasks at any time, but this is not recommended. To
23
+ // make sure the efficiency is maximal, you should pick a pre-defined method
24
+ // like `everyFewMinutes` (instead of `register`) and choose the maximum time
25
+ // which fits your use-case.
26
+ //
27
+ // Here are a few examples:
28
+ //
29
+ // 1. You need to update a config fetched from CDN and it does not change more
30
+ // than once an hour, then it's recommended to use `pacemaker.everyHour()`.
31
+ //
32
+ // 2. You need to run a check on the state of your module every few seconds (and
33
+ // it does not matter exactly how many seconds as long as it's less or equal to
34
+ // 10), then you should use `pacemaker.everyFewSeconds()`.
35
+
36
+ const logger = Logger.get('pacemaker', { level: 'log' });
37
+
38
+ // Common durations
39
+ const ONE_SECOND = 1000;
40
+ const ONE_MINUTE = 60 * ONE_SECOND;
41
+ const ONE_HOUR = 60 * ONE_MINUTE;
42
+ // const ONE_DAY = 24 * ONE_HOUR;
43
+
44
+ class Task {
45
+ constructor({ fn, timeout, once, startImmediately, args }) {
46
+ if (!fn.name || fn.name === 'fn') {
47
+ throw new Error('Pacemaker can register named callbacks only');
48
+ }
49
+ this.name = fn.name || '<anon>';
50
+ this.fn = fn;
51
+ this.timeout = timeout;
52
+ this.once = once;
53
+ this.args = args;
54
+
55
+ // Setting `last` to `0` means that whenever the next tick happens, this
56
+ // task will be triggerd, no matter how big the `timeout` is.
57
+ this.last = startImmediately ? -timeout : Date.now();
58
+ this.startImmediately = startImmediately;
59
+
60
+ this.verboseLogging = false;
61
+ }
62
+
63
+ run(now) {
64
+ if (this.verboseLogging) {
65
+ logger.debug('run task:', this.name);
66
+ }
67
+ const t0 = Date.now();
68
+ try {
69
+ this.fn(...this.args);
70
+ this.last = now;
71
+ if (this.verboseLogging) {
72
+ logger.debug('task', this.name, 'took', Date.now() - t0, 'ms');
73
+ }
74
+ } catch (e) {
75
+ logger.error('error executing task', this.name, e);
76
+ }
77
+ }
78
+ }
79
+
80
+ export class Pacemaker {
81
+ constructor() {
82
+ this.freq = null;
83
+ this.timer = null;
84
+ this.tasks = new Set();
85
+ }
86
+
87
+ stop() {
88
+ clearTimeout(this.timer);
89
+ this.timer = null;
90
+ this.freq = null;
91
+ this.tasks = new Set();
92
+ }
93
+
94
+ /**
95
+ * When tasks are added or removed, make sure that the pacemaker interval is
96
+ * running at a frequency which corresponds to the frequency of the most
97
+ * frequent task. If that is not the case already, then the existing interval
98
+ * is stopped and a new one is started with the correct frequency.
99
+ *
100
+ * If there is currently no registered task, then stop the interval completely.
101
+ */
102
+ _adjustFrequency({ added = [], removed = [] } = {}) {
103
+ if (this.verboseLogging) {
104
+ logger.debug('_adjustFrequency', { added, removed });
105
+ }
106
+
107
+ if (this.tasks.size === 0) {
108
+ logger.log('no task in pacemaker, stop interval');
109
+ this.stop();
110
+ return;
111
+ }
112
+
113
+ if (this.freq !== null) {
114
+ // Knowing which tasks were removed and which were added we can check if we
115
+ // actually need to adjust the interval. If a task with interval lower than
116
+ // the current pacemaker interval is added then we need to adjust.
117
+ let minIntervalAdded = Number.MAX_SAFE_INTEGER;
118
+ if (added.length !== 0) {
119
+ for (const { timeout } of added) {
120
+ if (timeout < minIntervalAdded) {
121
+ minIntervalAdded = timeout;
122
+ }
123
+ }
124
+ }
125
+
126
+ // If a task with interval equal to the current interval of the pacemaker
127
+ // then we might need to adjust (if this was the only task with this
128
+ // interval).
129
+ let minIntervalRemoved = Number.MAX_SAFE_INTEGER;
130
+ if (removed.length !== 0) {
131
+ for (const { timeout } of removed) {
132
+ if (timeout < minIntervalRemoved) {
133
+ minIntervalRemoved = timeout;
134
+ }
135
+ }
136
+ }
137
+
138
+ // If none of the conditions is met then the current interval is un-changed.
139
+ if (minIntervalAdded >= this.freq && minIntervalRemoved > this.freq) {
140
+ return;
141
+ }
142
+ }
143
+
144
+ // Get minimum frequency of remaining tasks and use it as base interval
145
+ let minFreq = Number.MAX_SAFE_INTEGER;
146
+ for (const { timeout } of this.tasks) {
147
+ if (timeout < minFreq) {
148
+ minFreq = timeout;
149
+ }
150
+ }
151
+ logger.debug('current minimum timeout:', minFreq);
152
+
153
+ // Frequency needs to be adjusted
154
+ if (this.freq === null || this.freq !== minFreq) {
155
+ logger.log('interval timeout change detected', this.freq, '->', minFreq);
156
+
157
+ // Reset timeout
158
+ clearTimeout(this.timer);
159
+ this.freq = minFreq;
160
+
161
+ // In case some instant task was added, we run a first tick to make sure
162
+ // instant timeouts or intervals are executed straight away. Otherwise, we
163
+ // just set a timeout to trigger a _tick in `this.freq` milliseconds.
164
+ const hasInstantTask = added.some(
165
+ ({ startImmediately }) => startImmediately,
166
+ );
167
+ this._scheduleNextTick(hasInstantTask ? 0 : this.freq);
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Schedule next tick
173
+ */
174
+ _scheduleNextTick(timeout) {
175
+ clearTimeout(this.timer);
176
+ this.timer = setTimeout(() => this._tick(), timeout);
177
+ }
178
+
179
+ /**
180
+ * Make sure that tasks which should run... run.
181
+ */
182
+ _tick() {
183
+ const now = Date.now();
184
+ if (this.verboseLogging) {
185
+ logger.debug('_tick', now);
186
+ }
187
+
188
+ // Check all tasks
189
+ const removedTasks = [];
190
+ for (const task of this.tasks) {
191
+ if (now >= task.last + task.timeout) {
192
+ task.run(now);
193
+
194
+ // delete setTimeout tasks after they run
195
+ if (task.once === true) {
196
+ this.tasks.delete(task);
197
+ removedTasks.push(task);
198
+ }
199
+ }
200
+ }
201
+ if (this.verboseLogging) {
202
+ logger.debug('duration sync', Date.now() - now);
203
+ }
204
+
205
+ // Register timout for next _tick
206
+ this._scheduleNextTick(this.freq);
207
+
208
+ // Check if frequency needs to be adjusted
209
+ if (removedTasks.length !== 0) {
210
+ this._adjustFrequency({ removed: removedTasks });
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Register a function to be run by the pacemaker. By default it will run
216
+ * periodically like in a setInterval. It's possible to make the function
217
+ * start immediately, or only once like a setTimeout.
218
+ */
219
+ register(fn, { timeout, once = false, startImmediately = false, args = [] }) {
220
+ if (fn === undefined) {
221
+ throw new Error('fn cannot be undefined');
222
+ }
223
+
224
+ if (timeout === undefined) {
225
+ throw new Error('timeout cannot be undefined');
226
+ }
227
+
228
+ const task = new Task({
229
+ fn,
230
+ timeout,
231
+ once,
232
+ startImmediately,
233
+ args,
234
+ });
235
+
236
+ logger.debug('new task', task);
237
+ this.tasks.add(task);
238
+ this._adjustFrequency({ added: [task] });
239
+
240
+ return {
241
+ stop: () => {
242
+ this.tasks.delete(task);
243
+ this._adjustFrequency({ removed: [task] });
244
+ },
245
+ };
246
+ }
247
+
248
+ everySecond(fn) {
249
+ return this.register(fn, { timeout: ONE_SECOND });
250
+ }
251
+
252
+ everyFewSeconds(fn) {
253
+ return this.register(fn, { timeout: 10 * ONE_SECOND });
254
+ }
255
+
256
+ everyMinute(fn) {
257
+ return this.register(fn, { timeout: ONE_MINUTE });
258
+ }
259
+
260
+ everyFewMinutes(fn) {
261
+ return this.register(fn, { timeout: 10 * ONE_MINUTE });
262
+ }
263
+
264
+ everyHour(fn) {
265
+ return this.register(fn, { timeout: ONE_HOUR });
266
+ }
267
+
268
+ setTimeout(fn, timeout, ...args) {
269
+ return this.register(fn, { timeout, once: true, args });
270
+ }
271
+
272
+ clearTimeout(timeout) {
273
+ if (timeout && timeout.stop) {
274
+ timeout.stop();
275
+ }
276
+ }
277
+ }
278
+
279
+ export default new Pacemaker();
@@ -0,0 +1,114 @@
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 { ImmutableURL } from '@cliqz/url-parser';
13
+
14
+ const ipv4Part = '0*([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])'; // numbers 0 - 255
15
+ const ipv4Regex = new RegExp(
16
+ `^${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}([:]([0-9])+)?$`,
17
+ ); // port number
18
+
19
+ export function isIpv4Address(host) {
20
+ return ipv4Regex.test(host);
21
+ }
22
+
23
+ /**
24
+ * This is an abstraction over URL with caching and basic error handling built in. The main
25
+ * difference is that this catches exceptions from the URL constructor (when the url is invalid)
26
+ * and returns null instead in these cases.
27
+ * @param String url
28
+ * @returns {URL} parsed URL if valid is parseable, otherwise null;
29
+ */
30
+ export function parse(url) {
31
+ // We can only try to parse url of type `string`.
32
+ if (typeof url !== 'string') {
33
+ return null;
34
+ }
35
+
36
+ // If it's the first time we see `url`, try to parse it.
37
+ try {
38
+ const parsed = new ImmutableURL(url);
39
+ return parsed;
40
+ } catch (e) {
41
+ return null;
42
+ }
43
+ }
44
+
45
+ function tryDecode(fn) {
46
+ return (url) => {
47
+ // Any decoding function should always be given a 'string' argument but
48
+ // since the name of the function `try` implies that it should *never* throw
49
+ // it is safer to add an explicit check for this.
50
+ if (typeof url !== 'string') {
51
+ return url;
52
+ }
53
+
54
+ // We observe that in practice, most URLs do not need any decoding; to make
55
+ // sure the cost is as low as possible, we first check if there is a chance
56
+ // that decoding will be needed (will be false 99% of the time).
57
+ if (url.indexOf('%') === -1) {
58
+ return url;
59
+ }
60
+
61
+ try {
62
+ return fn(url);
63
+ } catch (e) {
64
+ return url;
65
+ }
66
+ };
67
+ }
68
+
69
+ export const tryDecodeURIComponent = tryDecode(decodeURIComponent);
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
+ export function getName(url) {
101
+ if (url === null) {
102
+ return null;
103
+ }
104
+
105
+ if (url.hostIsIp) {
106
+ return 'IP';
107
+ }
108
+
109
+ if (!url.hostname) {
110
+ return url.pathname;
111
+ }
112
+
113
+ return url.domainInfo.domainWithoutSuffix || url.generalDomain;
114
+ }