@profullstack/threatcrush 0.15.1 → 0.15.2

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 CHANGED
@@ -17997,6 +17997,7 @@ function defaultGateways() {
17997
17997
  }
17998
17998
 
17999
17999
  // src/core/threat-feeds/index.ts
18000
+ var CARRY_MAX_MS = 24 * 36e5;
18000
18001
  var FEEDS = {
18001
18002
  /** POST `{ query: 'get_iocs', days }` with an `Auth-Key` header. */
18002
18003
  threatfoxApi: "https://threatfox-api.abuse.ch/api/v1/",
@@ -18227,7 +18228,7 @@ function redact(message, key) {
18227
18228
  if (!key) return message;
18228
18229
  return message.split(key).join("<auth-key>").split(encodeURIComponent(key)).join("<auth-key>");
18229
18230
  }
18230
- async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3) {
18231
+ async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3, previous = null, now = /* @__PURE__ */ new Date()) {
18231
18232
  const sources = [];
18232
18233
  const parts = [];
18233
18234
  const key = settings.authKey?.trim() || void 0;
@@ -18259,8 +18260,11 @@ async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3) {
18259
18260
  }
18260
18261
  const count = (part.ips?.size ?? 0) + (part.domains?.size ?? 0);
18261
18262
  if (count === 0 && !emptyOk) throw new Error("no entries in the response");
18263
+ for (const map of [part.ips, part.domains]) {
18264
+ for (const [k, ind] of map ?? []) map.set(k, { ...ind, source: feed });
18265
+ }
18262
18266
  parts.push(part);
18263
- sources.push({ feed, ok: true, count });
18267
+ sources.push({ feed, ok: true, count, last_ok_at: now.toISOString() });
18264
18268
  } catch (err) {
18265
18269
  sources.push({ feed, ok: false, count: 0, error: redact(err.message, key) });
18266
18270
  }
@@ -18280,8 +18284,26 @@ async function fetchFeeds(settings, fetchImpl = fetch, retryDelayMs = 5e3) {
18280
18284
  // Feodo has been near-empty since 2025; an empty list there is real.
18281
18285
  get2("feodo", { url: FEEDS.feodoIps }, (t) => ({ ips: parseIpList(t, "feodo") }), true)
18282
18286
  ]);
18287
+ carryForward(previous, sources, parts, now);
18283
18288
  sources.sort((a, b) => a.feed.localeCompare(b.feed));
18284
- return buildFeedSet(parts, settings.allow, sources);
18289
+ return buildFeedSet(parts, settings.allow, sources, now);
18290
+ }
18291
+ function carryForward(previous, sources, parts, now) {
18292
+ if (!previous) return;
18293
+ for (const s of sources) {
18294
+ if (s.ok || s.error === NEEDS_KEY) continue;
18295
+ const prev = previous.sources?.find((p) => p.feed === s.feed);
18296
+ const lastOk = prev?.last_ok_at;
18297
+ if (!lastOk || now.getTime() - Date.parse(lastOk) > CARRY_MAX_MS) continue;
18298
+ const part = { ips: /* @__PURE__ */ new Map(), domains: /* @__PURE__ */ new Map() };
18299
+ for (const [ip, ind] of Object.entries(previous.ips)) if (ind.source === s.feed) part.ips.set(ip, ind);
18300
+ for (const [d, ind] of Object.entries(previous.domains)) if (ind.source === s.feed) part.domains.set(d, ind);
18301
+ const kept = part.ips.size + part.domains.size;
18302
+ s.last_ok_at = lastOk;
18303
+ if (!kept) continue;
18304
+ parts.push(part);
18305
+ s.carried = kept;
18306
+ }
18285
18307
  }
18286
18308
  function readFeedCache(path) {
18287
18309
  try {
@@ -26925,7 +26947,7 @@ var ThreatFeeds = class {
26925
26947
  }
26926
26948
  async refresh() {
26927
26949
  try {
26928
- const set = await fetchFeeds(this.opts.settings, this.opts.fetchImpl, this.opts.retryDelayMs);
26950
+ const set = await fetchFeeds(this.opts.settings, this.opts.fetchImpl, this.opts.retryDelayMs, this.set, new Date(this.now()));
26929
26951
  const failed = set.sources.filter((s) => !s.ok);
26930
26952
  if (failed.length === set.sources.length) {
26931
26953
  this.opts.log(`[threat-feeds] refresh failed, keeping previous list: ${failed.map((s) => `${s.feed}: ${s.error}`).join("; ")}`);
@@ -26953,7 +26975,7 @@ var ThreatFeeds = class {
26953
26975
  this.blocking = ok;
26954
26976
  mode = ok ? "blocking egress" : "detecting (nft load failed)";
26955
26977
  }
26956
- const failed = (set.sources ?? []).filter((s) => !s.ok).map((s) => s.feed);
26978
+ const failed = (set.sources ?? []).filter((s) => !s.ok).map((s) => s.carried ? `${s.feed}: kept ${s.carried} from ${s.last_ok_at?.slice(11, 16)} UTC` : s.feed);
26957
26979
  const failing = failed.length ? `; ${failed.length}/${set.sources.length} feeds failing (${failed.join(", ")}), see \`threatcrush feeds\`` : "";
26958
26980
  const detail = `${ips.length} IPs, ${domains} domains, ${mode}${this.writeResolverFiles(set)}${failing}`;
26959
26981
  this.opts.log(`[threat-feeds] ${from === "cache" ? "loaded cached" : "refreshed"} list: ${detail} (${set.skipped_shared} shared/protected entries skipped)`);