@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.
- package/.editorconfig +12 -0
- package/.eslintignore +3 -0
- package/.eslintrc +16 -0
- package/.github/workflows/release.yml +34 -0
- package/.github/workflows/tests.yml +20 -0
- package/.prettierrc +9 -0
- package/.tool-versions +1 -0
- package/CHANGELOG.md +795 -0
- package/LICENSE +373 -0
- package/README.md +1 -0
- package/communication/README.md +11 -0
- package/communication/example/index.js +43 -0
- package/communication/example/manifest.json +16 -0
- package/communication/karma.conf.cjs +19 -0
- package/communication/package.json +52 -0
- package/communication/rollup.common-config.cjs +17 -0
- package/communication/rollup.config.cjs +10 -0
- package/communication/src/encoding.js +54 -0
- package/communication/src/errors.js +84 -0
- package/communication/src/index.js +76 -0
- package/communication/src/logger.js +41 -0
- package/communication/src/padding.js +60 -0
- package/communication/src/proxied-http.js +231 -0
- package/communication/src/server-public-key-accessor.js +123 -0
- package/communication/src/timestamps.js +37 -0
- package/communication/src/trusted-clock.js +58 -0
- package/communication/src/utils.js +28 -0
- package/communication/src/zlib.js +17 -0
- package/communication/test/helpers/in-memory-database.js +43 -0
- package/communication/test/server-public-key-accessor.spec.js +135 -0
- package/communication/test/utils.spec.js +43 -0
- package/package.json +50 -0
- package/reporting/TODO.md +2 -0
- package/reporting/assets/request/bloom_filter.dat +0 -0
- package/reporting/assets/request/update.json +1 -0
- package/reporting/example/content.js +11 -0
- package/reporting/example/index.js +132 -0
- package/reporting/example/inspector/index.html +17 -0
- package/reporting/example/inspector/index.js +27 -0
- package/reporting/example/manifests/chromium.json +37 -0
- package/reporting/example/manifests/firefox.json +35 -0
- package/reporting/example/rules.json +62 -0
- package/reporting/example/setup.js +1 -0
- package/reporting/example/tests/test1.html +10 -0
- package/reporting/karma.conf.cjs +22 -0
- package/reporting/package.json +63 -0
- package/reporting/rollup.common-config.cjs +19 -0
- package/reporting/rollup.config.cjs +20 -0
- package/reporting/src/LRU.js +149 -0
- package/reporting/src/activity-estimator.js +298 -0
- package/reporting/src/alive-check.js +139 -0
- package/reporting/src/alive-message-generator.js +142 -0
- package/reporting/src/bloom-filters.js +345 -0
- package/reporting/src/country-provider.js +295 -0
- package/reporting/src/cyrb53.js +32 -0
- package/reporting/src/digest.js +33 -0
- package/reporting/src/doublefetch-page-handler.js +548 -0
- package/reporting/src/duplicate-detector.js +233 -0
- package/reporting/src/errors.js +84 -0
- package/reporting/src/event-listener-queue.js +121 -0
- package/reporting/src/fixed-size-cache.js +63 -0
- package/reporting/src/hash-detector.js +1526 -0
- package/reporting/src/html-parser.js +17 -0
- package/reporting/src/http.js +265 -0
- package/reporting/src/index.js +14 -0
- package/reporting/src/job-scheduler.js +912 -0
- package/reporting/src/logger.js +121 -0
- package/reporting/src/md5.js +334 -0
- package/reporting/src/message-sender.js +51 -0
- package/reporting/src/network.js +140 -0
- package/reporting/src/new-page-approver.js +119 -0
- package/reporting/src/page-aggregator.js +185 -0
- package/reporting/src/page-quorum-check-handler.js +200 -0
- package/reporting/src/page-structure.js +136 -0
- package/reporting/src/pagedb.js +671 -0
- package/reporting/src/pages.js +1798 -0
- package/reporting/src/patterns-updater.js +310 -0
- package/reporting/src/patterns.js +416 -0
- package/reporting/src/persisted-bitarray.js +265 -0
- package/reporting/src/persisted-hashes.js +189 -0
- package/reporting/src/quorum-checker.js +327 -0
- package/reporting/src/random.js +39 -0
- package/reporting/src/reporting.js +290 -0
- package/reporting/src/request/config.js +116 -0
- package/reporting/src/request/content-script.js +77 -0
- package/reporting/src/request/database.js +147 -0
- package/reporting/src/request/dnt.js +24 -0
- package/reporting/src/request/hash.js +101 -0
- package/reporting/src/request/index.js +874 -0
- package/reporting/src/request/page-telemetry.js +42 -0
- package/reporting/src/request/qs-whitelist2.js +247 -0
- package/reporting/src/request/resources/prob.js +601 -0
- package/reporting/src/request/steps/block-rules.js +40 -0
- package/reporting/src/request/steps/check-context.js +37 -0
- package/reporting/src/request/steps/cookie-context.js +209 -0
- package/reporting/src/request/steps/oauth-detector.js +101 -0
- package/reporting/src/request/steps/page-logger.js +177 -0
- package/reporting/src/request/steps/redirect-tagger.js +75 -0
- package/reporting/src/request/steps/subdomain-check.js +34 -0
- package/reporting/src/request/steps/token-checker/index.js +189 -0
- package/reporting/src/request/steps/token-checker/token-domain.js +129 -0
- package/reporting/src/request/steps/token-examiner.js +182 -0
- package/reporting/src/request/steps/token-telemetry/cached-entry-pipeline.js +210 -0
- package/reporting/src/request/steps/token-telemetry/index.js +234 -0
- package/reporting/src/request/steps/token-telemetry/key-pipeline.js +109 -0
- package/reporting/src/request/steps/token-telemetry/token-pipeline.js +105 -0
- package/reporting/src/request/time.js +73 -0
- package/reporting/src/request/utils/bloom-filter-packed.js +107 -0
- package/reporting/src/request/utils/chrome-storage-map.js +282 -0
- package/reporting/src/request/utils/subject.js +37 -0
- package/reporting/src/request/utils/temp-set.js +56 -0
- package/reporting/src/request/utils/tlds.js +55 -0
- package/reporting/src/request/utils.js +41 -0
- package/reporting/src/request-reporter.js +111 -0
- package/reporting/src/sanitizer.js +519 -0
- package/reporting/src/search-extractor.js +338 -0
- package/reporting/src/self-check.js +105 -0
- package/reporting/src/seq-executor.js +43 -0
- package/reporting/src/session-storage.js +399 -0
- package/reporting/src/url-analyzer.js +161 -0
- package/reporting/src/url-cleaner.js +60 -0
- package/reporting/src/utils/pacemaker.js +279 -0
- package/reporting/src/utils/url.js +114 -0
- package/reporting/src/utils.js +345 -0
- package/reporting/src/webrequest-pipeline/cname-uncloak.js +110 -0
- package/reporting/src/webrequest-pipeline/index.js +287 -0
- package/reporting/src/webrequest-pipeline/logger.js +14 -0
- package/reporting/src/webrequest-pipeline/page-store.js +282 -0
- package/reporting/src/webrequest-pipeline/page.js +140 -0
- package/reporting/src/webrequest-pipeline/pipeline.js +249 -0
- package/reporting/src/webrequest-pipeline/utils/webrequest.js +113 -0
- package/reporting/src/webrequest-pipeline/webrequest-context.js +153 -0
- package/reporting/test/README.md +2 -0
- package/reporting/test/activity-estimator.spec.js +356 -0
- package/reporting/test/alive-check.spec.js +156 -0
- package/reporting/test/alive-message-generator.spec.js +186 -0
- package/reporting/test/country-provider.spec.js +263 -0
- package/reporting/test/doublefetch-page-handler.spec.js +818 -0
- package/reporting/test/duplicate-detector.spec.js +689 -0
- package/reporting/test/helpers/dom-parsers.js +41 -0
- package/reporting/test/helpers/fake-session-storage.js +69 -0
- package/reporting/test/helpers/fast-check-utils.js +28 -0
- package/reporting/test/helpers/fetch-mock.js +57 -0
- package/reporting/test/helpers/in-memory-database.js +14 -0
- package/reporting/test/helpers/memory-map.js +72 -0
- package/reporting/test/helpers/pagedb-mocks.js +41 -0
- package/reporting/test/index.js +47 -0
- package/reporting/test/job-scheduler.spec.js +691 -0
- package/reporting/test/network.spec.js +72 -0
- package/reporting/test/page-aggregator.spec.js +104 -0
- package/reporting/test/page-quorum-check-handler.spec.js +86 -0
- package/reporting/test/pagedb.spec.js +250 -0
- package/reporting/test/pages.spec.js +693 -0
- package/reporting/test/patterns-updater.spec.js +446 -0
- package/reporting/test/patterns.spec.js +751 -0
- package/reporting/test/persisted-hashes.spec.js +169 -0
- package/reporting/test/reporting.spec.js +205 -0
- package/reporting/test/request/database.spec.js +59 -0
- package/reporting/test/request/hash.spec.js +108 -0
- package/reporting/test/request/index.spec.js +378 -0
- package/reporting/test/request/qs-whitelist2.spec.js +189 -0
- package/reporting/test/request/steps/check-context.spec.js +51 -0
- package/reporting/test/request/steps/oauth-detector.spec.js +339 -0
- package/reporting/test/request/test-pages.js +1246 -0
- package/reporting/test/request/utils/bloom-filter-packed.spec.js +37 -0
- package/reporting/test/request/utils/chrome-storage-map.spec.js +28 -0
- package/reporting/test/request/utils/tldts.spec.js +62 -0
- package/reporting/test/request/utils.spec.js +168 -0
- package/reporting/test/sanitizer.spec.js +1087 -0
- package/reporting/test/search-extractor.spec.js +590 -0
- package/reporting/test/seq-executor.spec.js +158 -0
- package/reporting/test/session-storage.spec.js +400 -0
- package/reporting/test/setup.js +24 -0
- package/reporting/test/url-analyzer.spec.js +451 -0
- package/reporting/test/url-cleaner.spec.js +102 -0
- package/reporting/test/utils/pacemaker.spec.js +222 -0
- package/reporting/test/utils/url.spec.js +660 -0
- package/reporting/test/utils.spec.js +299 -0
- package/reporting/test/webrequest-pipeline/pipeline.spec.js +251 -0
|
@@ -0,0 +1,310 @@
|
|
|
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 { randBetween, clamp } from './utils';
|
|
14
|
+
import SelfChecks from './self-check';
|
|
15
|
+
|
|
16
|
+
const SECOND = 1000;
|
|
17
|
+
const MINUTE = 60 * SECOND;
|
|
18
|
+
const HOUR = 60 * MINUTE;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* If you need to introduce incompatible changes to the the state
|
|
22
|
+
* persistence, you can bump this number to clear the persisted cache.
|
|
23
|
+
* It will be as if you start with a fresh installation of the extension.
|
|
24
|
+
*
|
|
25
|
+
* (If you are not sure whether the change is incompatible, it is
|
|
26
|
+
* a good idea to be conservative and bump this number anyway; it will
|
|
27
|
+
* only introduce little overhead.)
|
|
28
|
+
*/
|
|
29
|
+
const DB_VERSION = 1;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Responsible for keeping the patterns up-to-date by polling
|
|
33
|
+
* the backend for changes. By design, it supports situations where
|
|
34
|
+
* the extension is frequently restarted; in other words, it is
|
|
35
|
+
* designed to work in an empheral service worker model and
|
|
36
|
+
* does not required a persistent background.
|
|
37
|
+
*
|
|
38
|
+
* The current implementation assumes that the "update" function
|
|
39
|
+
* gets triggered frequently enough to check for new patterns
|
|
40
|
+
* within the configured intervals.
|
|
41
|
+
*/
|
|
42
|
+
export default class PatternsUpdater {
|
|
43
|
+
constructor({ config, patterns, storage, storageKey }) {
|
|
44
|
+
this.patterns = patterns;
|
|
45
|
+
this.storage = storage;
|
|
46
|
+
this.storageKey = storageKey;
|
|
47
|
+
this.patternUpdateUrl = config.PATTERNS_URL;
|
|
48
|
+
if (!this.patternUpdateUrl) {
|
|
49
|
+
logger.warn(
|
|
50
|
+
'PATTERNS_URL is not configured. Pattern updates will be skipped and empty patterns will be used instead.',
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Update intervals:
|
|
55
|
+
// 1) standard polling interval
|
|
56
|
+
// (it can be configured conservatively to save bandwidth)
|
|
57
|
+
this.defaultUpdateInterval = {
|
|
58
|
+
min: 8 * HOUR,
|
|
59
|
+
max: 24 * HOUR,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// 2) accelerated polling intervals
|
|
63
|
+
// It can happen that a pattern update is followed quickly by another one;
|
|
64
|
+
// so, temporarily switch to a faster polling frequency to see these
|
|
65
|
+
// as fast as possible. It is desirable that clients do not fall into
|
|
66
|
+
// different populations with different patterns version.
|
|
67
|
+
this.fastUpdateInterval = {
|
|
68
|
+
min: 30 * MINUTE,
|
|
69
|
+
max: 2 * HOUR,
|
|
70
|
+
};
|
|
71
|
+
this._initEmptyCache();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
_initEmptyCache() {
|
|
75
|
+
this._persistedState = {
|
|
76
|
+
patterns: null, // string (unmodified as it came from the server)
|
|
77
|
+
skipAttemptsUntil: 0, // Unix epoch
|
|
78
|
+
lastFetchAttempt: 0, // Unix epoch
|
|
79
|
+
lastConfirmedModification: 0, // Unix epoch
|
|
80
|
+
failedAttemptsInARow: 0,
|
|
81
|
+
dbVersion: DB_VERSION,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async _savePersistedState() {
|
|
86
|
+
return this.storage.set(this.storageKey, this._persistedState);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async init({ now = Date.now() } = {}) {
|
|
90
|
+
let force = false;
|
|
91
|
+
try {
|
|
92
|
+
let persistedState = await this.storage.get(this.storageKey);
|
|
93
|
+
if (persistedState && persistedState.dbVersion !== DB_VERSION) {
|
|
94
|
+
logger.info('DB_VERSION changed. Discarding the cache...');
|
|
95
|
+
persistedState = null;
|
|
96
|
+
}
|
|
97
|
+
if (persistedState && !this._timestampsLookValid(persistedState, now)) {
|
|
98
|
+
logger.warn(
|
|
99
|
+
'The timestamps in the pattern cache show indications that the system clock was off. Discarding the cache:',
|
|
100
|
+
persistedState,
|
|
101
|
+
);
|
|
102
|
+
persistedState = null;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (persistedState) {
|
|
106
|
+
if (persistedState.patterns) {
|
|
107
|
+
this.patterns.updatePatterns(JSON.parse(persistedState.patterns));
|
|
108
|
+
}
|
|
109
|
+
this._persistedState = persistedState;
|
|
110
|
+
} else {
|
|
111
|
+
logger.info(
|
|
112
|
+
'Pattern cache does not exist. This should only happen on the first time the extension is started.',
|
|
113
|
+
);
|
|
114
|
+
force = true;
|
|
115
|
+
}
|
|
116
|
+
} catch (e) {
|
|
117
|
+
logger.warn(
|
|
118
|
+
'Failed to load cached patterns from disk. Forcing an update.',
|
|
119
|
+
);
|
|
120
|
+
force = true;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
try {
|
|
124
|
+
await this.update({ force, now });
|
|
125
|
+
} catch (e) {
|
|
126
|
+
logger.warn('Failed to fetch patterns', e);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Poll for pattern updates. It will block until the update operation
|
|
132
|
+
* is finished.
|
|
133
|
+
*
|
|
134
|
+
* Cooldowns:
|
|
135
|
+
* ----------
|
|
136
|
+
* To make this function easier to use, the caller is not responsible
|
|
137
|
+
* for throttling updates. In fact, it is better if the update function
|
|
138
|
+
* is called as often as possible.
|
|
139
|
+
*
|
|
140
|
+
* Error handling:
|
|
141
|
+
* ---------------
|
|
142
|
+
* It is not the responsibility of the caller to schedule retry attemps,
|
|
143
|
+
* but only to guarantee that the "update" function is called regurarily.
|
|
144
|
+
* As it is generally not useful to learn about failure, the returned
|
|
145
|
+
* promise will always resolve. But if you want to know whether it really
|
|
146
|
+
* succeeded or not - for logging or debugging purposes - you can overwrite
|
|
147
|
+
* the default by passing the "ignoreError" flag.
|
|
148
|
+
*/
|
|
149
|
+
async update({ force = false, ignoreErrors = true, now = Date.now() } = {}) {
|
|
150
|
+
try {
|
|
151
|
+
await this._update({ force, now });
|
|
152
|
+
} catch (e) {
|
|
153
|
+
if (!ignoreErrors) {
|
|
154
|
+
throw e;
|
|
155
|
+
}
|
|
156
|
+
logger.debug('Failed to update patterns. It is safe to continue.');
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async _update({ force = false, now = Date.now() } = {}) {
|
|
161
|
+
const url = this.patternUpdateUrl;
|
|
162
|
+
if (!url) {
|
|
163
|
+
logger.debug('Pattern updates skipped (update URL not configured)');
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (!force && now < this._persistedState.skipAttemptsUntil) {
|
|
168
|
+
logger.debug(
|
|
169
|
+
'Cooldown not reached yet. Need to wait until',
|
|
170
|
+
this._persistedState.skipAttemptsUntil,
|
|
171
|
+
'before updating patterns again.',
|
|
172
|
+
);
|
|
173
|
+
if (this._persistedState.failedAttemptsInARow > 0) {
|
|
174
|
+
throw new Error(
|
|
175
|
+
'Unable to fetch patterns. Need to wait for the cooldown to finish before retrying...',
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const otherUpdate = this._pendingUpdate;
|
|
182
|
+
if (otherUpdate) {
|
|
183
|
+
logger.debug('Pattern update already in progress...');
|
|
184
|
+
await otherUpdate;
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
let done;
|
|
189
|
+
this._pendingUpdate = new Promise((resolve) => {
|
|
190
|
+
done = resolve;
|
|
191
|
+
});
|
|
192
|
+
try {
|
|
193
|
+
this._persistedState.lastFetchAttempt = now;
|
|
194
|
+
const response = await fetch(url, {
|
|
195
|
+
method: 'GET',
|
|
196
|
+
cache: 'no-cache',
|
|
197
|
+
credentials: 'omit',
|
|
198
|
+
});
|
|
199
|
+
if (!response.ok) {
|
|
200
|
+
throw new Error(
|
|
201
|
+
`Failed to fetch patterns (${response.statusText}) from url=${url}`,
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
const newPatterns = await response.text();
|
|
205
|
+
const rules = JSON.parse(newPatterns);
|
|
206
|
+
|
|
207
|
+
// Bookkeeping to detect if the server just released an update.
|
|
208
|
+
// It is useful for debugging, but it also means we should
|
|
209
|
+
// temporarily poll more frequently for updates.
|
|
210
|
+
const oldPatterns = this._persistedState.patterns;
|
|
211
|
+
this._persistedState.patterns = newPatterns;
|
|
212
|
+
const detectedModification = oldPatterns && oldPatterns !== newPatterns;
|
|
213
|
+
if (detectedModification) {
|
|
214
|
+
logger.info('The server released new patterns:', rules);
|
|
215
|
+
this._persistedState.lastConfirmedModification = now;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// successful update: set cooldown
|
|
219
|
+
this._persistedState.failedAttemptsInARow = 0;
|
|
220
|
+
const { min, max } = detectedModification
|
|
221
|
+
? this.fastUpdateInterval
|
|
222
|
+
: this.defaultUpdateInterval;
|
|
223
|
+
this._persistedState.skipAttemptsUntil = now + randBetween(min, max);
|
|
224
|
+
|
|
225
|
+
// apply the pattern update
|
|
226
|
+
if (!oldPatterns || detectedModification) {
|
|
227
|
+
this.patterns.updatePatterns(rules);
|
|
228
|
+
}
|
|
229
|
+
} catch (e) {
|
|
230
|
+
// the update failed: we have to retry, but approximate an
|
|
231
|
+
// exponential backoff to prevent a burst HTTP calls.
|
|
232
|
+
this._persistedState.failedAttemptsInARow += 1;
|
|
233
|
+
const avgCooldown =
|
|
234
|
+
this._persistedState.failedAttemptsInARow * (10 * SECOND);
|
|
235
|
+
const noisyCooldown = randBetween(avgCooldown / 1.5, 1.5 * avgCooldown);
|
|
236
|
+
const finalCooldown = clamp({
|
|
237
|
+
value: noisyCooldown,
|
|
238
|
+
min: 3 * SECOND,
|
|
239
|
+
max: 8 * HOUR,
|
|
240
|
+
});
|
|
241
|
+
this._persistedState.skipAttemptsUntil = now + finalCooldown;
|
|
242
|
+
logger.warn(
|
|
243
|
+
'Failed to fetch pattern. Cooldown until:',
|
|
244
|
+
new Date(this._persistedState.skipAttemptsUntil),
|
|
245
|
+
e,
|
|
246
|
+
);
|
|
247
|
+
throw e;
|
|
248
|
+
} finally {
|
|
249
|
+
try {
|
|
250
|
+
await this._savePersistedState();
|
|
251
|
+
} catch (e) {
|
|
252
|
+
logger.warn('Failed to update patterns cache.', e);
|
|
253
|
+
}
|
|
254
|
+
this._pendingUpdate = null;
|
|
255
|
+
done();
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Run some sanity checks on the timestamps. If any of the timestamps
|
|
261
|
+
* were produced from a clock that was in the future, updates will
|
|
262
|
+
* stop working. If we detect such a case, we should purge the cache
|
|
263
|
+
* and start from scratch.
|
|
264
|
+
*
|
|
265
|
+
* Staying forever on outdated patterns would also increase the risk
|
|
266
|
+
* of sticking out from the crowd.
|
|
267
|
+
*/
|
|
268
|
+
_timestampsLookValid(persistedState, now = Date.now()) {
|
|
269
|
+
const maxCooldown = Math.max(
|
|
270
|
+
this.defaultUpdateInterval.min,
|
|
271
|
+
this.defaultUpdateInterval.max,
|
|
272
|
+
this.fastUpdateInterval.min,
|
|
273
|
+
this.fastUpdateInterval.max,
|
|
274
|
+
);
|
|
275
|
+
|
|
276
|
+
// Small jumps are not a concern (some minutes). But it becomes a
|
|
277
|
+
// problem if the clock jumped too in the future (months).
|
|
278
|
+
// The systems were the system clock is off are rare, but they
|
|
279
|
+
// can happen (e.g. https://github.com/systemd/systemd/issues/6036).
|
|
280
|
+
const allowedDrift = 5 * MINUTE;
|
|
281
|
+
const isOK = (ts) => ts < now + allowedDrift;
|
|
282
|
+
|
|
283
|
+
return (
|
|
284
|
+
isOK(persistedState.skipAttemptsUntil - maxCooldown) &&
|
|
285
|
+
isOK(persistedState.lastConfirmedModification) &&
|
|
286
|
+
isOK(persistedState.lastFetchAttempt)
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
async selfChecks(check = new SelfChecks()) {
|
|
291
|
+
if (this._persistedState.failedAttemptsInARow > 0) {
|
|
292
|
+
check.warn('unable to update patterns', {
|
|
293
|
+
errorsInARow: this._persistedState.failedAttemptsInARow,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const patternAge = Date.now() - this._persistedState.lastFetchAttempt;
|
|
298
|
+
if (patternAge > this.defaultUpdateInterval.max) {
|
|
299
|
+
check.fail('patterns are outdated', {
|
|
300
|
+
ageInHours: patternAge / HOUR,
|
|
301
|
+
maxAgeInHours: this.defaultUpdateInterval.max / HOUR,
|
|
302
|
+
});
|
|
303
|
+
} else {
|
|
304
|
+
check.pass('patterns are up to date', {
|
|
305
|
+
lastUpdated: `${patternAge / HOUR} hours ago`,
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
return check;
|
|
309
|
+
}
|
|
310
|
+
}
|