@profullstack/threatcrush 0.12.0 → 0.12.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/index.js CHANGED
@@ -10598,19 +10598,13 @@ var init_ipc_client = __esm({
10598
10598
  return this.request("blocklist");
10599
10599
  }
10600
10600
  /**
10601
- * Ban an address. The control token is read from disk here rather than by
10602
- * the caller, so the dashboard and the CLI go through the same gate.
10601
+ * Ban an address.
10603
10602
  */
10604
10603
  async block(ip, reason, ttl) {
10605
- return this.request("block", {
10606
- ip,
10607
- reason,
10608
- ttl,
10609
- token: readControlToken()
10610
- });
10604
+ return this.request("block", { ip, reason, ttl });
10611
10605
  }
10612
10606
  async unblock(ip, forget = true) {
10613
- return this.request("unblock", { ip, forget, token: readControlToken() });
10607
+ return this.request("unblock", { ip, forget });
10614
10608
  }
10615
10609
  async shutdown() {
10616
10610
  await this.request("shutdown", { token: readControlToken() });
@@ -10757,7 +10751,8 @@ function reducer(state, action) {
10757
10751
  enabled: action.reply.enabled,
10758
10752
  dry_run: action.reply.dry_run,
10759
10753
  backend: action.reply.backend,
10760
- min_severity: action.reply.min_severity
10754
+ min_severity: action.reply.min_severity,
10755
+ warning: action.reply.warning
10761
10756
  },
10762
10757
  banIndex
10763
10758
  };
@@ -11248,6 +11243,12 @@ function bansPanel(parent, state, theme, options) {
11248
11243
  panel.label("[remediation] enabled = false", { fg: theme.muted });
11249
11244
  return;
11250
11245
  }
11246
+ if (fw.warning) {
11247
+ panel.text("NOT PRIVILEGED", { fg: severityColors.critical, bold: true });
11248
+ panel.label(fw.warning, { fg: severityColors.high });
11249
+ panel.label("sudo threatcrush install-service", { fg: theme.muted });
11250
+ panel.spacer(1);
11251
+ }
11251
11252
  if (state.bans.length === 0) {
11252
11253
  panel.label("nothing banned", { fg: theme.muted });
11253
11254
  panel.label(fw.dry_run ? "dry-run: bans are simulated" : "bans: 1m \u2192 2m \u2192 3m \u2192 5m \u2192 8m", {
@@ -23293,18 +23294,12 @@ var IpcServer = class {
23293
23294
  enabled: status.enabled,
23294
23295
  dry_run: status.dry_run,
23295
23296
  backend: status.backend,
23296
- min_severity: status.min_severity
23297
+ min_severity: status.min_severity,
23298
+ warning: status.warning
23297
23299
  };
23298
23300
  return this.send(client, { id: req.id, ok: true, result: reply });
23299
23301
  }
23300
23302
  case "block": {
23301
- if (!tokensMatch(this.controlToken, req.params?.token)) {
23302
- return this.send(client, {
23303
- id: req.id,
23304
- ok: false,
23305
- error: "banning requires the daemon control token (run as root, or as the user running threatcrushd)"
23306
- });
23307
- }
23308
23303
  if (!this.remediation) {
23309
23304
  return this.send(client, { id: req.id, ok: false, error: "remediation is not running" });
23310
23305
  }
@@ -23319,13 +23314,6 @@ var IpcServer = class {
23319
23314
  return this.send(client, { id: req.id, ok: true, result: result.entry });
23320
23315
  }
23321
23316
  case "unblock": {
23322
- if (!tokensMatch(this.controlToken, req.params?.token)) {
23323
- return this.send(client, {
23324
- id: req.id,
23325
- ok: false,
23326
- error: "unbanning requires the daemon control token (run as root, or as the user running threatcrushd)"
23327
- });
23328
- }
23329
23317
  if (!this.remediation) {
23330
23318
  return this.send(client, { id: req.id, ok: false, error: "remediation is not running" });
23331
23319
  }
@@ -25440,6 +25428,13 @@ var SEVERITY_RANK4 = {
25440
25428
  high: 3,
25441
25429
  critical: 4
25442
25430
  };
25431
+ function explainBlockFailure(err, backend) {
25432
+ const raw = err.message || String(err);
25433
+ const denied = /not permitted|EACCES|EPERM|permission denied|must be root/i.test(raw);
25434
+ if (!denied) return `${raw} (backend: ${backend})`;
25435
+ const who = typeof process.getuid === "function" && process.getuid() === 0 ? "as root" : `as uid ${typeof process.getuid === "function" ? process.getuid() : "?"}`;
25436
+ return `threatcrushd is running ${who} and cannot manage ${backend}. A ban is written by the daemon, not by whoever asked for it \u2014 run the daemon as root: sudo threatcrush install-service && sudo systemctl enable --now threatcrushd`;
25437
+ }
25443
25438
  var RemediationManager = class {
25444
25439
  constructor(adapter, bus2, config) {
25445
25440
  this.adapter = adapter;
@@ -25513,14 +25508,14 @@ var RemediationManager = class {
25513
25508
  try {
25514
25509
  await this.adapter.block(ip);
25515
25510
  } catch (err) {
25516
- const message = err.message;
25511
+ const message = explainBlockFailure(err, this.adapter.name);
25517
25512
  this.logLine(`[firewall] error blocking ${ip}: ${message}`);
25518
25513
  this.bus.publish({
25519
25514
  timestamp: /* @__PURE__ */ new Date(),
25520
25515
  module: "firewall-rules",
25521
25516
  category: "system",
25522
25517
  severity: "medium",
25523
- message: `Failed to block ${ip}: ${message}. Ensure the daemon can manage ${this.adapter.name}.`,
25518
+ message: `Failed to block ${ip}: ${message}`,
25524
25519
  source_ip: ip
25525
25520
  });
25526
25521
  return { ok: false, error: message };
@@ -25607,9 +25602,23 @@ var RemediationManager = class {
25607
25602
  backend: this.adapter.name,
25608
25603
  min_severity: this.config.min_severity,
25609
25604
  banned: this.blocklist.length,
25610
- max_ban_seconds: this.config.max_ban_seconds
25605
+ max_ban_seconds: this.config.max_ban_seconds,
25606
+ warning: this.privilegeWarning()
25611
25607
  };
25612
25608
  }
25609
+ /**
25610
+ * Set when the daemon intends to enforce but cannot. `nft --version` succeeds
25611
+ * for anybody, so backend detection alone will happily pick nftables inside
25612
+ * an unprivileged daemon — and then every ban fails at the moment it matters.
25613
+ * Saying so up front beats a dashboard that looks armed and is not.
25614
+ */
25615
+ privilegeWarning() {
25616
+ if (!this.config.enabled || this.config.dry_run) return void 0;
25617
+ if (this.adapter.enforces === false) return void 0;
25618
+ const uid = typeof process.getuid === "function" ? process.getuid() : 0;
25619
+ if (uid === 0) return void 0;
25620
+ return `daemon runs as uid ${uid} and cannot write ${this.adapter.name} rules \u2014 bans will fail`;
25621
+ }
25613
25622
  addToAllowlist(ip) {
25614
25623
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
25615
25624
  if (!this.config.allowlist.includes(ip)) this.config.allowlist.push(ip);