@profullstack/threatcrush 0.15.0 → 0.15.1
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/dist/daemon.js +23 -9
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +23 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -57009,11 +57009,14 @@ function buildFeedSet(parts, allow, sources, now = /* @__PURE__ */ new Date()) {
|
|
|
57009
57009
|
}
|
|
57010
57010
|
return { fetched_at: now.toISOString(), ips, domains, sources, skipped_shared: skipped };
|
|
57011
57011
|
}
|
|
57012
|
+
var FETCH_ATTEMPTS = 3;
|
|
57013
|
+
var FatalFeedError = class extends Error {
|
|
57014
|
+
};
|
|
57012
57015
|
function redact(message, key) {
|
|
57013
57016
|
if (!key) return message;
|
|
57014
57017
|
return message.split(key).join("<auth-key>").split(encodeURIComponent(key)).join("<auth-key>");
|
|
57015
57018
|
}
|
|
57016
|
-
async function fetchFeeds(settings, fetchImpl = fetch) {
|
|
57019
|
+
async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3) {
|
|
57017
57020
|
const sources = [];
|
|
57018
57021
|
const parts = [];
|
|
57019
57022
|
const key = settings.authKey?.trim() || void 0;
|
|
@@ -57025,13 +57028,24 @@ async function fetchFeeds(settings, fetchImpl = fetch) {
|
|
|
57025
57028
|
}
|
|
57026
57029
|
try {
|
|
57027
57030
|
const extra = request2.init?.headers ?? {};
|
|
57028
|
-
|
|
57029
|
-
|
|
57030
|
-
|
|
57031
|
-
|
|
57032
|
-
|
|
57033
|
-
|
|
57034
|
-
|
|
57031
|
+
let part;
|
|
57032
|
+
for (let attempt = 1; ; attempt++) {
|
|
57033
|
+
try {
|
|
57034
|
+
const res = await fetchImpl(request2.url, { ...request2.init, signal: AbortSignal.timeout(6e4), headers: { ...ua, ...extra } });
|
|
57035
|
+
if (res.status === 401 || res.status === 403) throw new FatalFeedError(`HTTP ${res.status}: abuse.ch refused the Auth-Key`);
|
|
57036
|
+
if (res.status >= 400 && res.status < 500) throw new FatalFeedError(`HTTP ${res.status}`);
|
|
57037
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
57038
|
+
const text = await res.text();
|
|
57039
|
+
const type = res.headers.get("content-type") ?? "";
|
|
57040
|
+
if (type.includes("text/html") || /^\s*<(!doctype|html)/i.test(text)) throw new FatalFeedError(`HTTP ${res.status} but an HTML page, not feed data`);
|
|
57041
|
+
part = parse3(text);
|
|
57042
|
+
break;
|
|
57043
|
+
} catch (err) {
|
|
57044
|
+
const retryable = !(err instanceof FatalFeedError) && !/^ThreatFox API: /.test(err.message);
|
|
57045
|
+
if (!retryable || attempt >= FETCH_ATTEMPTS) throw err;
|
|
57046
|
+
await new Promise((r) => setTimeout(r, retryDelayMs * attempt));
|
|
57047
|
+
}
|
|
57048
|
+
}
|
|
57035
57049
|
const count = (part.ips?.size ?? 0) + (part.domains?.size ?? 0);
|
|
57036
57050
|
if (count === 0 && !emptyOk) throw new Error("no entries in the response");
|
|
57037
57051
|
parts.push(part);
|
|
@@ -59680,7 +59694,7 @@ var ThreatFeeds = class {
|
|
|
59680
59694
|
}
|
|
59681
59695
|
async refresh() {
|
|
59682
59696
|
try {
|
|
59683
|
-
const set = await fetchFeeds(this.opts.settings, this.opts.fetchImpl);
|
|
59697
|
+
const set = await fetchFeeds(this.opts.settings, this.opts.fetchImpl, this.opts.retryDelayMs);
|
|
59684
59698
|
const failed = set.sources.filter((s) => !s.ok);
|
|
59685
59699
|
if (failed.length === set.sources.length) {
|
|
59686
59700
|
this.opts.log(`[threat-feeds] refresh failed, keeping previous list: ${failed.map((s) => `${s.feed}: ${s.error}`).join("; ")}`);
|