@profullstack/threatcrush 0.13.78 → 0.13.79

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
@@ -2026,7 +2026,7 @@ var require_toml = __commonJS({
2026
2026
  });
2027
2027
 
2028
2028
  // src/daemon/index.ts
2029
- var import_node_fs38 = require("fs");
2029
+ var import_node_fs39 = require("fs");
2030
2030
  var import_node_child_process14 = require("child_process");
2031
2031
  var import_node_os6 = require("os");
2032
2032
  var import_node_path30 = require("path");
@@ -9495,13 +9495,13 @@ var CrsEngine = class {
9495
9495
  }
9496
9496
  return hits;
9497
9497
  }
9498
- assess(request) {
9498
+ assess(request2) {
9499
9499
  const ctx = new RequestContext({
9500
- method: request.method,
9501
- uri: asBytes(request.uri),
9502
- protocol: request.protocol,
9503
- userAgent: asBytes(request.userAgent),
9504
- referer: asBytes(request.referer)
9500
+ method: request2.method,
9501
+ uri: asBytes(request2.uri),
9502
+ protocol: request2.protocol,
9503
+ userAgent: asBytes(request2.userAgent),
9504
+ referer: asBytes(request2.referer)
9505
9505
  });
9506
9506
  const hit = new Uint8Array(this.rules.length);
9507
9507
  for (const [target, rules] of this.byTarget) {
@@ -9574,9 +9574,9 @@ function parseCaddyAccessLog(line) {
9574
9574
  return null;
9575
9575
  }
9576
9576
  if (typeof entry.logger !== "string" || !/^http\.log\.access(?:\.log\d+)?$/.test(entry.logger)) return null;
9577
- const request = entry.request;
9578
- if (!request || typeof request !== "object" || Array.isArray(request)) return null;
9579
- const req = request;
9577
+ const request2 = entry.request;
9578
+ if (!request2 || typeof request2 !== "object" || Array.isArray(request2)) return null;
9579
+ const req = request2;
9580
9580
  const host = typeof req.host === "string" ? req.host.toLowerCase() : "";
9581
9581
  if (host !== "agent.database.pit.world") return null;
9582
9582
  const required = [req.method, req.uri, entry.status, entry.size];
@@ -11256,6 +11256,7 @@ function parseConfigText(raw) {
11256
11256
  file_integrity: parsed.file_integrity,
11257
11257
  edr: parsed.edr,
11258
11258
  lightning: parsed.lightning,
11259
+ docker_logs: parsed.docker_logs,
11259
11260
  storage: parsed.storage,
11260
11261
  // TOML's `[abuse-reporter]` parses to a hyphenated key; expose it under
11261
11262
  // the JS-friendly name the rest of the daemon reads.
@@ -20303,10 +20304,307 @@ var LightningWatch = class {
20303
20304
  }
20304
20305
  };
20305
20306
 
20306
- // src/core/tor-exits.ts
20307
+ // src/daemon/workers/docker-logs.ts
20307
20308
  var import_node_fs32 = require("fs");
20308
- var import_node_path25 = require("path");
20309
+ var import_node_http = require("http");
20309
20310
  var import_node_net12 = require("net");
20311
+ var DEFAULT_DOCKER_SOCKET = "/var/run/docker.sock";
20312
+ var DEFAULT_NAME_PATTERN = "supabase-db$";
20313
+ var DEFAULT_IMAGE_PATTERN = "(^|/)postgres(:|@|$)";
20314
+ function regexOr(source, fallback) {
20315
+ if (typeof source === "string" && source) {
20316
+ try {
20317
+ return new RegExp(source, "i");
20318
+ } catch {
20319
+ }
20320
+ }
20321
+ return new RegExp(fallback, "i");
20322
+ }
20323
+ function dockerLogsSettings(section) {
20324
+ const poll = Number(section?.poll_seconds);
20325
+ return {
20326
+ enabled: section?.enabled !== false,
20327
+ socket: typeof section?.socket === "string" && section.socket ? section.socket : DEFAULT_DOCKER_SOCKET,
20328
+ namePattern: regexOr(section?.name_pattern, DEFAULT_NAME_PATTERN),
20329
+ imagePattern: regexOr(section?.image_pattern, DEFAULT_IMAGE_PATTERN),
20330
+ pollMs: Number.isFinite(poll) && poll >= 2 ? poll * 1e3 : 15e3
20331
+ };
20332
+ }
20333
+ var PASSWORD_FAILED = /FATAL:\s+password authentication failed for user "([^"]*)"/;
20334
+ var HBA_REJECT = /FATAL:\s+no pg_hba\.conf entry for (?:replication connection from )?host "([^"]+)", user "([^"]*)"(?:, database "([^"]*)")?/;
20335
+ function cleanPgHost(raw) {
20336
+ if (!raw) return void 0;
20337
+ let host = raw.trim().replace(/\(\d+\)$/, "").replace(/^\[|\]$/g, "");
20338
+ if (/^::ffff:\d+\.\d+\.\d+\.\d+$/i.test(host)) host = host.slice(7);
20339
+ return (0, import_node_net12.isIP)(host) ? host : void 0;
20340
+ }
20341
+ function prefixHost(line) {
20342
+ const first = cleanPgHost(line.split(/\s/, 1)[0]);
20343
+ if (first) return first;
20344
+ const m = /\b(?:host|client|remote)=(\S+?)[\s,]/.exec(line);
20345
+ return cleanPgHost(m?.[1]);
20346
+ }
20347
+ function parsePostgresAuthFailure(line) {
20348
+ const hba = HBA_REJECT.exec(line);
20349
+ if (hba) {
20350
+ return {
20351
+ kind: "pg_hba",
20352
+ ip: cleanPgHost(hba[1]) ?? prefixHost(line),
20353
+ user: hba[2],
20354
+ ...hba[3] !== void 0 ? { database: hba[3] } : {}
20355
+ };
20356
+ }
20357
+ const pw = PASSWORD_FAILED.exec(line);
20358
+ if (pw) {
20359
+ const ip = prefixHost(line);
20360
+ const db2 = /\s([^\s@]+)@([^\s@]+)\s+FATAL:/.exec(line);
20361
+ return { kind: "password", ...ip ? { ip } : {}, user: pw[1], ...db2 ? { database: db2[2] } : {} };
20362
+ }
20363
+ return null;
20364
+ }
20365
+ function isUnbannableSource(ip, protectedList = []) {
20366
+ return isProtected(ip, [...DEFAULT_PROTECTED, ...protectedList]);
20367
+ }
20368
+ function postgresAuthEvent(line, container, protectedList = [], now = /* @__PURE__ */ new Date()) {
20369
+ const failure = parsePostgresAuthFailure(line);
20370
+ if (!failure?.ip) return null;
20371
+ if (isUnbannableSource(failure.ip, protectedList)) return null;
20372
+ const who = `user "${failure.user ?? ""}"${failure.database !== void 0 ? ` database "${failure.database}"` : ""}`;
20373
+ const message = failure.kind === "password" ? `Postgres password authentication failed for ${who} from ${failure.ip} (${container})` : `Postgres connection rejected by pg_hba for ${who} from ${failure.ip} (${container})`;
20374
+ return {
20375
+ timestamp: now,
20376
+ module: "postgres-guard",
20377
+ category: "auth",
20378
+ // One failure is not an attack, and anything at the remediation floor
20379
+ // (`min_severity`, high by default) bans on its own. The rule decides.
20380
+ severity: "low",
20381
+ message,
20382
+ source_ip: failure.ip,
20383
+ details: {
20384
+ service: "postgres",
20385
+ container,
20386
+ kind: failure.kind,
20387
+ ...failure.user !== void 0 ? { user: failure.user } : {},
20388
+ ...failure.database !== void 0 ? { database: failure.database } : {},
20389
+ line: line.slice(0, 500)
20390
+ }
20391
+ };
20392
+ }
20393
+ var DockerLogDecoder = class {
20394
+ constructor(tty2, onLine) {
20395
+ this.tty = tty2;
20396
+ this.onLine = onLine;
20397
+ }
20398
+ tty;
20399
+ onLine;
20400
+ pending = Buffer.alloc(0);
20401
+ partial = /* @__PURE__ */ new Map();
20402
+ push(chunk) {
20403
+ if (this.tty) {
20404
+ this.text(1, chunk.toString("utf-8"));
20405
+ return;
20406
+ }
20407
+ this.pending = this.pending.length ? Buffer.concat([this.pending, chunk]) : chunk;
20408
+ while (this.pending.length >= 8) {
20409
+ const stream = this.pending[0];
20410
+ const size = this.pending.readUInt32BE(4);
20411
+ if (stream > 2 || this.pending[1] !== 0 || this.pending[2] !== 0 || this.pending[3] !== 0) {
20412
+ this.tty = true;
20413
+ const rest = this.pending;
20414
+ this.pending = Buffer.alloc(0);
20415
+ this.text(1, rest.toString("utf-8"));
20416
+ return;
20417
+ }
20418
+ if (this.pending.length < 8 + size) break;
20419
+ this.text(stream, this.pending.subarray(8, 8 + size).toString("utf-8"));
20420
+ this.pending = this.pending.subarray(8 + size);
20421
+ }
20422
+ }
20423
+ text(stream, text) {
20424
+ let buf = (this.partial.get(stream) ?? "") + text;
20425
+ let idx;
20426
+ while ((idx = buf.indexOf("\n")) >= 0) {
20427
+ const line = buf.slice(0, idx).replace(/\r$/, "");
20428
+ buf = buf.slice(idx + 1);
20429
+ if (line) this.onLine(line);
20430
+ }
20431
+ this.partial.set(stream, buf.length > 65536 ? "" : buf);
20432
+ }
20433
+ };
20434
+ function socketDeps(socketPath) {
20435
+ return {
20436
+ getJson: (path) => new Promise((resolve4, reject) => {
20437
+ const req = (0, import_node_http.request)({ socketPath, path, method: "GET", timeout: 1e4 }, (res) => {
20438
+ const chunks = [];
20439
+ res.on("data", (c) => chunks.push(c));
20440
+ res.on("end", () => {
20441
+ const body = Buffer.concat(chunks).toString("utf-8");
20442
+ if ((res.statusCode ?? 500) >= 300) return reject(new Error(`docker ${path}: HTTP ${res.statusCode} ${body.slice(0, 200)}`));
20443
+ try {
20444
+ resolve4(JSON.parse(body));
20445
+ } catch (err) {
20446
+ reject(err);
20447
+ }
20448
+ });
20449
+ res.on("error", reject);
20450
+ });
20451
+ req.on("timeout", () => req.destroy(new Error(`docker ${path}: timed out`)));
20452
+ req.on("error", reject);
20453
+ req.end();
20454
+ }),
20455
+ stream: (path, onData, onEnd) => {
20456
+ let ended = false;
20457
+ const end = () => {
20458
+ if (!ended) {
20459
+ ended = true;
20460
+ onEnd();
20461
+ }
20462
+ };
20463
+ const req = (0, import_node_http.request)({ socketPath, path, method: "GET" }, (res) => {
20464
+ if ((res.statusCode ?? 500) >= 300) {
20465
+ res.resume();
20466
+ end();
20467
+ return;
20468
+ }
20469
+ res.on("data", onData);
20470
+ res.on("end", end);
20471
+ res.on("close", end);
20472
+ res.on("error", end);
20473
+ });
20474
+ req.on("error", end);
20475
+ req.on("close", end);
20476
+ req.end();
20477
+ return req;
20478
+ }
20479
+ };
20480
+ }
20481
+ var DockerLogsWatch = class {
20482
+ constructor(opts) {
20483
+ this.opts = opts;
20484
+ this.deps = opts.deps ?? socketDeps(opts.settings.socket);
20485
+ }
20486
+ opts;
20487
+ follows = /* @__PURE__ */ new Map();
20488
+ /** When each container's stream last closed: a restart resumes from there. */
20489
+ closedAt = /* @__PURE__ */ new Map();
20490
+ timer = null;
20491
+ lastPoll = 0;
20492
+ stopped = false;
20493
+ deps;
20494
+ warned = false;
20495
+ /** False when off or there is no Docker here. */
20496
+ start() {
20497
+ const { settings } = this.opts;
20498
+ if (!settings.enabled) return false;
20499
+ if (!this.opts.deps && !(0, import_node_fs32.existsSync)(settings.socket)) return false;
20500
+ this.opts.log(`[docker-logs] following containers named /${settings.namePattern.source}/ or with image /${settings.imagePattern.source}/ for Postgres auth failures`);
20501
+ void this.poll();
20502
+ this.timer = setInterval(() => {
20503
+ void this.poll();
20504
+ }, settings.pollMs);
20505
+ this.timer.unref?.();
20506
+ return true;
20507
+ }
20508
+ stop() {
20509
+ this.stopped = true;
20510
+ if (this.timer) clearInterval(this.timer);
20511
+ this.timer = null;
20512
+ for (const f of this.follows.values()) {
20513
+ try {
20514
+ f.req.destroy();
20515
+ } catch {
20516
+ }
20517
+ }
20518
+ this.follows.clear();
20519
+ }
20520
+ /** Names of the containers being followed now. */
20521
+ following() {
20522
+ return [...this.follows.values()].map((f) => f.name).sort();
20523
+ }
20524
+ matches(c) {
20525
+ const name = (c.Names?.[0] ?? "").replace(/^\//, "");
20526
+ return this.opts.settings.namePattern.test(name) || this.opts.settings.imagePattern.test(c.Image ?? "");
20527
+ }
20528
+ /** One discovery pass: follow new or restarted matches, drop gone ones. */
20529
+ async poll() {
20530
+ if (this.stopped) return;
20531
+ const now = Date.now();
20532
+ const previous = this.lastPoll;
20533
+ let list;
20534
+ try {
20535
+ list = await this.deps.getJson("/containers/json");
20536
+ this.warned = false;
20537
+ } catch (err) {
20538
+ if (!this.warned) this.opts.log(`[docker-logs] cannot list containers: ${err.message}`);
20539
+ this.warned = true;
20540
+ return;
20541
+ }
20542
+ this.lastPoll = now;
20543
+ const running = /* @__PURE__ */ new Set();
20544
+ for (const c of Array.isArray(list) ? list : []) {
20545
+ if (!c?.Id || !this.matches(c)) continue;
20546
+ running.add(c.Id);
20547
+ if (this.follows.has(c.Id)) continue;
20548
+ const from = this.closedAt.get(c.Id) ?? (previous || now);
20549
+ await this.follow(c, from);
20550
+ }
20551
+ for (const [id, f] of this.follows) {
20552
+ if (!running.has(id)) {
20553
+ try {
20554
+ f.req.destroy();
20555
+ } catch {
20556
+ }
20557
+ this.follows.delete(id);
20558
+ }
20559
+ }
20560
+ for (const id of this.closedAt.keys()) if (!running.has(id)) this.closedAt.delete(id);
20561
+ }
20562
+ async follow(c, fromMs) {
20563
+ const name = (c.Names?.[0] ?? c.Id.slice(0, 12)).replace(/^\//, "");
20564
+ let tty2 = false;
20565
+ try {
20566
+ const info = await this.deps.getJson(`/containers/${c.Id}/json`);
20567
+ tty2 = info?.Config?.Tty === true;
20568
+ } catch {
20569
+ }
20570
+ if (this.stopped || this.follows.has(c.Id)) return;
20571
+ const since = Math.max(1, Math.floor(fromMs / 1e3));
20572
+ const decoder = new DockerLogDecoder(tty2, (line) => this.line(line, name));
20573
+ const req = this.deps.stream(
20574
+ `/containers/${c.Id}/logs?follow=1&stdout=1&stderr=1&since=${since}`,
20575
+ (chunk) => {
20576
+ try {
20577
+ decoder.push(chunk);
20578
+ } catch {
20579
+ }
20580
+ },
20581
+ () => {
20582
+ if (this.follows.get(c.Id)?.req === req) {
20583
+ this.follows.delete(c.Id);
20584
+ this.closedAt.set(c.Id, Date.now());
20585
+ }
20586
+ }
20587
+ );
20588
+ this.follows.set(c.Id, { req, name });
20589
+ this.opts.log(`[docker-logs] following ${name}`);
20590
+ }
20591
+ /** Exposed for tests and `rules test`: one container log line through the parser. */
20592
+ line(line, container) {
20593
+ const event = postgresAuthEvent(line, container, this.opts.protectedList ?? []);
20594
+ if (!event) return null;
20595
+ try {
20596
+ insertEvent(event);
20597
+ } catch {
20598
+ }
20599
+ this.opts.bus.publish(event);
20600
+ return event;
20601
+ }
20602
+ };
20603
+
20604
+ // src/core/tor-exits.ts
20605
+ var import_node_fs33 = require("fs");
20606
+ var import_node_path25 = require("path");
20607
+ var import_node_net13 = require("net");
20310
20608
  var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
20311
20609
  function parseTorExitList(text) {
20312
20610
  const out = /* @__PURE__ */ new Set();
@@ -20314,7 +20612,7 @@ function parseTorExitList(text) {
20314
20612
  const line = raw.trim();
20315
20613
  if (!line || line.startsWith("#")) continue;
20316
20614
  const ip = line.split(/\s+/)[0];
20317
- if ((0, import_node_net12.isIP)(ip)) out.add(normalizeIp(ip));
20615
+ if ((0, import_node_net13.isIP)(ip)) out.add(normalizeIp(ip));
20318
20616
  }
20319
20617
  return out;
20320
20618
  }
@@ -20373,10 +20671,10 @@ var TorExitList = class _TorExitList {
20373
20671
  }
20374
20672
  loadCache() {
20375
20673
  try {
20376
- if (!(0, import_node_fs32.existsSync)(this.opts.cachePath)) return false;
20377
- const parsed = parseTorExitList((0, import_node_fs32.readFileSync)(this.opts.cachePath, "utf-8"));
20674
+ if (!(0, import_node_fs33.existsSync)(this.opts.cachePath)) return false;
20675
+ const parsed = parseTorExitList((0, import_node_fs33.readFileSync)(this.opts.cachePath, "utf-8"));
20378
20676
  if (parsed.size === 0) return false;
20379
- this.load(parsed, (0, import_node_fs32.statSync)(this.opts.cachePath).mtimeMs);
20677
+ this.load(parsed, (0, import_node_fs33.statSync)(this.opts.cachePath).mtimeMs);
20380
20678
  this.log(`[tor] loaded ${parsed.size} Tor exit addresses from cache (${new Date(this.updatedAt).toISOString()})`);
20381
20679
  return true;
20382
20680
  } catch (err) {
@@ -20408,9 +20706,9 @@ var TorExitList = class _TorExitList {
20408
20706
  const before = this.exits.size;
20409
20707
  this.load(parsed);
20410
20708
  try {
20411
- (0, import_node_fs32.mkdirSync)((0, import_node_path25.dirname)(this.opts.cachePath), { recursive: true });
20412
- (0, import_node_fs32.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
20413
- (0, import_node_fs32.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
20709
+ (0, import_node_fs33.mkdirSync)((0, import_node_path25.dirname)(this.opts.cachePath), { recursive: true });
20710
+ (0, import_node_fs33.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
20711
+ (0, import_node_fs33.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
20414
20712
  } catch (err) {
20415
20713
  this.log(`[tor] could not save the exit list cache: ${err.message}`);
20416
20714
  }
@@ -20631,7 +20929,7 @@ var RuleEngine = class {
20631
20929
  };
20632
20930
 
20633
20931
  // src/daemon/rules/loader.ts
20634
- var import_node_fs33 = require("fs");
20932
+ var import_node_fs34 = require("fs");
20635
20933
  var import_node_path26 = require("path");
20636
20934
 
20637
20935
  // src/daemon/rules/default-rules.ts
@@ -21269,6 +21567,33 @@ var DEFAULT_RULES = [
21269
21567
  tags: ["agentdb", "rate-limit", "data-access"],
21270
21568
  remediation: { action: "alert", description: "Review AgentDB audit metadata for the token and request pattern" },
21271
21569
  enabled: true
21570
+ },
21571
+ {
21572
+ // 2026-11-20 dev2: ~10,150 failed `postgres` logins from ~60 addresses in
21573
+ // 72h against a Supabase Postgres published on 0.0.0.0, none banned. Fed by
21574
+ // docker-logs (`[docker_logs]`), which already drops private, Docker-bridge
21575
+ // and protected sources, so every event here names a public client.
21576
+ id: "postgres-auth-bruteforce",
21577
+ title: "Postgres Brute Force Detected",
21578
+ description: "Repeated Postgres password failures or pg_hba rejects from the same source",
21579
+ version: "1.0.0",
21580
+ category: "auth",
21581
+ severity: "high",
21582
+ source_types: ["postgres-guard"],
21583
+ match: {
21584
+ field: "message",
21585
+ operator: "regex",
21586
+ value: "^Postgres (?:password authentication failed|connection rejected by pg_hba) "
21587
+ },
21588
+ threshold: 5,
21589
+ window_seconds: 600,
21590
+ cooldown_seconds: 600,
21591
+ tags: ["postgres", "database", "brute-force", "credential-stuffing"],
21592
+ remediation: {
21593
+ action: "block",
21594
+ description: "Block source IP brute-forcing Postgres"
21595
+ },
21596
+ enabled: true
21272
21597
  }
21273
21598
  ];
21274
21599
 
@@ -21277,11 +21602,16 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
21277
21602
  function loadAllRules(customDir) {
21278
21603
  const rules = [...DEFAULT_RULES];
21279
21604
  const dir = customDir || RULES_DIR;
21280
- if ((0, import_node_fs33.existsSync)(dir)) {
21281
- const files = (0, import_node_fs33.readdirSync)(dir).filter((f) => f.endsWith(".json"));
21605
+ if ((0, import_node_fs34.existsSync)(dir)) {
21606
+ let files = [];
21607
+ try {
21608
+ files = (0, import_node_fs34.readdirSync)(dir).filter((f) => f.endsWith(".json"));
21609
+ } catch (err) {
21610
+ console.warn(`[rules] cannot read ${dir}: ${err.message}; custom rules not loaded`);
21611
+ }
21282
21612
  for (const file of files) {
21283
21613
  try {
21284
- const raw = (0, import_node_fs33.readFileSync)((0, import_node_path26.join)(dir, file), "utf-8");
21614
+ const raw = (0, import_node_fs34.readFileSync)((0, import_node_path26.join)(dir, file), "utf-8");
21285
21615
  const parsed = JSON.parse(raw);
21286
21616
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
21287
21617
  for (const rule of customRules) {
@@ -21313,23 +21643,23 @@ function loadAllRules(customDir) {
21313
21643
 
21314
21644
  // src/daemon/firewall/adapters.ts
21315
21645
  var import_node_child_process11 = require("child_process");
21316
- var import_node_fs34 = require("fs");
21646
+ var import_node_fs35 = require("fs");
21317
21647
  var import_node_path27 = require("path");
21318
- var import_node_net13 = require("net");
21648
+ var import_node_net14 = require("net");
21319
21649
  function assertValidFirewallIp(ip) {
21320
- if ((0, import_node_net13.isIP)(ip) !== 4) {
21650
+ if ((0, import_node_net14.isIP)(ip) !== 4) {
21321
21651
  throw new Error(`Invalid IPv4 address: ${ip}`);
21322
21652
  }
21323
21653
  }
21324
21654
  function assertBannableIp(ip) {
21325
- if ((0, import_node_net13.isIP)(ip) === 0) {
21655
+ if ((0, import_node_net14.isIP)(ip) === 0) {
21326
21656
  throw new Error(`Invalid IP address: ${ip}`);
21327
21657
  }
21328
21658
  }
21329
21659
  function writeIfAbsent(path, contents) {
21330
- (0, import_node_fs34.mkdirSync)((0, import_node_path27.dirname)(path), { recursive: true });
21660
+ (0, import_node_fs35.mkdirSync)((0, import_node_path27.dirname)(path), { recursive: true });
21331
21661
  try {
21332
- (0, import_node_fs34.writeFileSync)(path, contents, { flag: "wx" });
21662
+ (0, import_node_fs35.writeFileSync)(path, contents, { flag: "wx" });
21333
21663
  } catch (err) {
21334
21664
  if (err.code !== "EEXIST") throw err;
21335
21665
  }
@@ -21428,7 +21758,7 @@ var Fail2banAdapter = class {
21428
21758
  const status = this.client(["status", this.jail]);
21429
21759
  const line = status.split("\n").find((l) => /Banned IP list:/i.test(l));
21430
21760
  if (!line) return [];
21431
- return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net13.isIP)(s) !== 0);
21761
+ return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net14.isIP)(s) !== 0);
21432
21762
  } catch {
21433
21763
  return [];
21434
21764
  }
@@ -21438,10 +21768,10 @@ var Fail2banAdapter = class {
21438
21768
  function parseBannedList(output) {
21439
21769
  const found = [];
21440
21770
  for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
21441
- if ((0, import_node_net13.isIP)(match[1]) !== 0) found.push(match[1]);
21771
+ if ((0, import_node_net14.isIP)(match[1]) !== 0) found.push(match[1]);
21442
21772
  }
21443
21773
  if (found.length > 0) return found;
21444
- return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net13.isIP)(s) !== 0);
21774
+ return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net14.isIP)(s) !== 0);
21445
21775
  }
21446
21776
  var NftablesAdapter = class {
21447
21777
  name = "nftables";
@@ -21588,9 +21918,9 @@ function detectFirewallAdapter(backend = "auto") {
21588
21918
  }
21589
21919
 
21590
21920
  // src/daemon/firewall/remediation.ts
21591
- var import_node_fs35 = require("fs");
21921
+ var import_node_fs36 = require("fs");
21592
21922
  var import_node_child_process12 = require("child_process");
21593
- var import_node_net14 = require("net");
21923
+ var import_node_net15 = require("net");
21594
21924
 
21595
21925
  // src/daemon/firewall/crawlers.ts
21596
21926
  var import_node_dns2 = require("dns");
@@ -21658,19 +21988,19 @@ var defaultDiscovery = {
21658
21988
  const snapshot = takeSnapshot({
21659
21989
  readFile: (p) => {
21660
21990
  try {
21661
- return (0, import_node_fs35.readFileSync)(p, "utf-8");
21991
+ return (0, import_node_fs36.readFileSync)(p, "utf-8");
21662
21992
  } catch {
21663
21993
  return null;
21664
21994
  }
21665
21995
  },
21666
21996
  readDir: (p) => {
21667
21997
  try {
21668
- return (0, import_node_fs35.readdirSync)(p);
21998
+ return (0, import_node_fs36.readdirSync)(p);
21669
21999
  } catch {
21670
22000
  return null;
21671
22001
  }
21672
22002
  },
21673
- exists: (p) => (0, import_node_fs35.existsSync)(p)
22003
+ exists: (p) => (0, import_node_fs36.existsSync)(p)
21674
22004
  });
21675
22005
  const out = /* @__PURE__ */ new Set();
21676
22006
  for (const keys of Object.values(snapshot.keys)) {
@@ -21759,7 +22089,7 @@ var RemediationManager = class {
21759
22089
  setTorExitCheck(check) {
21760
22090
  this.isTorExit = check;
21761
22091
  let dropped = 0;
21762
- this.protectedList = this.protectedList.filter((a) => !(0, import_node_net14.isIP)(a) || !check(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
22092
+ this.protectedList = this.protectedList.filter((a) => !(0, import_node_net15.isIP)(a) || !check(a) || this.pinned.has(a) || this.config.allowlist.includes(a));
21763
22093
  for (const ip of Object.keys(this.operators)) {
21764
22094
  if (!check(ip)) continue;
21765
22095
  delete this.operators[ip];
@@ -21852,7 +22182,7 @@ var RemediationManager = class {
21852
22182
  if (remediation?.action !== "block") return;
21853
22183
  }
21854
22184
  const ip = event.source_ip;
21855
- if (!ip || (0, import_node_net14.isIP)(ip) === 0) return;
22185
+ if (!ip || (0, import_node_net15.isIP)(ip) === 0) return;
21856
22186
  const strict = remediation?.override_operator_protection === true;
21857
22187
  if (strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
21858
22188
  if (strict) this.logLine(`[remediation] not banning ${ip}: it is one of our own addresses (${event.message})`);
@@ -21881,7 +22211,7 @@ var RemediationManager = class {
21881
22211
  * 4th offence and so on, clamped to `max_ban_seconds`.
21882
22212
  */
21883
22213
  async ban(ip, reason, opts = {}) {
21884
- if ((0, import_node_net14.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
22214
+ if ((0, import_node_net15.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
21885
22215
  if (opts.strict ? this.isFleetAddress(ip) : this.isAllowlisted(ip)) {
21886
22216
  return { ok: false, error: `${ip} is protected and can never be blocked` };
21887
22217
  }
@@ -22158,7 +22488,7 @@ var RemediationManager = class {
22158
22488
  if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
22159
22489
  const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
22160
22490
  for (const [ip, at] of Object.entries(saved)) {
22161
- if (typeof at !== "number" || at < cutoff || !(0, import_node_net14.isIP)(ip)) continue;
22491
+ if (typeof at !== "number" || at < cutoff || !(0, import_node_net15.isIP)(ip)) continue;
22162
22492
  if (this.blocklist.some((b) => b.ip === ip && b.strict)) continue;
22163
22493
  this.operators[ip] = at;
22164
22494
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
@@ -22183,7 +22513,7 @@ var RemediationManager = class {
22183
22513
  }
22184
22514
  logLine(line) {
22185
22515
  try {
22186
- (0, import_node_fs35.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
22516
+ (0, import_node_fs36.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
22187
22517
  `);
22188
22518
  } catch {
22189
22519
  }
@@ -22223,11 +22553,11 @@ function remediationSettings(section) {
22223
22553
  }
22224
22554
 
22225
22555
  // src/daemon/watchdog-service.ts
22226
- var import_node_fs37 = require("fs");
22556
+ var import_node_fs38 = require("fs");
22227
22557
  var import_node_path29 = require("path");
22228
22558
 
22229
22559
  // src/core/watchdog.ts
22230
- var import_node_fs36 = require("fs");
22560
+ var import_node_fs37 = require("fs");
22231
22561
  var import_node_crypto9 = require("crypto");
22232
22562
  var import_node_path28 = require("path");
22233
22563
  var WATCHDOG_DIRNAME = "watchdog";
@@ -22320,10 +22650,10 @@ var WatchdogLog = class {
22320
22650
  this.dir = dir;
22321
22651
  this.file = (0, import_node_path28.join)(dir, LOG_FILE2);
22322
22652
  this.shareGid = options.shareGid;
22323
- (0, import_node_fs36.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
22653
+ (0, import_node_fs37.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
22324
22654
  if (this.shareGid !== void 0) {
22325
- (0, import_node_fs36.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
22326
- (0, import_node_fs36.chmodSync)(dir, 1528);
22655
+ (0, import_node_fs37.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
22656
+ (0, import_node_fs37.chmodSync)(dir, 1528);
22327
22657
  }
22328
22658
  for (const r of readTail(this.file, 512 * 1024)) this.remember(dedupeKey(r));
22329
22659
  }
@@ -22352,16 +22682,16 @@ var WatchdogLog = class {
22352
22682
  const chunk = this.buffer.join("\n") + "\n";
22353
22683
  this.buffer = [];
22354
22684
  try {
22355
- if ((0, import_node_fs36.statSync)(this.file).size > ROTATE_BYTES) {
22356
- (0, import_node_fs36.renameSync)(this.file, (0, import_node_path28.join)(this.dir, ROTATED_FILE));
22685
+ if ((0, import_node_fs37.statSync)(this.file).size > ROTATE_BYTES) {
22686
+ (0, import_node_fs37.renameSync)(this.file, (0, import_node_path28.join)(this.dir, ROTATED_FILE));
22357
22687
  }
22358
22688
  } catch {
22359
22689
  }
22360
- (0, import_node_fs36.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
22690
+ (0, import_node_fs37.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
22361
22691
  if (this.shareGid !== void 0) {
22362
22692
  try {
22363
- (0, import_node_fs36.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
22364
- (0, import_node_fs36.chmodSync)(this.file, 432);
22693
+ (0, import_node_fs37.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
22694
+ (0, import_node_fs37.chmodSync)(this.file, 432);
22365
22695
  } catch {
22366
22696
  }
22367
22697
  }
@@ -22382,21 +22712,21 @@ function parseLines(text) {
22382
22712
  function readTail(file, bytes) {
22383
22713
  let fd;
22384
22714
  try {
22385
- fd = (0, import_node_fs36.openSync)(file, "r");
22715
+ fd = (0, import_node_fs37.openSync)(file, "r");
22386
22716
  } catch (err) {
22387
22717
  if (err.code === "ENOENT") return [];
22388
22718
  throw err;
22389
22719
  }
22390
22720
  try {
22391
- const size = (0, import_node_fs36.fstatSync)(fd).size;
22721
+ const size = (0, import_node_fs37.fstatSync)(fd).size;
22392
22722
  const start = Math.max(0, size - bytes);
22393
22723
  const buf = Buffer.alloc(size - start);
22394
- (0, import_node_fs36.readSync)(fd, buf, 0, buf.length, start);
22724
+ (0, import_node_fs37.readSync)(fd, buf, 0, buf.length, start);
22395
22725
  let text = buf.toString("utf8");
22396
22726
  if (start > 0) text = text.slice(text.indexOf("\n") + 1);
22397
22727
  return parseLines(text);
22398
22728
  } finally {
22399
- (0, import_node_fs36.closeSync)(fd);
22729
+ (0, import_node_fs37.closeSync)(fd);
22400
22730
  }
22401
22731
  }
22402
22732
 
@@ -22405,7 +22735,7 @@ function defaultShareGid() {
22405
22735
  const isRoot2 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
22406
22736
  if (!isRoot2) return void 0;
22407
22737
  try {
22408
- return (0, import_node_fs37.statSync)("/var/log/auth.log").gid;
22738
+ return (0, import_node_fs38.statSync)("/var/log/auth.log").gid;
22409
22739
  } catch {
22410
22740
  return void 0;
22411
22741
  }
@@ -22518,7 +22848,7 @@ function daemonNodeProblem(version) {
22518
22848
  // src/daemon/index.ts
22519
22849
  function readVersion2() {
22520
22850
  try {
22521
- const pkg = JSON.parse((0, import_node_fs38.readFileSync)((0, import_node_path30.join)(__dirname, "..", "package.json"), "utf-8"));
22851
+ const pkg = JSON.parse((0, import_node_fs39.readFileSync)((0, import_node_path30.join)(__dirname, "..", "package.json"), "utf-8"));
22522
22852
  return pkg.version || "0.0.0";
22523
22853
  } catch {
22524
22854
  return "0.0.0";
@@ -22549,7 +22879,7 @@ async function runPatchCheck() {
22549
22879
  }
22550
22880
  function logLine(line) {
22551
22881
  try {
22552
- (0, import_node_fs38.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
22882
+ (0, import_node_fs39.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
22553
22883
  `);
22554
22884
  } catch {
22555
22885
  }
@@ -22719,6 +23049,13 @@ async function runDaemon() {
22719
23049
  log: logLine
22720
23050
  });
22721
23051
  lightningWatch.start();
23052
+ const dockerLogs = new DockerLogsWatch({
23053
+ bus,
23054
+ settings: dockerLogsSettings(config.docker_logs),
23055
+ protectedList: remediation.getAllowlist(),
23056
+ log: logLine
23057
+ });
23058
+ dockerLogs.start();
22722
23059
  let cloudSyncRef = null;
22723
23060
  new AlertDispatcher(bus, config, { cloudHealthy: () => cloudSyncRef?.healthy ?? false, log: logLine });
22724
23061
  if (loaded.error) {
@@ -22863,6 +23200,10 @@ async function runDaemon() {
22863
23200
  lightningWatch.stop();
22864
23201
  } catch {
22865
23202
  }
23203
+ try {
23204
+ dockerLogs.stop();
23205
+ } catch {
23206
+ }
22866
23207
  try {
22867
23208
  await ipc.stop();
22868
23209
  } catch {