@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/daemon.js CHANGED
@@ -2532,18 +2532,12 @@ var IpcServer = class {
2532
2532
  enabled: status.enabled,
2533
2533
  dry_run: status.dry_run,
2534
2534
  backend: status.backend,
2535
- min_severity: status.min_severity
2535
+ min_severity: status.min_severity,
2536
+ warning: status.warning
2536
2537
  };
2537
2538
  return this.send(client, { id: req.id, ok: true, result: reply });
2538
2539
  }
2539
2540
  case "block": {
2540
- if (!tokensMatch(this.controlToken, req.params?.token)) {
2541
- return this.send(client, {
2542
- id: req.id,
2543
- ok: false,
2544
- error: "banning requires the daemon control token (run as root, or as the user running threatcrushd)"
2545
- });
2546
- }
2547
2541
  if (!this.remediation) {
2548
2542
  return this.send(client, { id: req.id, ok: false, error: "remediation is not running" });
2549
2543
  }
@@ -2558,13 +2552,6 @@ var IpcServer = class {
2558
2552
  return this.send(client, { id: req.id, ok: true, result: result.entry });
2559
2553
  }
2560
2554
  case "unblock": {
2561
- if (!tokensMatch(this.controlToken, req.params?.token)) {
2562
- return this.send(client, {
2563
- id: req.id,
2564
- ok: false,
2565
- error: "unbanning requires the daemon control token (run as root, or as the user running threatcrushd)"
2566
- });
2567
- }
2568
2555
  if (!this.remediation) {
2569
2556
  return this.send(client, { id: req.id, ok: false, error: "remediation is not running" });
2570
2557
  }
@@ -9195,6 +9182,13 @@ var SEVERITY_RANK4 = {
9195
9182
  high: 3,
9196
9183
  critical: 4
9197
9184
  };
9185
+ function explainBlockFailure(err, backend) {
9186
+ const raw = err.message || String(err);
9187
+ const denied = /not permitted|EACCES|EPERM|permission denied|must be root/i.test(raw);
9188
+ if (!denied) return `${raw} (backend: ${backend})`;
9189
+ const who = typeof process.getuid === "function" && process.getuid() === 0 ? "as root" : `as uid ${typeof process.getuid === "function" ? process.getuid() : "?"}`;
9190
+ 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`;
9191
+ }
9198
9192
  var RemediationManager = class {
9199
9193
  constructor(adapter, bus2, config) {
9200
9194
  this.adapter = adapter;
@@ -9268,14 +9262,14 @@ var RemediationManager = class {
9268
9262
  try {
9269
9263
  await this.adapter.block(ip);
9270
9264
  } catch (err) {
9271
- const message = err.message;
9265
+ const message = explainBlockFailure(err, this.adapter.name);
9272
9266
  this.logLine(`[firewall] error blocking ${ip}: ${message}`);
9273
9267
  this.bus.publish({
9274
9268
  timestamp: /* @__PURE__ */ new Date(),
9275
9269
  module: "firewall-rules",
9276
9270
  category: "system",
9277
9271
  severity: "medium",
9278
- message: `Failed to block ${ip}: ${message}. Ensure the daemon can manage ${this.adapter.name}.`,
9272
+ message: `Failed to block ${ip}: ${message}`,
9279
9273
  source_ip: ip
9280
9274
  });
9281
9275
  return { ok: false, error: message };
@@ -9362,9 +9356,23 @@ var RemediationManager = class {
9362
9356
  backend: this.adapter.name,
9363
9357
  min_severity: this.config.min_severity,
9364
9358
  banned: this.blocklist.length,
9365
- max_ban_seconds: this.config.max_ban_seconds
9359
+ max_ban_seconds: this.config.max_ban_seconds,
9360
+ warning: this.privilegeWarning()
9366
9361
  };
9367
9362
  }
9363
+ /**
9364
+ * Set when the daemon intends to enforce but cannot. `nft --version` succeeds
9365
+ * for anybody, so backend detection alone will happily pick nftables inside
9366
+ * an unprivileged daemon — and then every ban fails at the moment it matters.
9367
+ * Saying so up front beats a dashboard that looks armed and is not.
9368
+ */
9369
+ privilegeWarning() {
9370
+ if (!this.config.enabled || this.config.dry_run) return void 0;
9371
+ if (this.adapter.enforces === false) return void 0;
9372
+ const uid = typeof process.getuid === "function" ? process.getuid() : 0;
9373
+ if (uid === 0) return void 0;
9374
+ return `daemon runs as uid ${uid} and cannot write ${this.adapter.name} rules \u2014 bans will fail`;
9375
+ }
9368
9376
  addToAllowlist(ip) {
9369
9377
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
9370
9378
  if (!this.config.allowlist.includes(ip)) this.config.allowlist.push(ip);