@profullstack/threatcrush 0.13.59 → 0.13.61

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
@@ -1655,20 +1655,20 @@ var require_parse_async = __commonJS({
1655
1655
  const index = 0;
1656
1656
  const blocksize = opts.blocksize || 40960;
1657
1657
  const parser = new TOMLParser();
1658
- return new Promise((resolve7, reject) => {
1659
- setImmediate(parseAsyncNext, index, blocksize, resolve7, reject);
1658
+ return new Promise((resolve8, reject) => {
1659
+ setImmediate(parseAsyncNext, index, blocksize, resolve8, reject);
1660
1660
  });
1661
- function parseAsyncNext(index2, blocksize2, resolve7, reject) {
1661
+ function parseAsyncNext(index2, blocksize2, resolve8, reject) {
1662
1662
  if (index2 >= str3.length) {
1663
1663
  try {
1664
- return resolve7(parser.finish());
1664
+ return resolve8(parser.finish());
1665
1665
  } catch (err) {
1666
1666
  return reject(prettyError(err, str3));
1667
1667
  }
1668
1668
  }
1669
1669
  try {
1670
1670
  parser.parse(str3.slice(index2, index2 + blocksize2));
1671
- setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2, resolve7, reject);
1671
+ setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2, resolve8, reject);
1672
1672
  } catch (err) {
1673
1673
  reject(prettyError(err, str3));
1674
1674
  }
@@ -1694,7 +1694,7 @@ var require_parse_stream = __commonJS({
1694
1694
  function parseReadable(stm) {
1695
1695
  const parser = new TOMLParser();
1696
1696
  stm.setEncoding("utf8");
1697
- return new Promise((resolve7, reject) => {
1697
+ return new Promise((resolve8, reject) => {
1698
1698
  let readable;
1699
1699
  let ended = false;
1700
1700
  let errored = false;
@@ -1702,7 +1702,7 @@ var require_parse_stream = __commonJS({
1702
1702
  ended = true;
1703
1703
  if (readable) return;
1704
1704
  try {
1705
- resolve7(parser.finish());
1705
+ resolve8(parser.finish());
1706
1706
  } catch (err) {
1707
1707
  reject(err);
1708
1708
  }
@@ -16764,8 +16764,8 @@ var init_app = __esm({
16764
16764
  this.frame();
16765
16765
  }, interval);
16766
16766
  this.timer.unref?.();
16767
- await new Promise((resolve7) => {
16768
- this.exitResolve = resolve7;
16767
+ await new Promise((resolve8) => {
16768
+ this.exitResolve = resolve8;
16769
16769
  });
16770
16770
  }
16771
16771
  targetFps() {
@@ -17238,7 +17238,7 @@ var init_ipc_client = __esm({
17238
17238
  if (!(0, import_node_fs8.existsSync)(this.socketPath)) {
17239
17239
  throw new Error(`threatcrushd socket not found at ${this.socketPath}`);
17240
17240
  }
17241
- return new Promise((resolve7, reject) => {
17241
+ return new Promise((resolve8, reject) => {
17242
17242
  const sock = (0, import_node_net.createConnection)(this.socketPath);
17243
17243
  const timer = setTimeout(() => {
17244
17244
  sock.destroy();
@@ -17251,7 +17251,7 @@ var init_ipc_client = __esm({
17251
17251
  sock.on("data", (chunk2) => this.onData(chunk2.toString()));
17252
17252
  sock.on("close", () => this.onClose());
17253
17253
  sock.on("error", () => this.onClose());
17254
- resolve7();
17254
+ resolve8();
17255
17255
  });
17256
17256
  sock.once("error", (err) => {
17257
17257
  clearTimeout(timer);
@@ -17267,14 +17267,14 @@ var init_ipc_client = __esm({
17267
17267
  if (!this.socket) throw new Error("not connected");
17268
17268
  const id = this.nextId++;
17269
17269
  const frame = params ? { id, method, params } : { id, method };
17270
- return new Promise((resolve7, reject) => {
17270
+ return new Promise((resolve8, reject) => {
17271
17271
  const timer = setTimeout(() => {
17272
17272
  this.pending.delete(id);
17273
17273
  reject(new Error(
17274
17274
  `threatcrushd did not answer "${method}" within ${REQUEST_TIMEOUT_MS / 1e3}s; if it is older than this CLI, update it`
17275
17275
  ));
17276
17276
  }, REQUEST_TIMEOUT_MS);
17277
- this.pending.set(id, { resolve: resolve7, reject, timer });
17277
+ this.pending.set(id, { resolve: resolve8, reject, timer });
17278
17278
  this.socket.write(JSON.stringify(frame) + "\n", (err) => {
17279
17279
  if (err && this.pending.delete(id)) {
17280
17280
  clearTimeout(timer);
@@ -23426,8 +23426,8 @@ var source_default = chalk;
23426
23426
  // src/index.ts
23427
23427
  var import_readline = __toESM(require("readline"));
23428
23428
  var import_node_child_process24 = require("child_process");
23429
- var import_node_fs55 = require("fs");
23430
- var import_node_path42 = require("path");
23429
+ var import_node_fs56 = require("fs");
23430
+ var import_node_path43 = require("path");
23431
23431
  var import_node_os17 = require("os");
23432
23432
 
23433
23433
  // src/commands/monitor.ts
@@ -38664,8 +38664,8 @@ function askPiped(question, mask) {
38664
38664
  if (reader.lines.length > 0) return Promise.resolve(settle2(reader.lines.shift()));
38665
38665
  if (reader.ended) return Promise.resolve(settle2(null));
38666
38666
  reader.rl.resume();
38667
- return new Promise((resolve7) => {
38668
- reader.waiting = (line2) => resolve7(settle2(line2));
38667
+ return new Promise((resolve8) => {
38668
+ reader.waiting = (line2) => resolve8(settle2(line2));
38669
38669
  });
38670
38670
  }
38671
38671
  function askTerminal(question, mask) {
@@ -38673,20 +38673,20 @@ function askTerminal(question, mask) {
38673
38673
  cb();
38674
38674
  } }) : process.stdout;
38675
38675
  const rl = import_node_readline.default.createInterface({ input: process.stdin, output, terminal: true });
38676
- return new Promise((resolve7) => {
38676
+ return new Promise((resolve8) => {
38677
38677
  let settled = false;
38678
38678
  rl.on("close", () => {
38679
38679
  if (settled) return;
38680
38680
  settled = true;
38681
38681
  process.stdout.write("\n");
38682
- resolve7(null);
38682
+ resolve8(null);
38683
38683
  });
38684
38684
  if (mask) process.stdout.write(question);
38685
38685
  rl.question(mask ? "" : question, (answer) => {
38686
38686
  settled = true;
38687
38687
  rl.close();
38688
38688
  if (mask) process.stdout.write("\n");
38689
- resolve7(answer);
38689
+ resolve8(answer);
38690
38690
  });
38691
38691
  });
38692
38692
  }
@@ -38724,7 +38724,7 @@ async function startLinkLogin(pkce, deviceName = (0, import_node_os8.hostname)()
38724
38724
  }
38725
38725
  return data;
38726
38726
  }
38727
- var sleep = (ms) => new Promise((resolve7) => setTimeout(resolve7, ms));
38727
+ var sleep = (ms) => new Promise((resolve8) => setTimeout(resolve8, ms));
38728
38728
  async function waitForApproval(request, pkce, opts = {}) {
38729
38729
  const wait = opts.sleepMs ?? sleep;
38730
38730
  const now = opts.now ?? Date.now;
@@ -41084,9 +41084,9 @@ async function fetchOrgs() {
41084
41084
  }
41085
41085
  function askChoice(question) {
41086
41086
  const rl = import_node_readline2.default.createInterface({ input: process.stdin, output: process.stdout });
41087
- return new Promise((resolve7) => rl.question(question, (answer) => {
41087
+ return new Promise((resolve8) => rl.question(question, (answer) => {
41088
41088
  rl.close();
41089
- resolve7(answer.trim());
41089
+ resolve8(answer.trim());
41090
41090
  }));
41091
41091
  }
41092
41092
  async function chooseOrg(orgs, flag, ask2) {
@@ -41232,6 +41232,7 @@ var import_node_os12 = require("os");
41232
41232
  var import_node_fs26 = require("fs");
41233
41233
  var import_node_path22 = require("path");
41234
41234
  var import_node_child_process5 = require("child_process");
41235
+ var import_node_net3 = require("net");
41235
41236
  var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
41236
41237
  var CONFIG_PATH3 = (0, import_node_path22.join)((0, import_node_os12.homedir)(), ".threatcrush", "config.json");
41237
41238
  function readConfig2() {
@@ -41257,7 +41258,7 @@ async function connectCommand(options) {
41257
41258
  if (server) {
41258
41259
  await sshConnect({
41259
41260
  hostname: server.hostname || server.ip_address,
41260
- port: server.port,
41261
+ port: server.port || 22,
41261
41262
  username: user || server.ssh_username || null,
41262
41263
  identity
41263
41264
  });
@@ -41357,6 +41358,20 @@ async function resolveServer(nameOrSlug, orgSlug) {
41357
41358
  return null;
41358
41359
  }
41359
41360
  }
41361
+ var SSH_USER = /^[A-Za-z0-9_][A-Za-z0-9_.-]{0,63}$/;
41362
+ var SSH_HOST = /^(?=.{1,253}$)[A-Za-z0-9](?:[A-Za-z0-9-]{0,62}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,62}[A-Za-z0-9])?)*\.?$/;
41363
+ function sshTargetError(options) {
41364
+ if (!SSH_HOST.test(options.hostname) && (0, import_node_net3.isIP)(options.hostname) === 0) return `refusing unsafe hostname ${JSON.stringify(options.hostname)}`;
41365
+ if (!SSH_USER.test(options.username)) return `refusing unsafe ssh user ${JSON.stringify(options.username)}`;
41366
+ if (!Number.isInteger(options.port) || options.port < 1 || options.port > 65535) return `refusing port ${JSON.stringify(options.port)}`;
41367
+ return null;
41368
+ }
41369
+ function sshArgv(options) {
41370
+ const args = ["-p", String(options.port)];
41371
+ if (options.identity) args.push("-i", options.identity);
41372
+ args.push("--", `${options.username}@${options.hostname}`);
41373
+ return args;
41374
+ }
41360
41375
  async function sshConnect(options) {
41361
41376
  const { hostname: hostname5, port, username, identity } = options;
41362
41377
  if (!hostname5) {
@@ -41364,14 +41379,17 @@ async function sshConnect(options) {
41364
41379
  return;
41365
41380
  }
41366
41381
  const user = username || "root";
41382
+ const problem = sshTargetError({ hostname: hostname5, username: user, port });
41383
+ if (problem) {
41384
+ console.log(source_default.red(` ${problem}
41385
+ `));
41386
+ process.exitCode = 1;
41387
+ return;
41388
+ }
41367
41389
  console.log(source_default.green(` Connecting to ${user}@${hostname5}:${port}...
41368
41390
  `));
41369
41391
  console.log(source_default.dim(" (Spawning SSH session \u2014 exit with Ctrl+D or type 'exit')\n"));
41370
- const sshArgs = ["-p", String(port)];
41371
- if (identity) {
41372
- sshArgs.push("-i", identity);
41373
- }
41374
- sshArgs.push(`${user}@${hostname5}`);
41392
+ const sshArgs = sshArgv({ hostname: hostname5, username: user, port, identity });
41375
41393
  const ssh = (0, import_node_child_process5.spawn)("ssh", sshArgs, { stdio: "inherit" });
41376
41394
  ssh.on("error", (err) => {
41377
41395
  console.log(source_default.red(`
@@ -41391,20 +41409,20 @@ async function sshConnect(options) {
41391
41409
 
41392
41410
  // src/commands/daemon.ts
41393
41411
  var import_node_child_process17 = require("child_process");
41394
- var import_node_fs44 = require("fs");
41395
- var import_node_path34 = require("path");
41396
41412
  var import_node_fs45 = require("fs");
41413
+ var import_node_path35 = require("path");
41414
+ var import_node_fs46 = require("fs");
41397
41415
 
41398
41416
  // src/daemon/index.ts
41399
- var import_node_fs43 = require("fs");
41417
+ var import_node_fs44 = require("fs");
41400
41418
  var import_node_child_process16 = require("child_process");
41401
41419
  var import_node_os13 = require("os");
41402
- var import_node_path33 = require("path");
41420
+ var import_node_path34 = require("path");
41403
41421
  var import_node_util4 = require("util");
41404
41422
  init_paths();
41405
41423
 
41406
41424
  // src/daemon/ipc-server.ts
41407
- var import_node_net3 = require("net");
41425
+ var import_node_net4 = require("net");
41408
41426
  var import_node_fs27 = require("fs");
41409
41427
  init_paths();
41410
41428
  init_control_token();
@@ -41465,8 +41483,8 @@ var IpcServer = class {
41465
41483
  } catch {
41466
41484
  }
41467
41485
  }
41468
- return new Promise((resolve7, reject) => {
41469
- this.server = (0, import_node_net3.createServer)((sock) => this.handleClient(sock));
41486
+ return new Promise((resolve8, reject) => {
41487
+ this.server = (0, import_node_net4.createServer)((sock) => this.handleClient(sock));
41470
41488
  this.server.on("error", reject);
41471
41489
  this.server.listen(PATHS.socket, () => {
41472
41490
  const nodeFs = require("fs");
@@ -41484,7 +41502,7 @@ var IpcServer = class {
41484
41502
  }
41485
41503
  }
41486
41504
  }
41487
- resolve7();
41505
+ resolve8();
41488
41506
  });
41489
41507
  });
41490
41508
  }
@@ -41496,20 +41514,20 @@ var IpcServer = class {
41496
41514
  }
41497
41515
  }
41498
41516
  this.clients.clear();
41499
- return new Promise((resolve7) => {
41517
+ return new Promise((resolve8) => {
41500
41518
  if (!this.server) {
41501
41519
  try {
41502
41520
  if ((0, import_node_fs27.existsSync)(PATHS.socket)) (0, import_node_fs27.unlinkSync)(PATHS.socket);
41503
41521
  } catch {
41504
41522
  }
41505
- return resolve7();
41523
+ return resolve8();
41506
41524
  }
41507
41525
  this.server.close(() => {
41508
41526
  try {
41509
41527
  if ((0, import_node_fs27.existsSync)(PATHS.socket)) (0, import_node_fs27.unlinkSync)(PATHS.socket);
41510
41528
  } catch {
41511
41529
  }
41512
- resolve7();
41530
+ resolve8();
41513
41531
  });
41514
41532
  });
41515
41533
  }
@@ -42286,12 +42304,12 @@ var import_node_readline3 = require("readline");
42286
42304
  // src/core/threat-feeds/index.ts
42287
42305
  var import_node_fs31 = require("fs");
42288
42306
  var import_node_path23 = require("path");
42289
- var import_node_net5 = require("net");
42307
+ var import_node_net6 = require("net");
42290
42308
 
42291
42309
  // src/daemon/firewall/protected.ts
42292
42310
  var import_node_child_process8 = require("child_process");
42293
42311
  var import_node_fs30 = require("fs");
42294
- var import_node_net4 = require("net");
42312
+ var import_node_net5 = require("net");
42295
42313
  var DEFAULT_PROTECTED = [
42296
42314
  "127.0.0.0/8",
42297
42315
  "::1/128",
@@ -42335,7 +42353,7 @@ var SHARED_INFRASTRUCTURE = [
42335
42353
  "208.67.220.220/32"
42336
42354
  ];
42337
42355
  function ipToBytes(ip) {
42338
- const version = (0, import_node_net4.isIP)(ip);
42356
+ const version = (0, import_node_net5.isIP)(ip);
42339
42357
  if (version === 4) return v4ToBytes(ip);
42340
42358
  if (version === 6) return v6ToBytes(ip);
42341
42359
  return null;
@@ -42413,7 +42431,7 @@ function currentSshClient(env3 = process.env) {
42413
42431
  const source = env3.SSH_CLIENT || env3.SSH_CONNECTION;
42414
42432
  if (!source) return null;
42415
42433
  const ip = source.trim().split(/\s+/)[0];
42416
- return ip && (0, import_node_net4.isIP)(ip) ? ip : null;
42434
+ return ip && (0, import_node_net5.isIP)(ip) ? ip : null;
42417
42435
  }
42418
42436
  function establishedSshPeers() {
42419
42437
  const peers = /* @__PURE__ */ new Set();
@@ -42429,7 +42447,7 @@ function establishedSshPeers() {
42429
42447
  const peer = parts[4];
42430
42448
  if (!peer) continue;
42431
42449
  const ip = peer.slice(0, peer.lastIndexOf(":")).replace(/^\[|\]$/g, "");
42432
- if (ip && (0, import_node_net4.isIP)(ip)) peers.add(ip);
42450
+ if (ip && (0, import_node_net5.isIP)(ip)) peers.add(ip);
42433
42451
  }
42434
42452
  } catch {
42435
42453
  }
@@ -42438,7 +42456,7 @@ function establishedSshPeers() {
42438
42456
  function sshClientFromEnviron(environ) {
42439
42457
  for (const entry of environ.split("\0")) {
42440
42458
  const m = /^SSH_(?:CONNECTION|CLIENT)=(\S+)/.exec(entry);
42441
- if (m && (0, import_node_net4.isIP)(m[1])) return m[1];
42459
+ if (m && (0, import_node_net5.isIP)(m[1])) return m[1];
42442
42460
  }
42443
42461
  return null;
42444
42462
  }
@@ -42464,7 +42482,7 @@ function parseKeyLogins(text, skip = () => false) {
42464
42482
  const out = /* @__PURE__ */ new Map();
42465
42483
  for (const line2 of text.split("\n")) {
42466
42484
  const m = /^(\d+(?:\.\d+)?)\s.*Accepted publickey for \S+ from (\S+) port \d+ [^\s:]+(?:: \S+ (SHA256:\S+))?/.exec(line2);
42467
- if (!m || !(0, import_node_net4.isIP)(m[2])) continue;
42485
+ if (!m || !(0, import_node_net5.isIP)(m[2])) continue;
42468
42486
  if (m[3] && skip(m[3])) continue;
42469
42487
  const at = Math.round(Number(m[1]) * 1e3);
42470
42488
  if (at > (out.get(m[2]) ?? 0)) out.set(m[2], at);
@@ -42481,7 +42499,7 @@ function defaultGateways() {
42481
42499
  const out = (0, import_node_child_process8.execFileSync)("ip", args, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
42482
42500
  for (const line2 of out.split("\n")) {
42483
42501
  const match = line2.match(/\bvia\s+(\S+)/);
42484
- if (match && (0, import_node_net4.isIP)(match[1])) found.add(match[1]);
42502
+ if (match && (0, import_node_net5.isIP)(match[1])) found.add(match[1]);
42485
42503
  }
42486
42504
  } catch {
42487
42505
  }
@@ -42594,26 +42612,26 @@ function parseIpList(text, feed) {
42594
42612
  const out = /* @__PURE__ */ new Map();
42595
42613
  for (const line2 of text.split("\n")) {
42596
42614
  const ip = line2.trim();
42597
- if (ip && !ip.startsWith("#") && (0, import_node_net5.isIP)(ip)) out.set(ip, { malware: "unknown", threat: "botnet_cc", feed });
42615
+ if (ip && !ip.startsWith("#") && (0, import_node_net6.isIP)(ip)) out.set(ip, { malware: "unknown", threat: "botnet_cc", feed });
42598
42616
  }
42599
42617
  return out;
42600
42618
  }
42601
42619
  function stripPort(value) {
42602
42620
  const v6 = /^\[([^\]]+)\]:\d+$/.exec(value);
42603
42621
  const ip = v6 ? v6[1] : value.replace(/:\d+$/, "");
42604
- return (0, import_node_net5.isIP)(ip) ? ip : null;
42622
+ return (0, import_node_net6.isIP)(ip) ? ip : null;
42605
42623
  }
42606
42624
  function normalizeDomain(value) {
42607
42625
  const d = value.trim().toLowerCase().replace(/\.$/, "");
42608
- if (!d || d === "localhost" || (0, import_node_net5.isIP)(d) || !/^[a-z0-9_.-]+\.[a-z0-9-]{2,}$/.test(d)) return null;
42626
+ if (!d || d === "localhost" || (0, import_node_net6.isIP)(d) || !/^[a-z0-9_.-]+\.[a-z0-9-]{2,}$/.test(d)) return null;
42609
42627
  return d;
42610
42628
  }
42611
42629
  function allowedDomain(domain, allow) {
42612
42630
  return allow.some((a) => domain === a || domain.endsWith(`.${a}`));
42613
42631
  }
42614
42632
  function buildFeedSet(parts, allow, sources, now = /* @__PURE__ */ new Date()) {
42615
- const neverIps = [...DEFAULT_PROTECTED, ...SHARED_RANGES, ...allow.filter((a) => (0, import_node_net5.isIP)(a.split("/")[0]))];
42616
- const allowDomains = allow.filter((a) => !(0, import_node_net5.isIP)(a.split("/")[0])).map((a) => a.toLowerCase());
42633
+ const neverIps = [...DEFAULT_PROTECTED, ...SHARED_RANGES, ...allow.filter((a) => (0, import_node_net6.isIP)(a.split("/")[0]))];
42634
+ const allowDomains = allow.filter((a) => !(0, import_node_net6.isIP)(a.split("/")[0])).map((a) => a.toLowerCase());
42617
42635
  const ips = {};
42618
42636
  const domains = {};
42619
42637
  let skipped = 0;
@@ -43511,19 +43529,197 @@ function slackChannel(webhookUrl) {
43511
43529
  }
43512
43530
 
43513
43531
  // src/daemon/workers/runs-worker.ts
43532
+ var import_promises2 = require("dns/promises");
43533
+ var import_node_fs34 = require("fs");
43534
+ var import_node_net8 = require("net");
43535
+ var import_node_path25 = require("path");
43536
+ init_cli_config();
43537
+
43538
+ // src/core/cloud-events.ts
43539
+ var import_node_crypto7 = require("crypto");
43540
+ var import_node_net7 = require("net");
43514
43541
  init_cli_config();
43542
+ function currentLink() {
43543
+ if (!hasSession()) return null;
43544
+ const cfg = readCliConfig();
43545
+ if (!cfg.server_id || !cfg.server_org_id) return null;
43546
+ return { serverId: cfg.server_id, orgId: cfg.server_org_id };
43547
+ }
43548
+ var SEVERITY_RANK6 = {
43549
+ info: 0,
43550
+ low: 1,
43551
+ medium: 2,
43552
+ high: 3,
43553
+ critical: 4
43554
+ };
43555
+ var MAX_TITLE_CHARS = 300;
43556
+ var MAX_METADATA_BYTES = 16 * 1024;
43557
+ var MAX_STRING_CHARS = 1024;
43558
+ function jsonBytes(value) {
43559
+ try {
43560
+ return Buffer.byteLength(JSON.stringify(value) ?? "");
43561
+ } catch {
43562
+ return Infinity;
43563
+ }
43564
+ }
43565
+ function trimMetadata(meta) {
43566
+ const entries = [];
43567
+ for (const [key, value] of Object.entries(meta)) {
43568
+ if (value === void 0 || typeof value === "function") continue;
43569
+ const cut = typeof value === "string" && value.length > MAX_STRING_CHARS ? `${value.slice(0, MAX_STRING_CHARS)}\u2026` : value;
43570
+ if (jsonBytes(cut) === Infinity) continue;
43571
+ entries.push([key, cut]);
43572
+ }
43573
+ let out = Object.fromEntries(entries);
43574
+ let truncated = entries.length !== Object.keys(meta).length;
43575
+ if (jsonBytes(out) > MAX_METADATA_BYTES) {
43576
+ truncated = true;
43577
+ const work = new Map(entries);
43578
+ const shrunk = /* @__PURE__ */ new Set();
43579
+ const size = () => jsonBytes({ ...Object.fromEntries(work), _truncated: true });
43580
+ while (work.size > 0 && size() > MAX_METADATA_BYTES) {
43581
+ const [key] = [...work.entries()].filter(([k]) => k !== "evidence" || !shrunk.has(k)).sort((a, b) => jsonBytes(b[1]) - jsonBytes(a[1]))[0] ?? [];
43582
+ if (key === void 0) break;
43583
+ if (!shrunk.has(key)) {
43584
+ const text = typeof work.get(key) === "string" ? work.get(key) : JSON.stringify(work.get(key));
43585
+ work.set(key, text.length > MAX_STRING_CHARS ? `${text.slice(0, MAX_STRING_CHARS)}\u2026` : text);
43586
+ shrunk.add(key);
43587
+ } else if (key !== "evidence") {
43588
+ work.delete(key);
43589
+ } else break;
43590
+ }
43591
+ out = Object.fromEntries(work);
43592
+ }
43593
+ return truncated ? { ...out, _truncated: true } : out;
43594
+ }
43595
+ function str2(value) {
43596
+ return typeof value === "string" && value ? value : void 0;
43597
+ }
43598
+ function detectionEvent(serverId, event) {
43599
+ const { rule_id, username, user, description, ...rest } = event.details ?? {};
43600
+ const title = event.module === "rule-engine" ? event.message.replace(/^\[DETECTION\]\s*/, "") : event.message;
43601
+ return {
43602
+ type: "detection",
43603
+ server_id: serverId,
43604
+ severity: event.severity,
43605
+ title: title.slice(0, MAX_TITLE_CHARS) || event.module,
43606
+ rule_id: str2(rule_id) ?? event.module,
43607
+ description: str2(description),
43608
+ source_ip: event.source_ip && (0, import_node_net7.isIP)(event.source_ip) ? event.source_ip : void 0,
43609
+ username: str2(username) ?? str2(user),
43610
+ raw_metadata: trimMetadata({ module: event.module, category: event.category, ...rest }),
43611
+ detected_at: event.timestamp.toISOString()
43612
+ };
43613
+ }
43614
+ function remediationEvent(serverId, event) {
43615
+ const d = event.details ?? {};
43616
+ if (d.action !== "block" && d.action !== "unblock") return null;
43617
+ if (d.origin === "cloud" || !event.source_ip) return null;
43618
+ const at = event.timestamp;
43619
+ const ttl = typeof d.ttl_seconds === "number" ? d.ttl_seconds : null;
43620
+ return {
43621
+ type: "remediation",
43622
+ server_id: serverId,
43623
+ event_id: (0, import_node_crypto7.randomUUID)(),
43624
+ action_type: d.action,
43625
+ target_value: event.source_ip,
43626
+ status: d.failed === true ? "failed" : "executed",
43627
+ rule_id: str2(d.rule_id),
43628
+ reason: str2(d.reason),
43629
+ error: str2(d.error),
43630
+ dry_run: d.dry_run === true,
43631
+ executed_at: at.toISOString(),
43632
+ expires_at: d.action === "block" && ttl !== null && d.failed !== true ? new Date(at.getTime() + ttl * 1e3).toISOString() : null
43633
+ };
43634
+ }
43635
+ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date()) {
43636
+ return results.map((r) => ({
43637
+ type: "hardening_finding",
43638
+ server_id: serverId,
43639
+ finding_key: r.key,
43640
+ status: r.status,
43641
+ severity: r.severity,
43642
+ title: r.title.slice(0, MAX_TITLE_CHARS),
43643
+ recommendation: r.recommendation,
43644
+ observed_at: observedAt.toISOString(),
43645
+ ...r.details ? { details: trimMetadata(r.details) } : {}
43646
+ }));
43647
+ }
43648
+
43649
+ // src/daemon/workers/runs-worker.ts
43515
43650
  var POLL_INTERVAL_MS = 3e4;
43516
43651
  var SCHEDULE_INTERVAL_MS = 12e4;
43652
+ var NOT_PUBLIC = [
43653
+ ...DEFAULT_PROTECTED,
43654
+ "0.0.0.0/8",
43655
+ "100.64.0.0/10",
43656
+ "192.0.0.0/24",
43657
+ "198.18.0.0/15",
43658
+ "224.0.0.0/3",
43659
+ "::/128",
43660
+ "::ffff:0:0/96",
43661
+ "64:ff9b::/96",
43662
+ "ff00::/8"
43663
+ ];
43664
+ function isPublicTarget(ip) {
43665
+ return (0, import_node_net8.isIP)(ip) !== 0 && !isProtected(ip, NOT_PUBLIC);
43666
+ }
43667
+ async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0, import_promises2.lookup)(h, { all: true })).map((a) => a.address)) {
43668
+ let url;
43669
+ try {
43670
+ url = new URL(rawUrl.startsWith("http") ? rawUrl : `https://${rawUrl}`);
43671
+ } catch {
43672
+ return `not a URL: ${rawUrl}`;
43673
+ }
43674
+ if (url.protocol !== "http:" && url.protocol !== "https:") return `not an http(s) URL: ${rawUrl}`;
43675
+ const host = url.hostname.replace(/^\[|\]$/g, "");
43676
+ let addresses;
43677
+ try {
43678
+ addresses = (0, import_node_net8.isIP)(host) ? [host] : await resolveHost(host);
43679
+ } catch (err) {
43680
+ return `cannot resolve ${host}: ${err.message}`;
43681
+ }
43682
+ if (addresses.length === 0) return `cannot resolve ${host}`;
43683
+ const inside = addresses.find((a) => !isPublicTarget(a));
43684
+ return inside ? `${host} resolves to ${inside}, which is not a public address; dashboard runs never reach inside this network` : null;
43685
+ }
43686
+ function scanTargetError(target, roots, real = import_node_fs34.realpathSync) {
43687
+ if (roots.length === 0) {
43688
+ return "dashboard scans of this machine are off; list the directories they may read in [cloud] run_scan_paths";
43689
+ }
43690
+ let path2;
43691
+ try {
43692
+ path2 = real((0, import_node_path25.resolve)(target));
43693
+ } catch {
43694
+ return `no such path: ${target}`;
43695
+ }
43696
+ for (const root of roots) {
43697
+ let base;
43698
+ try {
43699
+ base = real((0, import_node_path25.resolve)(root));
43700
+ } catch {
43701
+ continue;
43702
+ }
43703
+ if (path2 === base || path2.startsWith(base.endsWith(import_node_path25.sep) ? base : base + import_node_path25.sep)) return null;
43704
+ }
43705
+ return `${target} is outside [cloud] run_scan_paths`;
43706
+ }
43517
43707
  var RunsWorker = class {
43518
- constructor(bus2) {
43708
+ constructor(bus2, opts = { enabled: false, scanRoots: [] }) {
43519
43709
  this.bus = bus2;
43710
+ this.opts = opts;
43520
43711
  }
43521
43712
  bus;
43713
+ opts;
43522
43714
  pollTimer = null;
43523
43715
  scheduleTimer = null;
43524
43716
  running = false;
43525
43717
  orgIds = [];
43526
43718
  async start() {
43719
+ if (!this.opts.enabled) {
43720
+ this.opts.log?.("[runs] dashboard property runs off (set [cloud] runs = true to run them on this machine)");
43721
+ return;
43722
+ }
43527
43723
  if (!hasSession()) return;
43528
43724
  try {
43529
43725
  await this.refreshOrgs();
@@ -43545,7 +43741,7 @@ var RunsWorker = class {
43545
43741
  async scheduleTick() {
43546
43742
  if (!hasSession()) return;
43547
43743
  try {
43548
- if (this.orgIds.length === 0) await this.refreshOrgs();
43744
+ await this.refreshOrgs();
43549
43745
  for (const orgId of this.orgIds) {
43550
43746
  try {
43551
43747
  await cloudFetch(`/api/orgs/${orgId}/schedules/tick`, { method: "POST" });
@@ -43560,7 +43756,7 @@ var RunsWorker = class {
43560
43756
  if (!hasSession()) return;
43561
43757
  this.running = true;
43562
43758
  try {
43563
- if (this.orgIds.length === 0) await this.refreshOrgs();
43759
+ await this.refreshOrgs();
43564
43760
  for (const orgId of this.orgIds) {
43565
43761
  const claimed = await this.claimOne(orgId);
43566
43762
  if (!claimed) continue;
@@ -43572,11 +43768,10 @@ var RunsWorker = class {
43572
43768
  this.running = false;
43573
43769
  }
43574
43770
  }
43771
+ /** Only the org this server is linked to: never every org its user is in. */
43575
43772
  async refreshOrgs() {
43576
- const res = await cloudFetch("/api/orgs");
43577
- if (!res.ok) return;
43578
- const data = await res.json();
43579
- this.orgIds = (data.organizations || []).map((o) => o.id);
43773
+ const link = currentLink();
43774
+ this.orgIds = link ? [link.orgId] : [];
43580
43775
  }
43581
43776
  async claimOne(orgId) {
43582
43777
  try {
@@ -43603,6 +43798,18 @@ var RunsWorker = class {
43603
43798
  error: "property target missing"
43604
43799
  };
43605
43800
  }
43801
+ const refused = run.type === "scan" ? scanTargetError(target, this.opts.scanRoots) : await pentestTargetError(target);
43802
+ if (refused) {
43803
+ this.opts.log?.(`[runs] refused ${run.type} ${target}: ${refused}`);
43804
+ return {
43805
+ type: run.type,
43806
+ target,
43807
+ findings: [],
43808
+ severity_summary: { critical: 0, high: 0, medium: 0, low: 0, info: 0 },
43809
+ summary: `refused: ${refused}`,
43810
+ error: refused
43811
+ };
43812
+ }
43606
43813
  this.bus.announceModule("runs-worker", "running", `${run.type} ${run.property?.name || target}`);
43607
43814
  try {
43608
43815
  if (run.type === "scan") return await runScan(target);
@@ -43646,118 +43853,17 @@ var RunsWorker = class {
43646
43853
  // src/daemon/workers/cloud-sync.ts
43647
43854
  init_cli_config();
43648
43855
 
43649
- // src/core/cloud-events.ts
43650
- var import_node_crypto7 = require("crypto");
43651
- var import_node_net6 = require("net");
43652
- init_cli_config();
43653
- function currentLink() {
43654
- if (!hasSession()) return null;
43655
- const cfg = readCliConfig();
43656
- if (!cfg.server_id || !cfg.server_org_id) return null;
43657
- return { serverId: cfg.server_id, orgId: cfg.server_org_id };
43658
- }
43659
- var SEVERITY_RANK6 = {
43660
- info: 0,
43661
- low: 1,
43662
- medium: 2,
43663
- high: 3,
43664
- critical: 4
43665
- };
43666
- var MAX_TITLE_CHARS = 300;
43667
- var MAX_METADATA_BYTES = 16 * 1024;
43668
- var MAX_STRING_CHARS = 1024;
43669
- function jsonBytes(value) {
43670
- try {
43671
- return Buffer.byteLength(JSON.stringify(value) ?? "");
43672
- } catch {
43673
- return Infinity;
43674
- }
43675
- }
43676
- function trimMetadata(meta) {
43677
- const entries = [];
43678
- for (const [key, value] of Object.entries(meta)) {
43679
- if (value === void 0 || typeof value === "function") continue;
43680
- const cut = typeof value === "string" && value.length > MAX_STRING_CHARS ? `${value.slice(0, MAX_STRING_CHARS)}\u2026` : value;
43681
- if (jsonBytes(cut) === Infinity) continue;
43682
- entries.push([key, cut]);
43683
- }
43684
- let out = Object.fromEntries(entries);
43685
- let truncated = entries.length !== Object.keys(meta).length;
43686
- if (jsonBytes(out) > MAX_METADATA_BYTES) {
43687
- truncated = true;
43688
- const bySize = [...entries].sort((a, b) => jsonBytes(a[1]) - jsonBytes(b[1]));
43689
- while (bySize.length > 0 && jsonBytes({ ...Object.fromEntries(bySize), _truncated: true }) > MAX_METADATA_BYTES) {
43690
- bySize.pop();
43691
- }
43692
- out = Object.fromEntries(bySize);
43693
- }
43694
- return truncated ? { ...out, _truncated: true } : out;
43695
- }
43696
- function str2(value) {
43697
- return typeof value === "string" && value ? value : void 0;
43698
- }
43699
- function detectionEvent(serverId, event) {
43700
- const { rule_id, username, user, description, ...rest } = event.details ?? {};
43701
- const title = event.module === "rule-engine" ? event.message.replace(/^\[DETECTION\]\s*/, "") : event.message;
43702
- return {
43703
- type: "detection",
43704
- server_id: serverId,
43705
- severity: event.severity,
43706
- title: title.slice(0, MAX_TITLE_CHARS) || event.module,
43707
- rule_id: str2(rule_id) ?? event.module,
43708
- description: str2(description),
43709
- source_ip: event.source_ip && (0, import_node_net6.isIP)(event.source_ip) ? event.source_ip : void 0,
43710
- username: str2(username) ?? str2(user),
43711
- raw_metadata: trimMetadata({ module: event.module, category: event.category, ...rest }),
43712
- detected_at: event.timestamp.toISOString()
43713
- };
43714
- }
43715
- function remediationEvent(serverId, event) {
43716
- const d = event.details ?? {};
43717
- if (d.action !== "block" && d.action !== "unblock") return null;
43718
- if (d.origin === "cloud" || !event.source_ip) return null;
43719
- const at = event.timestamp;
43720
- const ttl = typeof d.ttl_seconds === "number" ? d.ttl_seconds : null;
43721
- return {
43722
- type: "remediation",
43723
- server_id: serverId,
43724
- event_id: (0, import_node_crypto7.randomUUID)(),
43725
- action_type: d.action,
43726
- target_value: event.source_ip,
43727
- status: d.failed === true ? "failed" : "executed",
43728
- rule_id: str2(d.rule_id),
43729
- reason: str2(d.reason),
43730
- error: str2(d.error),
43731
- dry_run: d.dry_run === true,
43732
- executed_at: at.toISOString(),
43733
- expires_at: d.action === "block" && ttl !== null && d.failed !== true ? new Date(at.getTime() + ttl * 1e3).toISOString() : null
43734
- };
43735
- }
43736
- function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date()) {
43737
- return results.map((r) => ({
43738
- type: "hardening_finding",
43739
- server_id: serverId,
43740
- finding_key: r.key,
43741
- status: r.status,
43742
- severity: r.severity,
43743
- title: r.title.slice(0, MAX_TITLE_CHARS),
43744
- recommendation: r.recommendation,
43745
- observed_at: observedAt.toISOString(),
43746
- ...r.details ? { details: trimMetadata(r.details) } : {}
43747
- }));
43748
- }
43749
-
43750
43856
  // src/daemon/workers/cloud-spool.ts
43751
- var import_node_fs34 = require("fs");
43752
- var import_promises2 = require("fs/promises");
43753
- var import_node_path25 = require("path");
43857
+ var import_node_fs35 = require("fs");
43858
+ var import_promises3 = require("fs/promises");
43859
+ var import_node_path26 = require("path");
43754
43860
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
43755
43861
  var CloudSpool = class {
43756
43862
  constructor(path2, limits = DEFAULT_SPOOL_LIMITS) {
43757
43863
  this.path = path2;
43758
43864
  this.limits = limits;
43759
43865
  try {
43760
- (0, import_node_fs34.mkdirSync)((0, import_node_path25.dirname)(path2), { recursive: true });
43866
+ (0, import_node_fs35.mkdirSync)((0, import_node_path26.dirname)(path2), { recursive: true });
43761
43867
  } catch {
43762
43868
  }
43763
43869
  this.load();
@@ -43826,7 +43932,7 @@ var CloudSpool = class {
43826
43932
  load() {
43827
43933
  let raw;
43828
43934
  try {
43829
- raw = (0, import_node_fs34.readFileSync)(this.path, "utf-8");
43935
+ raw = (0, import_node_fs35.readFileSync)(this.path, "utf-8");
43830
43936
  } catch {
43831
43937
  return;
43832
43938
  }
@@ -43857,13 +43963,13 @@ var CloudSpool = class {
43857
43963
  const body = this.lines.length > 0 ? `${this.lines.join("\n")}
43858
43964
  ` : "";
43859
43965
  const tmp = `${this.path}.tmp`;
43860
- await (0, import_promises2.writeFile)(tmp, body, { mode: 384 });
43861
- await (0, import_promises2.rename)(tmp, this.path);
43966
+ await (0, import_promises3.writeFile)(tmp, body, { mode: 384 });
43967
+ await (0, import_promises3.rename)(tmp, this.path);
43862
43968
  } else if (this.pendingAppend.length > 0) {
43863
43969
  const chunk2 = `${this.pendingAppend.join("\n")}
43864
43970
  `;
43865
43971
  this.pendingAppend = [];
43866
- await (0, import_promises2.appendFile)(this.path, chunk2, { mode: 384 });
43972
+ await (0, import_promises3.appendFile)(this.path, chunk2, { mode: 384 });
43867
43973
  }
43868
43974
  }).catch(() => {
43869
43975
  this.needsRewrite = true;
@@ -44067,7 +44173,7 @@ var CloudSync = class {
44067
44173
  var import_node_crypto8 = require("crypto");
44068
44174
 
44069
44175
  // src/daemon/workers/abuse-evidence.ts
44070
- var import_node_net7 = require("net");
44176
+ var import_node_net9 = require("net");
44071
44177
  var NEVER_REPORT_RANGES = [
44072
44178
  ...DEFAULT_PROTECTED,
44073
44179
  "100.64.0.0/10",
@@ -44143,7 +44249,7 @@ function summarizeEvidence(events) {
44143
44249
  };
44144
44250
  }
44145
44251
  function isReportable(ip, evidence, config, now = Date.now()) {
44146
- if ((0, import_node_net7.isIP)(ip) === 0) return { reportable: false, reason: "not an IP address" };
44252
+ if ((0, import_node_net9.isIP)(ip) === 0) return { reportable: false, reason: "not an IP address" };
44147
44253
  if (isProtected(ip, config.neverReport)) {
44148
44254
  return { reportable: false, reason: "address is in a never-report range (private/CGNAT/reserved/allowlisted)" };
44149
44255
  }
@@ -44293,32 +44399,32 @@ function resolveConfig(section) {
44293
44399
  }
44294
44400
 
44295
44401
  // src/core/abuse-report-log.ts
44296
- var import_node_fs35 = require("fs");
44297
- var import_node_path26 = require("path");
44402
+ var import_node_fs36 = require("fs");
44403
+ var import_node_path27 = require("path");
44298
44404
  init_paths();
44299
44405
  var ABUSE_DIRNAME = "abuse-reports";
44300
44406
  var LOG_FILE2 = "reports.jsonl";
44301
44407
  function resolveAbuseDir(dir) {
44302
44408
  if (dir) return dir;
44303
44409
  if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
44304
- const system = (0, import_node_path26.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
44305
- if ((0, import_node_fs35.existsSync)(system)) return system;
44306
- return (0, import_node_path26.join)(PATHS.stateDir, ABUSE_DIRNAME);
44410
+ const system = (0, import_node_path27.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
44411
+ if ((0, import_node_fs36.existsSync)(system)) return system;
44412
+ return (0, import_node_path27.join)(PATHS.stateDir, ABUSE_DIRNAME);
44307
44413
  }
44308
44414
  function logPath(dir) {
44309
- return (0, import_node_path26.join)(resolveAbuseDir(dir), LOG_FILE2);
44415
+ return (0, import_node_path27.join)(resolveAbuseDir(dir), LOG_FILE2);
44310
44416
  }
44311
44417
  function appendReport(record, dir) {
44312
44418
  const path2 = logPath(dir);
44313
- (0, import_node_fs35.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
44314
- (0, import_node_fs35.appendFileSync)(path2, `${JSON.stringify(record)}
44419
+ (0, import_node_fs36.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
44420
+ (0, import_node_fs36.appendFileSync)(path2, `${JSON.stringify(record)}
44315
44421
  `, { mode: 420 });
44316
44422
  }
44317
44423
  function readReports(dir) {
44318
44424
  const path2 = logPath(dir);
44319
44425
  let raw;
44320
44426
  try {
44321
- raw = (0, import_node_fs35.readFileSync)(path2, "utf-8");
44427
+ raw = (0, import_node_fs36.readFileSync)(path2, "utf-8");
44322
44428
  } catch {
44323
44429
  return [];
44324
44430
  }
@@ -44494,20 +44600,27 @@ var AbuseReporter = class {
44494
44600
  };
44495
44601
 
44496
44602
  // src/daemon/workers/remediation-consumer.ts
44497
- var import_node_net9 = require("net");
44603
+ var import_node_net11 = require("net");
44498
44604
  init_cli_config();
44499
44605
 
44500
44606
  // src/daemon/workers/allowlist-sync.ts
44501
- var import_node_net8 = require("net");
44607
+ var import_node_net10 = require("net");
44502
44608
  init_cli_config();
44503
44609
  function isAddressOrCidr(value) {
44504
44610
  const [network, prefix, extra] = value.split("/");
44505
- const family = (0, import_node_net8.isIP)(network);
44611
+ const family = (0, import_node_net10.isIP)(network);
44506
44612
  if (family === 0 || extra !== void 0) return false;
44507
44613
  if (prefix === void 0) return true;
44508
44614
  if (!/^\d{1,3}$/.test(prefix)) return false;
44509
44615
  return Number(prefix) <= (family === 4 ? 32 : 128);
44510
44616
  }
44617
+ var CLOUD_MIN_PREFIX = { 4: 8, 6: 16 };
44618
+ function isCloudAllowEntry(value) {
44619
+ if (!isAddressOrCidr(value)) return false;
44620
+ const [network, prefix] = value.split("/");
44621
+ if (prefix === void 0) return true;
44622
+ return Number(prefix) >= CLOUD_MIN_PREFIX[(0, import_node_net10.isIP)(network)];
44623
+ }
44511
44624
  var AllowlistSync = class {
44512
44625
  constructor(manager, opts) {
44513
44626
  this.manager = manager;
@@ -44543,7 +44656,8 @@ var AllowlistSync = class {
44543
44656
  for (const entry of entries) {
44544
44657
  if (entry.type !== "ip" && entry.type !== "cidr") continue;
44545
44658
  const value = String(entry.value ?? "").trim();
44546
- if (isAddressOrCidr(value)) wanted.add(value);
44659
+ if (isCloudAllowEntry(value)) wanted.add(value);
44660
+ else if (isAddressOrCidr(value)) this.opts.log(`[cloud] org allowlist: ignoring ${value} (wider than /${CLOUD_MIN_PREFIX[(0, import_node_net10.isIP)(value.split("/")[0])]})`);
44547
44661
  }
44548
44662
  const added2 = [];
44549
44663
  const protectedNow = new Set(this.manager.getProtected());
@@ -44651,7 +44765,7 @@ var RemediationConsumer = class {
44651
44765
  try {
44652
44766
  switch (action.action_type) {
44653
44767
  case "block": {
44654
- if ((0, import_node_net9.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
44768
+ if ((0, import_node_net11.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
44655
44769
  let ttlSeconds = this.manager.status().max_ban_seconds;
44656
44770
  if (action.expires_at) {
44657
44771
  const until = Date.parse(action.expires_at);
@@ -44670,7 +44784,7 @@ var RemediationConsumer = class {
44670
44784
  return { status: "executed", dry_run: result.entry?.dry_run === true, executed_at };
44671
44785
  }
44672
44786
  case "unblock": {
44673
- if ((0, import_node_net9.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
44787
+ if ((0, import_node_net11.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
44674
44788
  const wasBanned = this.manager.getBlocklist().some((b) => b.ip === target);
44675
44789
  const result = await this.manager.unban(target, {
44676
44790
  forget: true,
@@ -44683,13 +44797,16 @@ var RemediationConsumer = class {
44683
44797
  return { status: "executed", dry_run: this.manager.status().dry_run, executed_at };
44684
44798
  }
44685
44799
  case "allowlist_add":
44686
- if (!isAddressOrCidr(target)) return failed(`not an IP address or CIDR: ${target}`);
44800
+ if (!isCloudAllowEntry(target)) return failed(`not an IP address or CIDR the dashboard may protect: ${target}`);
44687
44801
  this.manager.addToAllowlist(target);
44688
44802
  return { status: "executed", executed_at };
44689
44803
  case "allowlist_remove":
44690
44804
  if (DEFAULT_PROTECTED.includes(target)) {
44691
44805
  return failed(`${target} is a built-in protected range and cannot be removed`);
44692
44806
  }
44807
+ if (this.manager.isPinned(target)) {
44808
+ return failed(`${target} is protected by this server's own configuration and cannot be removed from the dashboard`);
44809
+ }
44693
44810
  this.manager.removeFromAllowlist(target);
44694
44811
  return { status: "executed", executed_at };
44695
44812
  case "restart": {
@@ -44722,8 +44839,8 @@ var RemediationConsumer = class {
44722
44839
 
44723
44840
  // src/daemon/workers/auto-update.ts
44724
44841
  var import_node_child_process10 = require("child_process");
44725
- var import_node_fs36 = require("fs");
44726
- var import_node_path27 = require("path");
44842
+ var import_node_fs37 = require("fs");
44843
+ var import_node_path28 = require("path");
44727
44844
  init_backoff();
44728
44845
  var PKG_NAME = "@profullstack/threatcrush";
44729
44846
  var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
@@ -44767,12 +44884,12 @@ function pickUpdate(doc, current, opts) {
44767
44884
  return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
44768
44885
  }
44769
44886
  function installPlan(opts) {
44770
- const expected = `${import_node_path27.sep}lib${import_node_path27.sep}node_modules${import_node_path27.sep}@profullstack${import_node_path27.sep}threatcrush`;
44887
+ const expected = `${import_node_path28.sep}lib${import_node_path28.sep}node_modules${import_node_path28.sep}@profullstack${import_node_path28.sep}threatcrush`;
44771
44888
  if (!opts.pkgRoot.endsWith(expected)) {
44772
44889
  return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
44773
44890
  }
44774
- const nodeBin = (0, import_node_path27.dirname)(opts.execPath);
44775
- const npm = (0, import_node_path27.join)(nodeBin, "npm");
44891
+ const nodeBin = (0, import_node_path28.dirname)(opts.execPath);
44892
+ const npm = (0, import_node_path28.join)(nodeBin, "npm");
44776
44893
  if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
44777
44894
  if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
44778
44895
  const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
@@ -44804,10 +44921,10 @@ function installPlan(opts) {
44804
44921
  }
44805
44922
  function ownerOf(path2, passwd = "/etc/passwd") {
44806
44923
  try {
44807
- const st = (0, import_node_fs36.statSync)(path2);
44924
+ const st = (0, import_node_fs37.statSync)(path2);
44808
44925
  let home = st.uid === 0 ? "/root" : "";
44809
44926
  try {
44810
- for (const line2 of (0, import_node_fs36.readFileSync)(passwd, "utf8").split("\n")) {
44927
+ for (const line2 of (0, import_node_fs37.readFileSync)(passwd, "utf8").split("\n")) {
44811
44928
  const f = line2.split(":");
44812
44929
  if (Number(f[2]) === st.uid && f[5]) home = f[5];
44813
44930
  }
@@ -44829,7 +44946,7 @@ function updateSettings(section, env3 = process.env) {
44829
44946
  };
44830
44947
  }
44831
44948
  function defaultRun(argv, env3) {
44832
- return new Promise((resolve7) => {
44949
+ return new Promise((resolve8) => {
44833
44950
  const child = (0, import_node_child_process10.spawn)(argv[0], argv.slice(1), {
44834
44951
  env: { ...process.env, ...env3 },
44835
44952
  stdio: ["ignore", "pipe", "pipe"]
@@ -44840,8 +44957,8 @@ function defaultRun(argv, env3) {
44840
44957
  };
44841
44958
  child.stdout?.on("data", keep);
44842
44959
  child.stderr?.on("data", keep);
44843
- child.on("error", (err) => resolve7({ code: -1, output: err.message }));
44844
- child.on("close", (code) => resolve7({ code: code ?? -1, output }));
44960
+ child.on("error", (err) => resolve8({ code: -1, output: err.message }));
44961
+ child.on("close", (code) => resolve8({ code: code ?? -1, output }));
44845
44962
  });
44846
44963
  }
44847
44964
  var AutoUpdate = class {
@@ -44917,7 +45034,7 @@ var AutoUpdate = class {
44917
45034
  uid: process.getuid?.() ?? -1,
44918
45035
  owner: ownerOf(this.opts.pkgRoot),
44919
45036
  underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
44920
- npmExists: import_node_fs36.existsSync
45037
+ npmExists: import_node_fs37.existsSync
44921
45038
  });
44922
45039
  if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
44923
45040
  this.recordAttempt(target);
@@ -44953,7 +45070,7 @@ var AutoUpdate = class {
44953
45070
  }
44954
45071
  lastAttempt() {
44955
45072
  try {
44956
- const v = JSON.parse((0, import_node_fs36.readFileSync)(this.opts.statePath, "utf8"));
45073
+ const v = JSON.parse((0, import_node_fs37.readFileSync)(this.opts.statePath, "utf8"));
44957
45074
  return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
44958
45075
  } catch {
44959
45076
  return null;
@@ -44961,7 +45078,7 @@ var AutoUpdate = class {
44961
45078
  }
44962
45079
  recordAttempt(version) {
44963
45080
  try {
44964
- (0, import_node_fs36.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
45081
+ (0, import_node_fs37.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
44965
45082
  } catch (err) {
44966
45083
  this.opts.log(`[update] could not record attempt: ${err.message}`);
44967
45084
  }
@@ -44970,9 +45087,9 @@ var AutoUpdate = class {
44970
45087
 
44971
45088
  // src/daemon/workers/threat-feeds.ts
44972
45089
  var import_node_child_process11 = require("child_process");
44973
- var import_node_fs37 = require("fs");
44974
- var import_node_path28 = require("path");
44975
- var import_node_net10 = require("net");
45090
+ var import_node_fs38 = require("fs");
45091
+ var import_node_path29 = require("path");
45092
+ var import_node_net12 = require("net");
44976
45093
  init_backoff();
44977
45094
  var EGRESS_TABLE = "threatcrush_egress";
44978
45095
  var DEFAULT_REFRESH_MS = 36e5;
@@ -44991,8 +45108,8 @@ function threatFeedSettings(section) {
44991
45108
  };
44992
45109
  }
44993
45110
  function egressRuleset(ips) {
44994
- const v4 = ips.filter((ip) => (0, import_node_net10.isIP)(ip) === 4);
44995
- const v6 = ips.filter((ip) => (0, import_node_net10.isIP)(ip) === 6);
45111
+ const v4 = ips.filter((ip) => (0, import_node_net12.isIP)(ip) === 4);
45112
+ const v6 = ips.filter((ip) => (0, import_node_net12.isIP)(ip) === 6);
44996
45113
  const set = (name, type, items) => ` set ${name} { type ${type};${items.length ? ` elements = { ${items.join(", ")} }` : ""} }`;
44997
45114
  const chain = (name, hook) => [
44998
45115
  ` chain ${name} {`,
@@ -45017,7 +45134,7 @@ function splitAddr(addr) {
45017
45134
  const m = /^\[?(.+?)\]?:(\d+|\*)$/.exec(addr);
45018
45135
  if (!m) return null;
45019
45136
  const ip = m[1].replace(/%.*$/, "").replace(/^::ffff:/i, "");
45020
- return (0, import_node_net10.isIP)(ip) ? { ip, port: m[2] === "*" ? 0 : Number(m[2]) } : null;
45137
+ return (0, import_node_net12.isIP)(ip) ? { ip, port: m[2] === "*" ? 0 : Number(m[2]) } : null;
45021
45138
  }
45022
45139
  function parseSs(text) {
45023
45140
  const out = [];
@@ -45143,14 +45260,14 @@ var ThreatFeeds = class {
45143
45260
  */
45144
45261
  writeResolverFiles(set) {
45145
45262
  const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
45146
- const dir = this.opts.resolverDir ?? (0, import_node_path28.dirname)(this.opts.cachePath);
45263
+ const dir = this.opts.resolverDir ?? (0, import_node_path29.dirname)(this.opts.cachePath);
45147
45264
  const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
45148
45265
  const write = (name, content) => {
45149
- const path2 = (0, import_node_path28.join)(dir, name);
45266
+ const path2 = (0, import_node_path29.join)(dir, name);
45150
45267
  if (this.resolverWritten.get(name) === content) return false;
45151
45268
  try {
45152
- (0, import_node_fs37.writeFileSync)(`${path2}.tmp`, content);
45153
- (0, import_node_fs37.renameSync)(`${path2}.tmp`, path2);
45269
+ (0, import_node_fs38.writeFileSync)(`${path2}.tmp`, content);
45270
+ (0, import_node_fs38.renameSync)(`${path2}.tmp`, path2);
45154
45271
  this.resolverWritten.set(name, content);
45155
45272
  return true;
45156
45273
  } catch (err) {
@@ -45161,11 +45278,11 @@ var ThreatFeeds = class {
45161
45278
  const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
45162
45279
  const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
45163
45280
  const via = [];
45164
- if ((0, import_node_fs37.existsSync)(hooks.dnsmasq)) {
45281
+ if ((0, import_node_fs38.existsSync)(hooks.dnsmasq)) {
45165
45282
  via.push("dnsmasq");
45166
45283
  if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
45167
45284
  }
45168
- if ((0, import_node_fs37.existsSync)(hooks.unbound)) {
45285
+ if ((0, import_node_fs38.existsSync)(hooks.unbound)) {
45169
45286
  via.push("unbound");
45170
45287
  if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
45171
45288
  this.run("systemctl", ["reload", "unbound.service"]);
@@ -45226,8 +45343,8 @@ var ThreatFeeds = class {
45226
45343
  };
45227
45344
 
45228
45345
  // src/daemon/workers/privilege-watch.ts
45229
- var import_node_fs38 = require("fs");
45230
- var import_node_path29 = require("path");
45346
+ var import_node_fs39 = require("fs");
45347
+ var import_node_path30 = require("path");
45231
45348
  var import_node_child_process12 = require("child_process");
45232
45349
 
45233
45350
  // src/core/privileges/index.ts
@@ -45418,31 +45535,31 @@ function countryName(code) {
45418
45535
  var fsIO = {
45419
45536
  readFile: (p) => {
45420
45537
  try {
45421
- return (0, import_node_fs38.readFileSync)(p, "utf-8");
45538
+ return (0, import_node_fs39.readFileSync)(p, "utf-8");
45422
45539
  } catch {
45423
45540
  return null;
45424
45541
  }
45425
45542
  },
45426
45543
  readDir: (p) => {
45427
45544
  try {
45428
- return (0, import_node_fs38.readdirSync)(p);
45545
+ return (0, import_node_fs39.readdirSync)(p);
45429
45546
  } catch {
45430
45547
  return null;
45431
45548
  }
45432
45549
  },
45433
- exists: (p) => (0, import_node_fs38.existsSync)(p)
45550
+ exists: (p) => (0, import_node_fs39.existsSync)(p)
45434
45551
  };
45435
45552
  function readJson(path2) {
45436
45553
  try {
45437
- return JSON.parse((0, import_node_fs38.readFileSync)(path2, "utf-8"));
45554
+ return JSON.parse((0, import_node_fs39.readFileSync)(path2, "utf-8"));
45438
45555
  } catch {
45439
45556
  return null;
45440
45557
  }
45441
45558
  }
45442
45559
  function writeJson(path2, value) {
45443
- (0, import_node_fs38.mkdirSync)((0, import_node_path29.dirname)(path2), { recursive: true });
45444
- (0, import_node_fs38.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
45445
- (0, import_node_fs38.renameSync)(`${path2}.tmp`, path2);
45560
+ (0, import_node_fs39.mkdirSync)((0, import_node_path30.dirname)(path2), { recursive: true });
45561
+ (0, import_node_fs39.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
45562
+ (0, import_node_fs39.renameSync)(`${path2}.tmp`, path2);
45446
45563
  }
45447
45564
  function defaultRun3(cmd, args) {
45448
45565
  const res = (0, import_node_child_process12.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -45598,7 +45715,7 @@ var PrivilegeWatch = class {
45598
45715
  * raised a "new country" alert on its first run; on dev2 it did, at once.
45599
45716
  */
45600
45717
  async backfillLogins() {
45601
- if ((0, import_node_fs38.existsSync)(this.opts.loginsPath)) return;
45718
+ if ((0, import_node_fs39.existsSync)(this.opts.loginsPath)) return;
45602
45719
  const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
45603
45720
  const byUser = parseAcceptedLogins(out ?? "");
45604
45721
  const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
@@ -45611,7 +45728,7 @@ var PrivilegeWatch = class {
45611
45728
  return;
45612
45729
  }
45613
45730
  }
45614
- if ((0, import_node_fs38.existsSync)(this.opts.loginsPath)) return;
45731
+ if ((0, import_node_fs39.existsSync)(this.opts.loginsPath)) return;
45615
45732
  const at = this.now().toISOString();
45616
45733
  const history = {};
45617
45734
  for (const [user, userIps] of byUser) {
@@ -45676,6 +45793,23 @@ function expire(window, now) {
45676
45793
  window.head = 0;
45677
45794
  }
45678
45795
  }
45796
+ var EVIDENCE_MESSAGE_CHARS = 500;
45797
+ var EVIDENCE_FIELD_CHARS = 200;
45798
+ var EVIDENCE_FIELDS = ["unit", "identifier", "process", "comm", "pid", "user", "path", "method", "status", "host", "priority"];
45799
+ function evidenceOf(event) {
45800
+ const details = event.details ?? {};
45801
+ const out = {
45802
+ at: event.timestamp instanceof Date ? event.timestamp.toISOString() : String(event.timestamp ?? ""),
45803
+ module: event.module,
45804
+ message: String(event.message ?? "").slice(0, EVIDENCE_MESSAGE_CHARS)
45805
+ };
45806
+ if (event.source_ip) out.source_ip = event.source_ip;
45807
+ for (const k of EVIDENCE_FIELDS) {
45808
+ const v = details[k];
45809
+ if (typeof v === "string" || typeof v === "number") out[k] = String(v).slice(0, EVIDENCE_FIELD_CHARS);
45810
+ }
45811
+ return out;
45812
+ }
45679
45813
  var RuleEngine = class {
45680
45814
  constructor(onDetection) {
45681
45815
  this.onDetection = onDetection;
@@ -45744,6 +45878,9 @@ var RuleEngine = class {
45744
45878
  tags: rule.tags,
45745
45879
  category: rule.category,
45746
45880
  remediation: rule.remediation,
45881
+ // What actually happened: without this every alert, page and incident
45882
+ // could only repeat the rule's description ("a critical log message").
45883
+ evidence: evidenceOf(event),
45747
45884
  ...aggregate ? { group_by: groupBy, group: groupValue, distinct_ips: distinctIps, hits } : {}
45748
45885
  }
45749
45886
  });
@@ -45823,8 +45960,8 @@ var RuleEngine = class {
45823
45960
  };
45824
45961
 
45825
45962
  // src/daemon/rules/loader.ts
45826
- var import_node_fs39 = require("fs");
45827
- var import_node_path30 = require("path");
45963
+ var import_node_fs40 = require("fs");
45964
+ var import_node_path31 = require("path");
45828
45965
 
45829
45966
  // src/daemon/rules/default-rules.ts
45830
45967
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
@@ -46294,11 +46431,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
46294
46431
  function loadAllRules(customDir) {
46295
46432
  const rules = [...DEFAULT_RULES];
46296
46433
  const dir = customDir || RULES_DIR;
46297
- if ((0, import_node_fs39.existsSync)(dir)) {
46298
- const files = (0, import_node_fs39.readdirSync)(dir).filter((f) => f.endsWith(".json"));
46434
+ if ((0, import_node_fs40.existsSync)(dir)) {
46435
+ const files = (0, import_node_fs40.readdirSync)(dir).filter((f) => f.endsWith(".json"));
46299
46436
  for (const file of files) {
46300
46437
  try {
46301
- const raw = (0, import_node_fs39.readFileSync)((0, import_node_path30.join)(dir, file), "utf-8");
46438
+ const raw = (0, import_node_fs40.readFileSync)((0, import_node_path31.join)(dir, file), "utf-8");
46302
46439
  const parsed = JSON.parse(raw);
46303
46440
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
46304
46441
  for (const rule of customRules) {
@@ -46330,23 +46467,23 @@ function loadAllRules(customDir) {
46330
46467
 
46331
46468
  // src/daemon/firewall/adapters.ts
46332
46469
  var import_node_child_process13 = require("child_process");
46333
- var import_node_fs40 = require("fs");
46334
- var import_node_path31 = require("path");
46335
- var import_node_net11 = require("net");
46470
+ var import_node_fs41 = require("fs");
46471
+ var import_node_path32 = require("path");
46472
+ var import_node_net13 = require("net");
46336
46473
  function assertValidFirewallIp(ip) {
46337
- if ((0, import_node_net11.isIP)(ip) !== 4) {
46474
+ if ((0, import_node_net13.isIP)(ip) !== 4) {
46338
46475
  throw new Error(`Invalid IPv4 address: ${ip}`);
46339
46476
  }
46340
46477
  }
46341
46478
  function assertBannableIp(ip) {
46342
- if ((0, import_node_net11.isIP)(ip) === 0) {
46479
+ if ((0, import_node_net13.isIP)(ip) === 0) {
46343
46480
  throw new Error(`Invalid IP address: ${ip}`);
46344
46481
  }
46345
46482
  }
46346
46483
  function writeIfAbsent(path2, contents) {
46347
- (0, import_node_fs40.mkdirSync)((0, import_node_path31.dirname)(path2), { recursive: true });
46484
+ (0, import_node_fs41.mkdirSync)((0, import_node_path32.dirname)(path2), { recursive: true });
46348
46485
  try {
46349
- (0, import_node_fs40.writeFileSync)(path2, contents, { flag: "wx" });
46486
+ (0, import_node_fs41.writeFileSync)(path2, contents, { flag: "wx" });
46350
46487
  } catch (err) {
46351
46488
  if (err.code !== "EEXIST") throw err;
46352
46489
  }
@@ -46445,7 +46582,7 @@ var Fail2banAdapter = class {
46445
46582
  const status = this.client(["status", this.jail]);
46446
46583
  const line2 = status.split("\n").find((l) => /Banned IP list:/i.test(l));
46447
46584
  if (!line2) return [];
46448
- return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net11.isIP)(s) !== 0);
46585
+ return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net13.isIP)(s) !== 0);
46449
46586
  } catch {
46450
46587
  return [];
46451
46588
  }
@@ -46455,10 +46592,10 @@ var Fail2banAdapter = class {
46455
46592
  function parseBannedList(output) {
46456
46593
  const found = [];
46457
46594
  for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
46458
- if ((0, import_node_net11.isIP)(match[1]) !== 0) found.push(match[1]);
46595
+ if ((0, import_node_net13.isIP)(match[1]) !== 0) found.push(match[1]);
46459
46596
  }
46460
46597
  if (found.length > 0) return found;
46461
- return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net11.isIP)(s) !== 0);
46598
+ return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net13.isIP)(s) !== 0);
46462
46599
  }
46463
46600
  var NftablesAdapter = class {
46464
46601
  name = "nftables";
@@ -46605,9 +46742,9 @@ function detectFirewallAdapter(backend = "auto") {
46605
46742
  }
46606
46743
 
46607
46744
  // src/daemon/firewall/remediation.ts
46608
- var import_node_fs41 = require("fs");
46745
+ var import_node_fs42 = require("fs");
46609
46746
  var import_node_child_process14 = require("child_process");
46610
- var import_node_net12 = require("net");
46747
+ var import_node_net14 = require("net");
46611
46748
  init_paths();
46612
46749
  init_backoff();
46613
46750
 
@@ -46676,19 +46813,19 @@ var defaultDiscovery = {
46676
46813
  const snapshot = takeSnapshot({
46677
46814
  readFile: (p) => {
46678
46815
  try {
46679
- return (0, import_node_fs41.readFileSync)(p, "utf-8");
46816
+ return (0, import_node_fs42.readFileSync)(p, "utf-8");
46680
46817
  } catch {
46681
46818
  return null;
46682
46819
  }
46683
46820
  },
46684
46821
  readDir: (p) => {
46685
46822
  try {
46686
- return (0, import_node_fs41.readdirSync)(p);
46823
+ return (0, import_node_fs42.readdirSync)(p);
46687
46824
  } catch {
46688
46825
  return null;
46689
46826
  }
46690
46827
  },
46691
- exists: (p) => (0, import_node_fs41.existsSync)(p)
46828
+ exists: (p) => (0, import_node_fs42.existsSync)(p)
46692
46829
  });
46693
46830
  const out = /* @__PURE__ */ new Set();
46694
46831
  for (const keys of Object.values(snapshot.keys)) {
@@ -46696,12 +46833,12 @@ var defaultDiscovery = {
46696
46833
  }
46697
46834
  return out;
46698
46835
  },
46699
- keyLoginJournal: (sinceSeconds) => new Promise((resolve7) => {
46836
+ keyLoginJournal: (sinceSeconds) => new Promise((resolve8) => {
46700
46837
  (0, import_node_child_process14.execFile)(
46701
46838
  "journalctl",
46702
46839
  ["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
46703
46840
  { maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
46704
- (_err, stdout) => resolve7(stdout ?? "")
46841
+ (_err, stdout) => resolve8(stdout ?? "")
46705
46842
  );
46706
46843
  })
46707
46844
  };
@@ -46736,6 +46873,7 @@ var RemediationManager = class {
46736
46873
  this.config.allowlist = [...this.config.allowlist];
46737
46874
  this.protectedList = [...DEFAULT_PROTECTED, ...SHARED_INFRASTRUCTURE, ...this.config.allowlist];
46738
46875
  for (const gateway of defaultGateways()) this.protectedList.push(gateway);
46876
+ this.pinned = new Set(this.protectedList);
46739
46877
  if (this.adapter.enforces === false) this.config.dry_run = true;
46740
46878
  this.loadState();
46741
46879
  this.refreshSshProtection();
@@ -46751,6 +46889,12 @@ var RemediationManager = class {
46751
46889
  blocklist = [];
46752
46890
  strikes = {};
46753
46891
  protectedList = [];
46892
+ /**
46893
+ * What was protected at start: built-ins, shared infrastructure, the
46894
+ * operator's `[remediation] allowlist`, default gateways. The dashboard may
46895
+ * add to the protected set but never take these out of it.
46896
+ */
46897
+ pinned = /* @__PURE__ */ new Set();
46754
46898
  /** Operator address → last time seen (ms), persisted. */
46755
46899
  operators = {};
46756
46900
  expiryTimer = null;
@@ -46823,7 +46967,7 @@ var RemediationManager = class {
46823
46967
  if (remediation?.action !== "block") return;
46824
46968
  }
46825
46969
  const ip = event.source_ip;
46826
- if (!ip || (0, import_node_net12.isIP)(ip) === 0) return;
46970
+ if (!ip || (0, import_node_net14.isIP)(ip) === 0) return;
46827
46971
  if (this.isAllowlisted(ip)) return;
46828
46972
  if (this.blocklist.some((b) => b.ip === ip)) return;
46829
46973
  if (this.config.spare_verified_crawlers) {
@@ -46842,7 +46986,7 @@ var RemediationManager = class {
46842
46986
  * 4th offence and so on, clamped to `max_ban_seconds`.
46843
46987
  */
46844
46988
  async ban(ip, reason, opts = {}) {
46845
- if ((0, import_node_net12.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
46989
+ if ((0, import_node_net14.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
46846
46990
  if (this.isAllowlisted(ip)) {
46847
46991
  return { ok: false, error: `${ip} is protected and can never be blocked` };
46848
46992
  }
@@ -46999,6 +47143,10 @@ var RemediationManager = class {
46999
47143
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
47000
47144
  if (!this.config.allowlist.includes(ip)) this.config.allowlist.push(ip);
47001
47145
  }
47146
+ /** Protected since start (built-in, shared infrastructure, operator config, gateway): not removable from the cloud. */
47147
+ isPinned(ip) {
47148
+ return this.pinned.has(ip);
47149
+ }
47002
47150
  removeFromAllowlist(ip) {
47003
47151
  if (DEFAULT_PROTECTED.includes(ip)) return;
47004
47152
  this.protectedList = this.protectedList.filter((a) => a !== ip);
@@ -47105,7 +47253,7 @@ var RemediationManager = class {
47105
47253
  if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
47106
47254
  const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
47107
47255
  for (const [ip, at] of Object.entries(saved)) {
47108
- if (typeof at !== "number" || at < cutoff || !(0, import_node_net12.isIP)(ip)) continue;
47256
+ if (typeof at !== "number" || at < cutoff || !(0, import_node_net14.isIP)(ip)) continue;
47109
47257
  this.operators[ip] = at;
47110
47258
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
47111
47259
  }
@@ -47129,7 +47277,7 @@ var RemediationManager = class {
47129
47277
  }
47130
47278
  logLine(line2) {
47131
47279
  try {
47132
- (0, import_node_fs41.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47280
+ (0, import_node_fs42.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47133
47281
  `);
47134
47282
  } catch {
47135
47283
  }
@@ -47172,19 +47320,19 @@ function remediationSettings(section) {
47172
47320
  init_backoff();
47173
47321
 
47174
47322
  // src/daemon/watchdog-service.ts
47175
- var import_node_fs42 = require("fs");
47176
- var import_node_path32 = require("path");
47323
+ var import_node_fs43 = require("fs");
47324
+ var import_node_path33 = require("path");
47177
47325
  function defaultShareGid() {
47178
47326
  const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
47179
47327
  if (!isRoot4) return void 0;
47180
47328
  try {
47181
- return (0, import_node_fs42.statSync)("/var/log/auth.log").gid;
47329
+ return (0, import_node_fs43.statSync)("/var/log/auth.log").gid;
47182
47330
  } catch {
47183
47331
  return void 0;
47184
47332
  }
47185
47333
  }
47186
47334
  function startWatchdog(opts) {
47187
- const dir = opts.config?.dir ?? (0, import_node_path32.join)(opts.stateDir, WATCHDOG_DIRNAME);
47335
+ const dir = opts.config?.dir ?? (0, import_node_path33.join)(opts.stateDir, WATCHDOG_DIRNAME);
47188
47336
  const base = { dir, logged: 0, answered: 0, errored: 0 };
47189
47337
  if (opts.config?.enabled === false) {
47190
47338
  opts.log("[watchdog] off ([watchdog] enabled = false)");
@@ -47299,7 +47447,7 @@ function versionOfNode(path2) {
47299
47447
  // src/daemon/index.ts
47300
47448
  function readVersion2() {
47301
47449
  try {
47302
- const pkg = JSON.parse((0, import_node_fs43.readFileSync)((0, import_node_path33.join)(__dirname, "..", "package.json"), "utf-8"));
47450
+ const pkg = JSON.parse((0, import_node_fs44.readFileSync)((0, import_node_path34.join)(__dirname, "..", "package.json"), "utf-8"));
47303
47451
  return pkg.version || "0.0.0";
47304
47452
  } catch {
47305
47453
  return "0.0.0";
@@ -47308,7 +47456,7 @@ function readVersion2() {
47308
47456
  async function runHardeningChecks() {
47309
47457
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
47310
47458
  process.execPath,
47311
- [(0, import_node_path33.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
47459
+ [(0, import_node_path34.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
47312
47460
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
47313
47461
  );
47314
47462
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -47322,7 +47470,7 @@ async function runHardeningChecks() {
47322
47470
  async function runPatchCheck() {
47323
47471
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
47324
47472
  process.execPath,
47325
- [(0, import_node_path33.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
47473
+ [(0, import_node_path34.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
47326
47474
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
47327
47475
  );
47328
47476
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -47330,7 +47478,7 @@ async function runPatchCheck() {
47330
47478
  }
47331
47479
  function logLine(line2) {
47332
47480
  try {
47333
- (0, import_node_fs43.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47481
+ (0, import_node_fs44.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47334
47482
  `);
47335
47483
  } catch {
47336
47484
  }
@@ -47372,7 +47520,7 @@ async function runDaemon() {
47372
47520
  } catch (err) {
47373
47521
  logLine(`[daemon] state db unavailable: ${err.message}`);
47374
47522
  }
47375
- const config = loadConfig((0, import_node_fs43.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
47523
+ const config = loadConfig((0, import_node_fs44.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
47376
47524
  configureAttackDetection(config.detection);
47377
47525
  const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
47378
47526
  const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
@@ -47436,7 +47584,7 @@ async function runDaemon() {
47436
47584
  const threatFeeds = new ThreatFeeds({
47437
47585
  settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
47438
47586
  enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
47439
- cachePath: (0, import_node_path33.join)(PATHS.stateDir, "threat-feeds.json"),
47587
+ cachePath: (0, import_node_path34.join)(PATHS.stateDir, "threat-feeds.json"),
47440
47588
  bus,
47441
47589
  log: logLine
47442
47590
  });
@@ -47444,14 +47592,18 @@ async function runDaemon() {
47444
47592
  const privilegeWatch = new PrivilegeWatch({
47445
47593
  settings: privilegeSettings(config.privileged),
47446
47594
  bus,
47447
- snapshotPath: (0, import_node_path33.join)(PATHS.stateDir, "privileges.json"),
47448
- loginsPath: (0, import_node_path33.join)(PATHS.stateDir, "login-countries.json"),
47449
- cursorPath: (0, import_node_path33.join)(PATHS.stateDir, "sudo-cursor.json"),
47595
+ snapshotPath: (0, import_node_path34.join)(PATHS.stateDir, "privileges.json"),
47596
+ loginsPath: (0, import_node_path34.join)(PATHS.stateDir, "login-countries.json"),
47597
+ cursorPath: (0, import_node_path34.join)(PATHS.stateDir, "sudo-cursor.json"),
47450
47598
  log: logLine
47451
47599
  });
47452
47600
  privilegeWatch.start();
47453
47601
  new AlertDispatcher(bus, config);
47454
- const runsWorker = new RunsWorker(bus);
47602
+ const runsWorker = new RunsWorker(bus, {
47603
+ enabled: config.cloud?.enabled !== false && config.cloud?.runs === true,
47604
+ scanRoots: Array.isArray(config.cloud?.run_scan_paths) ? config.cloud.run_scan_paths.filter((p) => typeof p === "string") : [],
47605
+ log: logLine
47606
+ });
47455
47607
  try {
47456
47608
  await runsWorker.start();
47457
47609
  } catch (err) {
@@ -47470,7 +47622,7 @@ async function runDaemon() {
47470
47622
  version,
47471
47623
  hostname: (0, import_node_os13.hostname)(),
47472
47624
  minSeverity,
47473
- spoolPath: (0, import_node_path33.join)(PATHS.stateDir, "cloud-spool.jsonl"),
47625
+ spoolPath: (0, import_node_path34.join)(PATHS.stateDir, "cloud-spool.jsonl"),
47474
47626
  log: logLine,
47475
47627
  ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
47476
47628
  runHardening: runHardeningChecks
@@ -47494,8 +47646,8 @@ async function runDaemon() {
47494
47646
  const autoUpdate = autoUpdateRef = new AutoUpdate({
47495
47647
  version,
47496
47648
  settings: updateSettings(config.update),
47497
- pkgRoot: (0, import_node_path33.join)(__dirname, ".."),
47498
- statePath: (0, import_node_path33.join)(PATHS.stateDir, "auto-update.json"),
47649
+ pkgRoot: (0, import_node_path34.join)(__dirname, ".."),
47650
+ statePath: (0, import_node_path34.join)(PATHS.stateDir, "auto-update.json"),
47499
47651
  bus,
47500
47652
  log: logLine,
47501
47653
  restartDaemon
@@ -47585,7 +47737,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
47585
47737
  function isRoot2() {
47586
47738
  return typeof process.getuid === "function" && process.getuid() === 0;
47587
47739
  }
47588
- var DAEMON_ENTRY = (0, import_node_path34.join)(__dirname, "daemon.js");
47740
+ var DAEMON_ENTRY = (0, import_node_path35.join)(__dirname, "daemon.js");
47589
47741
  async function daemonForeground() {
47590
47742
  await runDaemon();
47591
47743
  }
@@ -47606,7 +47758,7 @@ async function daemonStart() {
47606
47758
  return;
47607
47759
  }
47608
47760
  ensureRuntimeDirs();
47609
- if (!(0, import_node_fs44.existsSync)(DAEMON_ENTRY)) {
47761
+ if (!(0, import_node_fs45.existsSync)(DAEMON_ENTRY)) {
47610
47762
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
47611
47763
  console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
47612
47764
  return;
@@ -47614,8 +47766,8 @@ async function daemonStart() {
47614
47766
  let out;
47615
47767
  let err;
47616
47768
  try {
47617
- out = (0, import_node_fs45.openSync)(PATHS.logFile, "a");
47618
- err = (0, import_node_fs45.openSync)(PATHS.logFile, "a");
47769
+ out = (0, import_node_fs46.openSync)(PATHS.logFile, "a");
47770
+ err = (0, import_node_fs46.openSync)(PATHS.logFile, "a");
47619
47771
  } catch (e) {
47620
47772
  const code = e.code;
47621
47773
  console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
@@ -47703,12 +47855,12 @@ async function waitForExit(pid, timeoutMs) {
47703
47855
  }
47704
47856
  async function releaseStaleSocket() {
47705
47857
  const deadline = Date.now() + 2e3;
47706
- while ((0, import_node_fs44.existsSync)(PATHS.socket) && Date.now() < deadline) {
47858
+ while ((0, import_node_fs45.existsSync)(PATHS.socket) && Date.now() < deadline) {
47707
47859
  await new Promise((r) => setTimeout(r, 50));
47708
47860
  }
47709
- if ((0, import_node_fs44.existsSync)(PATHS.socket)) {
47861
+ if ((0, import_node_fs45.existsSync)(PATHS.socket)) {
47710
47862
  try {
47711
- (0, import_node_fs44.unlinkSync)(PATHS.socket);
47863
+ (0, import_node_fs45.unlinkSync)(PATHS.socket);
47712
47864
  } catch {
47713
47865
  }
47714
47866
  }
@@ -47716,26 +47868,26 @@ async function releaseStaleSocket() {
47716
47868
 
47717
47869
  // src/commands/service.ts
47718
47870
  var import_node_child_process18 = require("child_process");
47719
- var import_node_fs46 = require("fs");
47720
- var import_node_path35 = require("path");
47871
+ var import_node_fs47 = require("fs");
47872
+ var import_node_path36 = require("path");
47721
47873
  var import_node_os14 = require("os");
47722
47874
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
47723
47875
  var DAEMON_UNIT_NAME = "threatcrushd.service";
47724
47876
  function resolveTemplate() {
47725
- const templatePath = (0, import_node_path35.join)(__dirname, "systemd", "threatcrushd.service");
47726
- if (!(0, import_node_fs46.existsSync)(templatePath)) {
47877
+ const templatePath = (0, import_node_path36.join)(__dirname, "systemd", "threatcrushd.service");
47878
+ if (!(0, import_node_fs47.existsSync)(templatePath)) {
47727
47879
  throw new Error(`systemd unit template not found at ${templatePath}`);
47728
47880
  }
47729
- return (0, import_node_fs46.readFileSync)(templatePath, "utf-8");
47881
+ return (0, import_node_fs47.readFileSync)(templatePath, "utf-8");
47730
47882
  }
47731
47883
  function stableBinPath(binPath) {
47732
47884
  const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
47733
47885
  if (stable === binPath) return binPath;
47734
- return (0, import_node_fs46.existsSync)(stable) ? stable : binPath;
47886
+ return (0, import_node_fs47.existsSync)(stable) ? stable : binPath;
47735
47887
  }
47736
47888
  function resolveBinPath() {
47737
47889
  const arg = process.argv[1];
47738
- if (arg && (0, import_node_fs46.existsSync)(arg)) return stableBinPath(arg);
47890
+ if (arg && (0, import_node_fs47.existsSync)(arg)) return stableBinPath(arg);
47739
47891
  try {
47740
47892
  return (0, import_node_child_process18.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
47741
47893
  } catch {
@@ -47745,11 +47897,11 @@ function resolveBinPath() {
47745
47897
  function stableNodePath(execPath) {
47746
47898
  const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
47747
47899
  if (stable === execPath) return execPath;
47748
- return (0, import_node_fs46.existsSync)(stable) ? stable : execPath;
47900
+ return (0, import_node_fs47.existsSync)(stable) ? stable : execPath;
47749
47901
  }
47750
47902
  function looksLikeNodeScript(path2) {
47751
47903
  try {
47752
- const head = (0, import_node_fs46.readFileSync)(path2, "utf-8").slice(0, 120);
47904
+ const head = (0, import_node_fs47.readFileSync)(path2, "utf-8").slice(0, 120);
47753
47905
  return /^#!.*\bnode\b/.test(head);
47754
47906
  } catch {
47755
47907
  return false;
@@ -47789,7 +47941,7 @@ function callerHome() {
47789
47941
  try {
47790
47942
  const line2 = (0, import_node_child_process18.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
47791
47943
  const home = line2.split(":")[5];
47792
- return home && (0, import_node_fs46.existsSync)(home) ? home : null;
47944
+ return home && (0, import_node_fs47.existsSync)(home) ? home : null;
47793
47945
  } catch {
47794
47946
  return null;
47795
47947
  }
@@ -47797,13 +47949,13 @@ function callerHome() {
47797
47949
  function stopUserModeDaemon() {
47798
47950
  const home = callerHome();
47799
47951
  if (!home) return;
47800
- const runDir = (0, import_node_path35.join)(home, ".threatcrush", "run");
47801
- const pidFile = (0, import_node_path35.join)(runDir, "threatcrushd.pid");
47802
- const socket = (0, import_node_path35.join)(runDir, "threatcrushd.sock");
47803
- if (!(0, import_node_fs46.existsSync)(pidFile) && !(0, import_node_fs46.existsSync)(socket)) return;
47952
+ const runDir = (0, import_node_path36.join)(home, ".threatcrush", "run");
47953
+ const pidFile = (0, import_node_path36.join)(runDir, "threatcrushd.pid");
47954
+ const socket = (0, import_node_path36.join)(runDir, "threatcrushd.sock");
47955
+ if (!(0, import_node_fs47.existsSync)(pidFile) && !(0, import_node_fs47.existsSync)(socket)) return;
47804
47956
  let pid = null;
47805
47957
  try {
47806
- pid = Number.parseInt((0, import_node_fs46.readFileSync)(pidFile, "utf-8").trim(), 10);
47958
+ pid = Number.parseInt((0, import_node_fs47.readFileSync)(pidFile, "utf-8").trim(), 10);
47807
47959
  } catch {
47808
47960
  pid = null;
47809
47961
  }
@@ -47816,7 +47968,7 @@ function stopUserModeDaemon() {
47816
47968
  }
47817
47969
  for (const path2 of [socket, pidFile]) {
47818
47970
  try {
47819
- if ((0, import_node_fs46.existsSync)(path2)) (0, import_node_fs46.rmSync)(path2);
47971
+ if ((0, import_node_fs47.existsSync)(path2)) (0, import_node_fs47.rmSync)(path2);
47820
47972
  } catch {
47821
47973
  }
47822
47974
  }
@@ -47834,7 +47986,7 @@ async function installServiceCommand() {
47834
47986
  }
47835
47987
  const noSystemd = systemdUnavailableReason({
47836
47988
  hasSystemctl: (0, import_node_child_process18.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
47837
- booted: (0, import_node_fs46.existsSync)("/run/systemd/system")
47989
+ booted: (0, import_node_fs47.existsSync)("/run/systemd/system")
47838
47990
  });
47839
47991
  if (noSystemd) {
47840
47992
  console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
@@ -47856,7 +48008,7 @@ async function installServiceCommand() {
47856
48008
  const isNodeScript = looksLikeNodeScript(binPath);
47857
48009
  let nodePath = stableNodePath(process.execPath);
47858
48010
  if (isNodeScript && nodeVersionDir(binPath)) {
47859
- binPath = (0, import_node_fs46.realpathSync)(binPath);
48011
+ binPath = (0, import_node_fs47.realpathSync)(binPath);
47860
48012
  nodePath = process.execPath;
47861
48013
  }
47862
48014
  if (isNodeScript) {
@@ -47869,9 +48021,9 @@ async function installServiceCommand() {
47869
48021
  }
47870
48022
  }
47871
48023
  const exec = execStartCommand(binPath, nodePath, isNodeScript);
47872
- const configDir = (0, import_node_path35.join)((0, import_node_os14.homedir)(), ".threatcrush");
48024
+ const configDir = (0, import_node_path36.join)((0, import_node_os14.homedir)(), ".threatcrush");
47873
48025
  const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
47874
- (0, import_node_fs46.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
48026
+ (0, import_node_fs47.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
47875
48027
  console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
47876
48028
  console.log(source_default.dim(` ExecStart=${exec}`));
47877
48029
  const nodeDir = nodeVersionDir(nodePath);
@@ -47924,9 +48076,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
47924
48076
  ].join("\n");
47925
48077
  }
47926
48078
  function installLogrotate() {
47927
- if (!(0, import_node_fs46.existsSync)((0, import_node_path35.dirname)(LOGROTATE_PATH))) return;
48079
+ if (!(0, import_node_fs47.existsSync)((0, import_node_path36.dirname)(LOGROTATE_PATH))) return;
47928
48080
  try {
47929
- (0, import_node_fs46.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
48081
+ (0, import_node_fs47.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
47930
48082
  console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
47931
48083
  } catch (err) {
47932
48084
  console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
@@ -47948,20 +48100,20 @@ function ensureSystemDirs(configDir) {
47948
48100
  ];
47949
48101
  let admGid2 = null;
47950
48102
  try {
47951
- admGid2 = (0, import_node_fs46.statSync)("/var/log/auth.log").gid;
48103
+ admGid2 = (0, import_node_fs47.statSync)("/var/log/auth.log").gid;
47952
48104
  } catch {
47953
48105
  }
47954
48106
  for (const { path: path2, groupWritable, sticky } of dirs) {
47955
48107
  try {
47956
- (0, import_node_fs46.mkdirSync)(path2, { recursive: true });
48108
+ (0, import_node_fs47.mkdirSync)(path2, { recursive: true });
47957
48109
  } catch {
47958
48110
  }
47959
48111
  try {
47960
48112
  if (groupWritable && admGid2 !== null) {
47961
- (0, import_node_fs46.chmodSync)(path2, sticky ? 1533 : 509);
48113
+ (0, import_node_fs47.chmodSync)(path2, sticky ? 1533 : 509);
47962
48114
  (0, import_node_child_process18.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
47963
48115
  } else {
47964
- (0, import_node_fs46.chmodSync)(path2, 493);
48116
+ (0, import_node_fs47.chmodSync)(path2, 493);
47965
48117
  }
47966
48118
  } catch {
47967
48119
  }
@@ -47989,7 +48141,7 @@ async function uninstallServiceCommand() {
47989
48141
  } catch {
47990
48142
  }
47991
48143
  try {
47992
- if ((0, import_node_fs46.existsSync)(UNIT_PATH)) {
48144
+ if ((0, import_node_fs47.existsSync)(UNIT_PATH)) {
47993
48145
  (0, import_node_child_process18.execSync)(`rm -f ${UNIT_PATH}`);
47994
48146
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
47995
48147
  }
@@ -48003,7 +48155,7 @@ async function uninstallServiceCommand() {
48003
48155
  }
48004
48156
 
48005
48157
  // src/commands/save.ts
48006
- var import_node_fs47 = require("fs");
48158
+ var import_node_fs48 = require("fs");
48007
48159
  var import_toml5 = __toESM(require_toml());
48008
48160
  init_cli_config();
48009
48161
  init_paths();
@@ -48042,9 +48194,9 @@ async function saveCommand(opts = {}) {
48042
48194
  }
48043
48195
  const path2 = opts.config ?? PATHS.configFile;
48044
48196
  let config = {};
48045
- if ((0, import_node_fs47.existsSync)(path2)) {
48197
+ if ((0, import_node_fs48.existsSync)(path2)) {
48046
48198
  try {
48047
- config = import_toml5.default.parse((0, import_node_fs47.readFileSync)(path2, "utf-8"));
48199
+ config = import_toml5.default.parse((0, import_node_fs48.readFileSync)(path2, "utf-8"));
48048
48200
  } catch (err) {
48049
48201
  console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
48050
48202
  `));
@@ -48157,17 +48309,17 @@ function welcomeCommand() {
48157
48309
  }
48158
48310
 
48159
48311
  // src/commands/properties.ts
48160
- var import_node_fs48 = require("fs");
48161
- var import_node_path36 = require("path");
48312
+ var import_node_fs49 = require("fs");
48313
+ var import_node_path37 = require("path");
48162
48314
  var import_node_readline4 = __toESM(require("readline"));
48163
48315
  init_cli_config();
48164
48316
  var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
48165
48317
  var KINDS = ["url", "api", "domain", "ip", "repo"];
48166
48318
  function prompt(question) {
48167
48319
  const rl = import_node_readline4.default.createInterface({ input: process.stdin, output: process.stdout });
48168
- return new Promise((resolve7) => rl.question(question, (answer) => {
48320
+ return new Promise((resolve8) => rl.question(question, (answer) => {
48169
48321
  rl.close();
48170
- resolve7(answer.trim());
48322
+ resolve8(answer.trim());
48171
48323
  }));
48172
48324
  }
48173
48325
  async function requireAuth() {
@@ -48488,8 +48640,8 @@ async function propertiesRunsCommand(opts) {
48488
48640
  }
48489
48641
  }
48490
48642
  function parseImportFile(path2) {
48491
- const ext = (0, import_node_path36.extname)(path2).toLowerCase();
48492
- const raw = (0, import_node_fs48.readFileSync)(path2, "utf-8");
48643
+ const ext = (0, import_node_path37.extname)(path2).toLowerCase();
48644
+ const raw = (0, import_node_fs49.readFileSync)(path2, "utf-8");
48493
48645
  if (ext === ".json") {
48494
48646
  const parsed = JSON.parse(raw);
48495
48647
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -48684,7 +48836,7 @@ async function rulesCommand(opts) {
48684
48836
  }
48685
48837
 
48686
48838
  // src/commands/harden.ts
48687
- var import_node_fs49 = require("fs");
48839
+ var import_node_fs50 = require("fs");
48688
48840
  var import_node_child_process19 = require("child_process");
48689
48841
  init_cli_config();
48690
48842
  function tryExec(cmd) {
@@ -48696,7 +48848,7 @@ function tryExec(cmd) {
48696
48848
  }
48697
48849
  function tryRead(path2) {
48698
48850
  try {
48699
- return (0, import_node_fs49.readFileSync)(path2, "utf-8");
48851
+ return (0, import_node_fs50.readFileSync)(path2, "utf-8");
48700
48852
  } catch {
48701
48853
  return null;
48702
48854
  }
@@ -48800,8 +48952,8 @@ function checkSshWeakConfig() {
48800
48952
  };
48801
48953
  }
48802
48954
  function checkAutoUpdates() {
48803
- const unattended = (0, import_node_fs49.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs49.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
48804
- const dnfAuto = (0, import_node_fs49.existsSync)("/etc/dnf/automatic.conf");
48955
+ const unattended = (0, import_node_fs50.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs50.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
48956
+ const dnfAuto = (0, import_node_fs50.existsSync)("/etc/dnf/automatic.conf");
48805
48957
  if (unattended || dnfAuto) {
48806
48958
  return {
48807
48959
  key: "auto-updates",
@@ -48927,7 +49079,7 @@ function checkFail2ban() {
48927
49079
  explanation: "fail2ban is installed and running."
48928
49080
  };
48929
49081
  }
48930
- if ((0, import_node_fs49.existsSync)("/etc/fail2ban/fail2ban.conf")) {
49082
+ if ((0, import_node_fs50.existsSync)("/etc/fail2ban/fail2ban.conf")) {
48931
49083
  return {
48932
49084
  key: checkKey,
48933
49085
  status: "warn",
@@ -49113,8 +49265,8 @@ async function hardenCommand(opts) {
49113
49265
  }
49114
49266
 
49115
49267
  // src/core/patches/index.ts
49116
- var import_node_fs50 = require("fs");
49117
- var import_node_path37 = require("path");
49268
+ var import_node_fs51 = require("fs");
49269
+ var import_node_path38 = require("path");
49118
49270
  var import_node_child_process20 = require("child_process");
49119
49271
  var import_node_util5 = require("util");
49120
49272
 
@@ -49274,9 +49426,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
49274
49426
  function newestReleaseMtime(dir) {
49275
49427
  try {
49276
49428
  let newest = 0;
49277
- for (const name of (0, import_node_fs50.readdirSync)(dir)) {
49429
+ for (const name of (0, import_node_fs51.readdirSync)(dir)) {
49278
49430
  if (!/Release$/.test(name)) continue;
49279
- newest = Math.max(newest, (0, import_node_fs50.statSync)((0, import_node_path37.join)(dir, name)).mtimeMs);
49431
+ newest = Math.max(newest, (0, import_node_fs51.statSync)((0, import_node_path38.join)(dir, name)).mtimeMs);
49280
49432
  }
49281
49433
  return newest > 0 ? new Date(newest) : null;
49282
49434
  } catch {
@@ -49293,7 +49445,7 @@ async function checkPatches(opts = {}) {
49293
49445
  let osText = opts.osRelease;
49294
49446
  if (osText === void 0) {
49295
49447
  try {
49296
- osText = (0, import_node_fs50.readFileSync)("/etc/os-release", "utf-8");
49448
+ osText = (0, import_node_fs51.readFileSync)("/etc/os-release", "utf-8");
49297
49449
  } catch {
49298
49450
  osText = "";
49299
49451
  }
@@ -49519,25 +49671,25 @@ async function patchesCommand(opts) {
49519
49671
  }
49520
49672
 
49521
49673
  // src/commands/feeds.ts
49522
- var import_node_net13 = require("net");
49523
- var import_node_path39 = require("path");
49674
+ var import_node_net15 = require("net");
49675
+ var import_node_path40 = require("path");
49524
49676
  init_paths();
49525
49677
 
49526
49678
  // src/commands/feeds-resolver.ts
49527
49679
  var import_node_child_process21 = require("child_process");
49528
- var import_node_fs51 = require("fs");
49529
- var import_node_path38 = require("path");
49680
+ var import_node_fs52 = require("fs");
49681
+ var import_node_path39 = require("path");
49530
49682
  var realIO = {
49531
- exists: (p) => (0, import_node_fs51.existsSync)(p),
49683
+ exists: (p) => (0, import_node_fs52.existsSync)(p),
49532
49684
  read: (p) => {
49533
49685
  try {
49534
- return (0, import_node_fs51.readFileSync)(p, "utf-8");
49686
+ return (0, import_node_fs52.readFileSync)(p, "utf-8");
49535
49687
  } catch {
49536
49688
  return null;
49537
49689
  }
49538
49690
  },
49539
- write: (p, c) => (0, import_node_fs51.writeFileSync)(p, c),
49540
- remove: (p) => (0, import_node_fs51.rmSync)(p, { force: true }),
49691
+ write: (p, c) => (0, import_node_fs52.writeFileSync)(p, c),
49692
+ remove: (p) => (0, import_node_fs52.rmSync)(p, { force: true }),
49541
49693
  run: (cmd, args) => {
49542
49694
  const r = (0, import_node_child_process21.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
49543
49695
  return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
@@ -49547,17 +49699,17 @@ var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
49547
49699
  var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
49548
49700
  function hookContent(resolver, stateDir) {
49549
49701
  const head = "# Installed by `threatcrush feeds resolver install`; `threatcrush feeds resolver remove` takes it out.\n";
49550
- return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.hosts)}
49551
- ` : `${head}include: "${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound)}"
49702
+ return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path39.join)(stateDir, RESOLVER_FILES.hosts)}
49703
+ ` : `${head}include: "${(0, import_node_path39.join)(stateDir, RESOLVER_FILES.unbound)}"
49552
49704
  `;
49553
49705
  }
49554
49706
  function apparmorRule(stateDir) {
49555
- return ` ${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
49707
+ return ` ${(0, import_node_path39.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
49556
49708
  }
49557
49709
  function detectResolvers(io = realIO) {
49558
49710
  const found = [];
49559
- if (io.exists((0, import_node_path38.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
49560
- if (io.exists((0, import_node_path38.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
49711
+ if (io.exists((0, import_node_path39.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
49712
+ if (io.exists((0, import_node_path39.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
49561
49713
  return found;
49562
49714
  }
49563
49715
  function check(resolver, io) {
@@ -49570,7 +49722,7 @@ function restartIfActive(resolver, io) {
49570
49722
  }
49571
49723
  function installHook(resolver, stateDir, io = realIO) {
49572
49724
  const hook = RESOLVER_HOOKS[resolver];
49573
- const file = (0, import_node_path38.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
49725
+ const file = (0, import_node_path39.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
49574
49726
  if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
49575
49727
  io.write(hook, hookContent(resolver, stateDir));
49576
49728
  if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
@@ -49631,8 +49783,8 @@ function resolverCommand(sub, stateDir, io = realIO) {
49631
49783
  }
49632
49784
  return failed ? 1 : 0;
49633
49785
  }
49634
- const hosts = io.read((0, import_node_path38.join)(stateDir, RESOLVER_FILES.hosts));
49635
- const unbound = io.read((0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound));
49786
+ const hosts = io.read((0, import_node_path39.join)(stateDir, RESOLVER_FILES.hosts));
49787
+ const unbound = io.read((0, import_node_path39.join)(stateDir, RESOLVER_FILES.unbound));
49636
49788
  console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
49637
49789
  for (const r of ["dnsmasq", "unbound"]) {
49638
49790
  console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
@@ -49644,11 +49796,11 @@ function resolverCommand(sub, stateDir, io = realIO) {
49644
49796
  // src/commands/feeds.ts
49645
49797
  async function loadSet() {
49646
49798
  for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
49647
- const path2 = (0, import_node_path39.join)(dir, "threat-feeds.json");
49799
+ const path2 = (0, import_node_path40.join)(dir, "threat-feeds.json");
49648
49800
  const set = readFeedCache(path2);
49649
49801
  if (set) return { set, from: path2 };
49650
49802
  }
49651
- const settings = threatFeedSettings(loadConfig((0, import_node_path39.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
49803
+ const settings = threatFeedSettings(loadConfig((0, import_node_path40.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
49652
49804
  return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
49653
49805
  }
49654
49806
  async function feedsCommand(action, value, opts) {
@@ -49663,8 +49815,8 @@ async function feedsCommand(action, value, opts) {
49663
49815
  process.exitCode = 2;
49664
49816
  return;
49665
49817
  }
49666
- const ipHit = (0, import_node_net13.isIP)(value) ? matchIp(value, set) : null;
49667
- const domainHit = (0, import_node_net13.isIP)(value) ? null : matchDomain(value, set);
49818
+ const ipHit = (0, import_node_net15.isIP)(value) ? matchIp(value, set) : null;
49819
+ const domainHit = (0, import_node_net15.isIP)(value) ? null : matchDomain(value, set);
49668
49820
  const listed = ipHit ?? domainHit?.indicator ?? null;
49669
49821
  if (opts.json) {
49670
49822
  console.log(JSON.stringify({ value, listed: Boolean(listed), indicator: listed, matched: domainHit?.domain ?? (ipHit ? value : null), fetched_at: set.fetched_at }, null, 2));
@@ -49693,13 +49845,13 @@ async function feedsCommand(action, value, opts) {
49693
49845
 
49694
49846
  // src/commands/reputation.ts
49695
49847
  var import_node_os15 = require("os");
49696
- var import_node_fs52 = require("fs");
49697
- var import_node_path40 = require("path");
49848
+ var import_node_fs53 = require("fs");
49849
+ var import_node_path41 = require("path");
49698
49850
  var API_URL7 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
49699
- var CONFIG_PATH4 = (0, import_node_path40.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
49851
+ var CONFIG_PATH4 = (0, import_node_path41.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
49700
49852
  function readConfig3() {
49701
49853
  try {
49702
- return JSON.parse((0, import_node_fs52.readFileSync)(CONFIG_PATH4, "utf-8"));
49854
+ return JSON.parse((0, import_node_fs53.readFileSync)(CONFIG_PATH4, "utf-8"));
49703
49855
  } catch {
49704
49856
  return {};
49705
49857
  }
@@ -49887,7 +50039,7 @@ async function reputationSubscribeCommand(opts) {
49887
50039
  }
49888
50040
 
49889
50041
  // src/commands/privileged.ts
49890
- var import_node_fs53 = require("fs");
50042
+ var import_node_fs54 = require("fs");
49891
50043
  init_paths();
49892
50044
  var SEV2 = {
49893
50045
  critical: source_default.red.bold,
@@ -49900,19 +50052,19 @@ async function privilegedCommand(opts) {
49900
50052
  const snapshot = takeSnapshot({
49901
50053
  readFile: (p) => {
49902
50054
  try {
49903
- return (0, import_node_fs53.readFileSync)(p, "utf-8");
50055
+ return (0, import_node_fs54.readFileSync)(p, "utf-8");
49904
50056
  } catch {
49905
50057
  return null;
49906
50058
  }
49907
50059
  },
49908
50060
  readDir: (p) => {
49909
50061
  try {
49910
- return (0, import_node_fs53.readdirSync)(p);
50062
+ return (0, import_node_fs54.readdirSync)(p);
49911
50063
  } catch {
49912
50064
  return null;
49913
50065
  }
49914
50066
  },
49915
- exists: (p) => (0, import_node_fs53.existsSync)(p)
50067
+ exists: (p) => (0, import_node_fs54.existsSync)(p)
49916
50068
  });
49917
50069
  let events = [];
49918
50070
  let ledgerNote = "";
@@ -50094,7 +50246,7 @@ async function allowlistCommand(opts) {
50094
50246
  }
50095
50247
 
50096
50248
  // src/commands/abuse.ts
50097
- var import_node_fs54 = require("fs");
50249
+ var import_node_fs55 = require("fs");
50098
50250
  init_paths();
50099
50251
  function rows(records) {
50100
50252
  if (records.length === 0) {
@@ -50154,7 +50306,7 @@ function abuseRetractCommand(id, opts = {}) {
50154
50306
  );
50155
50307
  }
50156
50308
  function abuseStatusCommand(opts = {}) {
50157
- const config = loadConfig((0, import_node_fs54.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
50309
+ const config = loadConfig((0, import_node_fs55.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
50158
50310
  const cfg = resolveConfig(config.abuse_reporter);
50159
50311
  const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
50160
50312
  const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
@@ -50324,7 +50476,7 @@ function installUserAgent(target = globalThis) {
50324
50476
  // src/core/cloud-upload.ts
50325
50477
  var import_node_child_process23 = require("child_process");
50326
50478
  var import_node_os16 = require("os");
50327
- var import_node_path41 = require("path");
50479
+ var import_node_path42 = require("path");
50328
50480
  init_cli_config();
50329
50481
  function uploadDisabled(upload, env3 = process.env) {
50330
50482
  if (upload === false) return true;
@@ -50343,8 +50495,8 @@ function cleanUrl(raw) {
50343
50495
  return raw.split(/[?#]/)[0];
50344
50496
  }
50345
50497
  }
50346
- function repoTarget(path2, run = (args) => (0, import_node_child_process23.execFileSync)("git", args, { cwd: (0, import_node_path41.resolve)(path2), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim()) {
50347
- const abs = (0, import_node_path41.resolve)(path2);
50498
+ function repoTarget(path2, run = (args) => (0, import_node_child_process23.execFileSync)("git", args, { cwd: (0, import_node_path42.resolve)(path2), encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5e3 }).trim()) {
50499
+ const abs = (0, import_node_path42.resolve)(path2);
50348
50500
  try {
50349
50501
  const root = run(["rev-parse", "--show-toplevel"]);
50350
50502
  const sub = abs === root ? "." : abs.slice(root.length + 1);
@@ -50716,7 +50868,7 @@ ${source_default.dim(" C R U S H")}
50716
50868
  var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
50717
50869
  var PKG_NAME2 = "@profullstack/threatcrush";
50718
50870
  var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
50719
- var INSTALL_CONFIG_PATH = (0, import_node_path42.join)((0, import_node_os17.homedir)(), ".threatcrush", "install.json");
50871
+ var INSTALL_CONFIG_PATH = (0, import_node_path43.join)((0, import_node_os17.homedir)(), ".threatcrush", "install.json");
50720
50872
  function detectPackageManager() {
50721
50873
  try {
50722
50874
  const npmGlobal = (0, import_node_child_process24.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
@@ -50742,7 +50894,7 @@ function detectPackageManager() {
50742
50894
  }
50743
50895
  function readInstallConfig() {
50744
50896
  try {
50745
- return JSON.parse((0, import_node_fs55.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
50897
+ return JSON.parse((0, import_node_fs56.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
50746
50898
  } catch {
50747
50899
  return {};
50748
50900
  }
@@ -51152,7 +51304,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
51152
51304
  program2.command("logs").description("Tail daemon logs").action(async () => {
51153
51305
  console.log(LOGO2);
51154
51306
  const logPath2 = PATHS.logFile;
51155
- if (!(0, import_node_fs55.existsSync)(logPath2)) {
51307
+ if (!(0, import_node_fs56.existsSync)(logPath2)) {
51156
51308
  console.log(source_default.yellow(` No log file found at ${logPath2}`));
51157
51309
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
51158
51310
  return;
@@ -51220,10 +51372,10 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
51220
51372
  program2.command("remove").description("Uninstall ThreatCrush and the installed bundle").alias("uninstall").action(async () => {
51221
51373
  console.log(LOGO2);
51222
51374
  const rl = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
51223
- const confirm = await new Promise((resolve7) => {
51375
+ const confirm = await new Promise((resolve8) => {
51224
51376
  rl.question(source_default.yellow(" Are you sure you want to uninstall ThreatCrush? (y/N): "), (answer) => {
51225
51377
  rl.close();
51226
- resolve7(answer.trim().toLowerCase());
51378
+ resolve8(answer.trim().toLowerCase());
51227
51379
  });
51228
51380
  });
51229
51381
  if (confirm !== "y" && confirm !== "yes") {
@@ -51325,19 +51477,19 @@ storeCmd.command("search <query>").description("Search for modules in the store"
51325
51477
  });
51326
51478
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
51327
51479
  console.log(LOGO2);
51328
- const configPath = (0, import_node_path42.join)((0, import_node_os17.homedir)(), ".threatcrush", "config.json");
51480
+ const configPath = (0, import_node_path43.join)((0, import_node_os17.homedir)(), ".threatcrush", "config.json");
51329
51481
  let email = "";
51330
51482
  try {
51331
- const config = JSON.parse((0, import_node_fs55.readFileSync)(configPath, "utf-8"));
51483
+ const config = JSON.parse((0, import_node_fs56.readFileSync)(configPath, "utf-8"));
51332
51484
  email = config.email || "";
51333
51485
  } catch {
51334
51486
  }
51335
51487
  if (!email) {
51336
51488
  const rl2 = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
51337
- email = await new Promise((resolve7) => {
51489
+ email = await new Promise((resolve8) => {
51338
51490
  rl2.question(source_default.green(" Enter your email: "), (answer) => {
51339
51491
  rl2.close();
51340
- resolve7(answer.trim());
51492
+ resolve8(answer.trim());
51341
51493
  });
51342
51494
  });
51343
51495
  if (!email || !email.includes("@")) {
@@ -51345,9 +51497,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
51345
51497
  return;
51346
51498
  }
51347
51499
  try {
51348
- const dir = (0, import_node_path42.join)((0, import_node_os17.homedir)(), ".threatcrush");
51349
- if (!(0, import_node_fs55.existsSync)(dir)) (0, import_node_fs55.mkdirSync)(dir, { recursive: true });
51350
- (0, import_node_fs55.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
51500
+ const dir = (0, import_node_path43.join)((0, import_node_os17.homedir)(), ".threatcrush");
51501
+ if (!(0, import_node_fs56.existsSync)(dir)) (0, import_node_fs56.mkdirSync)(dir, { recursive: true });
51502
+ (0, import_node_fs56.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
51351
51503
  console.log(source_default.dim(` Saved email to ${configPath}`));
51352
51504
  } catch {
51353
51505
  }
@@ -51391,10 +51543,10 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
51391
51543
  }
51392
51544
  console.log();
51393
51545
  const rl = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
51394
- const confirm = await new Promise((resolve7) => {
51546
+ const confirm = await new Promise((resolve8) => {
51395
51547
  rl.question(source_default.yellow(" Publish this module? (y/N): "), (answer) => {
51396
51548
  rl.close();
51397
- resolve7(answer.trim().toLowerCase());
51549
+ resolve8(answer.trim().toLowerCase());
51398
51550
  });
51399
51551
  });
51400
51552
  if (confirm !== "y" && confirm !== "yes") {