@profullstack/threatcrush 0.13.59 → 0.13.60

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,187 @@ 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 bySize = [...entries].sort((a, b) => jsonBytes(a[1]) - jsonBytes(b[1]));
43578
+ while (bySize.length > 0 && jsonBytes({ ...Object.fromEntries(bySize), _truncated: true }) > MAX_METADATA_BYTES) {
43579
+ bySize.pop();
43580
+ }
43581
+ out = Object.fromEntries(bySize);
43582
+ }
43583
+ return truncated ? { ...out, _truncated: true } : out;
43584
+ }
43585
+ function str2(value) {
43586
+ return typeof value === "string" && value ? value : void 0;
43587
+ }
43588
+ function detectionEvent(serverId, event) {
43589
+ const { rule_id, username, user, description, ...rest } = event.details ?? {};
43590
+ const title = event.module === "rule-engine" ? event.message.replace(/^\[DETECTION\]\s*/, "") : event.message;
43591
+ return {
43592
+ type: "detection",
43593
+ server_id: serverId,
43594
+ severity: event.severity,
43595
+ title: title.slice(0, MAX_TITLE_CHARS) || event.module,
43596
+ rule_id: str2(rule_id) ?? event.module,
43597
+ description: str2(description),
43598
+ source_ip: event.source_ip && (0, import_node_net7.isIP)(event.source_ip) ? event.source_ip : void 0,
43599
+ username: str2(username) ?? str2(user),
43600
+ raw_metadata: trimMetadata({ module: event.module, category: event.category, ...rest }),
43601
+ detected_at: event.timestamp.toISOString()
43602
+ };
43603
+ }
43604
+ function remediationEvent(serverId, event) {
43605
+ const d = event.details ?? {};
43606
+ if (d.action !== "block" && d.action !== "unblock") return null;
43607
+ if (d.origin === "cloud" || !event.source_ip) return null;
43608
+ const at = event.timestamp;
43609
+ const ttl = typeof d.ttl_seconds === "number" ? d.ttl_seconds : null;
43610
+ return {
43611
+ type: "remediation",
43612
+ server_id: serverId,
43613
+ event_id: (0, import_node_crypto7.randomUUID)(),
43614
+ action_type: d.action,
43615
+ target_value: event.source_ip,
43616
+ status: d.failed === true ? "failed" : "executed",
43617
+ rule_id: str2(d.rule_id),
43618
+ reason: str2(d.reason),
43619
+ error: str2(d.error),
43620
+ dry_run: d.dry_run === true,
43621
+ executed_at: at.toISOString(),
43622
+ expires_at: d.action === "block" && ttl !== null && d.failed !== true ? new Date(at.getTime() + ttl * 1e3).toISOString() : null
43623
+ };
43624
+ }
43625
+ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date()) {
43626
+ return results.map((r) => ({
43627
+ type: "hardening_finding",
43628
+ server_id: serverId,
43629
+ finding_key: r.key,
43630
+ status: r.status,
43631
+ severity: r.severity,
43632
+ title: r.title.slice(0, MAX_TITLE_CHARS),
43633
+ recommendation: r.recommendation,
43634
+ observed_at: observedAt.toISOString(),
43635
+ ...r.details ? { details: trimMetadata(r.details) } : {}
43636
+ }));
43637
+ }
43638
+
43639
+ // src/daemon/workers/runs-worker.ts
43515
43640
  var POLL_INTERVAL_MS = 3e4;
43516
43641
  var SCHEDULE_INTERVAL_MS = 12e4;
43642
+ var NOT_PUBLIC = [
43643
+ ...DEFAULT_PROTECTED,
43644
+ "0.0.0.0/8",
43645
+ "100.64.0.0/10",
43646
+ "192.0.0.0/24",
43647
+ "198.18.0.0/15",
43648
+ "224.0.0.0/3",
43649
+ "::/128",
43650
+ "::ffff:0:0/96",
43651
+ "64:ff9b::/96",
43652
+ "ff00::/8"
43653
+ ];
43654
+ function isPublicTarget(ip) {
43655
+ return (0, import_node_net8.isIP)(ip) !== 0 && !isProtected(ip, NOT_PUBLIC);
43656
+ }
43657
+ async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0, import_promises2.lookup)(h, { all: true })).map((a) => a.address)) {
43658
+ let url;
43659
+ try {
43660
+ url = new URL(rawUrl.startsWith("http") ? rawUrl : `https://${rawUrl}`);
43661
+ } catch {
43662
+ return `not a URL: ${rawUrl}`;
43663
+ }
43664
+ if (url.protocol !== "http:" && url.protocol !== "https:") return `not an http(s) URL: ${rawUrl}`;
43665
+ const host = url.hostname.replace(/^\[|\]$/g, "");
43666
+ let addresses;
43667
+ try {
43668
+ addresses = (0, import_node_net8.isIP)(host) ? [host] : await resolveHost(host);
43669
+ } catch (err) {
43670
+ return `cannot resolve ${host}: ${err.message}`;
43671
+ }
43672
+ if (addresses.length === 0) return `cannot resolve ${host}`;
43673
+ const inside = addresses.find((a) => !isPublicTarget(a));
43674
+ return inside ? `${host} resolves to ${inside}, which is not a public address; dashboard runs never reach inside this network` : null;
43675
+ }
43676
+ function scanTargetError(target, roots, real = import_node_fs34.realpathSync) {
43677
+ if (roots.length === 0) {
43678
+ return "dashboard scans of this machine are off; list the directories they may read in [cloud] run_scan_paths";
43679
+ }
43680
+ let path2;
43681
+ try {
43682
+ path2 = real((0, import_node_path25.resolve)(target));
43683
+ } catch {
43684
+ return `no such path: ${target}`;
43685
+ }
43686
+ for (const root of roots) {
43687
+ let base;
43688
+ try {
43689
+ base = real((0, import_node_path25.resolve)(root));
43690
+ } catch {
43691
+ continue;
43692
+ }
43693
+ if (path2 === base || path2.startsWith(base.endsWith(import_node_path25.sep) ? base : base + import_node_path25.sep)) return null;
43694
+ }
43695
+ return `${target} is outside [cloud] run_scan_paths`;
43696
+ }
43517
43697
  var RunsWorker = class {
43518
- constructor(bus2) {
43698
+ constructor(bus2, opts = { enabled: false, scanRoots: [] }) {
43519
43699
  this.bus = bus2;
43700
+ this.opts = opts;
43520
43701
  }
43521
43702
  bus;
43703
+ opts;
43522
43704
  pollTimer = null;
43523
43705
  scheduleTimer = null;
43524
43706
  running = false;
43525
43707
  orgIds = [];
43526
43708
  async start() {
43709
+ if (!this.opts.enabled) {
43710
+ this.opts.log?.("[runs] dashboard property runs off (set [cloud] runs = true to run them on this machine)");
43711
+ return;
43712
+ }
43527
43713
  if (!hasSession()) return;
43528
43714
  try {
43529
43715
  await this.refreshOrgs();
@@ -43545,7 +43731,7 @@ var RunsWorker = class {
43545
43731
  async scheduleTick() {
43546
43732
  if (!hasSession()) return;
43547
43733
  try {
43548
- if (this.orgIds.length === 0) await this.refreshOrgs();
43734
+ await this.refreshOrgs();
43549
43735
  for (const orgId of this.orgIds) {
43550
43736
  try {
43551
43737
  await cloudFetch(`/api/orgs/${orgId}/schedules/tick`, { method: "POST" });
@@ -43560,7 +43746,7 @@ var RunsWorker = class {
43560
43746
  if (!hasSession()) return;
43561
43747
  this.running = true;
43562
43748
  try {
43563
- if (this.orgIds.length === 0) await this.refreshOrgs();
43749
+ await this.refreshOrgs();
43564
43750
  for (const orgId of this.orgIds) {
43565
43751
  const claimed = await this.claimOne(orgId);
43566
43752
  if (!claimed) continue;
@@ -43572,11 +43758,10 @@ var RunsWorker = class {
43572
43758
  this.running = false;
43573
43759
  }
43574
43760
  }
43761
+ /** Only the org this server is linked to: never every org its user is in. */
43575
43762
  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);
43763
+ const link = currentLink();
43764
+ this.orgIds = link ? [link.orgId] : [];
43580
43765
  }
43581
43766
  async claimOne(orgId) {
43582
43767
  try {
@@ -43603,6 +43788,18 @@ var RunsWorker = class {
43603
43788
  error: "property target missing"
43604
43789
  };
43605
43790
  }
43791
+ const refused = run.type === "scan" ? scanTargetError(target, this.opts.scanRoots) : await pentestTargetError(target);
43792
+ if (refused) {
43793
+ this.opts.log?.(`[runs] refused ${run.type} ${target}: ${refused}`);
43794
+ return {
43795
+ type: run.type,
43796
+ target,
43797
+ findings: [],
43798
+ severity_summary: { critical: 0, high: 0, medium: 0, low: 0, info: 0 },
43799
+ summary: `refused: ${refused}`,
43800
+ error: refused
43801
+ };
43802
+ }
43606
43803
  this.bus.announceModule("runs-worker", "running", `${run.type} ${run.property?.name || target}`);
43607
43804
  try {
43608
43805
  if (run.type === "scan") return await runScan(target);
@@ -43646,118 +43843,17 @@ var RunsWorker = class {
43646
43843
  // src/daemon/workers/cloud-sync.ts
43647
43844
  init_cli_config();
43648
43845
 
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
43846
  // 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");
43847
+ var import_node_fs35 = require("fs");
43848
+ var import_promises3 = require("fs/promises");
43849
+ var import_node_path26 = require("path");
43754
43850
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
43755
43851
  var CloudSpool = class {
43756
43852
  constructor(path2, limits = DEFAULT_SPOOL_LIMITS) {
43757
43853
  this.path = path2;
43758
43854
  this.limits = limits;
43759
43855
  try {
43760
- (0, import_node_fs34.mkdirSync)((0, import_node_path25.dirname)(path2), { recursive: true });
43856
+ (0, import_node_fs35.mkdirSync)((0, import_node_path26.dirname)(path2), { recursive: true });
43761
43857
  } catch {
43762
43858
  }
43763
43859
  this.load();
@@ -43826,7 +43922,7 @@ var CloudSpool = class {
43826
43922
  load() {
43827
43923
  let raw;
43828
43924
  try {
43829
- raw = (0, import_node_fs34.readFileSync)(this.path, "utf-8");
43925
+ raw = (0, import_node_fs35.readFileSync)(this.path, "utf-8");
43830
43926
  } catch {
43831
43927
  return;
43832
43928
  }
@@ -43857,13 +43953,13 @@ var CloudSpool = class {
43857
43953
  const body = this.lines.length > 0 ? `${this.lines.join("\n")}
43858
43954
  ` : "";
43859
43955
  const tmp = `${this.path}.tmp`;
43860
- await (0, import_promises2.writeFile)(tmp, body, { mode: 384 });
43861
- await (0, import_promises2.rename)(tmp, this.path);
43956
+ await (0, import_promises3.writeFile)(tmp, body, { mode: 384 });
43957
+ await (0, import_promises3.rename)(tmp, this.path);
43862
43958
  } else if (this.pendingAppend.length > 0) {
43863
43959
  const chunk2 = `${this.pendingAppend.join("\n")}
43864
43960
  `;
43865
43961
  this.pendingAppend = [];
43866
- await (0, import_promises2.appendFile)(this.path, chunk2, { mode: 384 });
43962
+ await (0, import_promises3.appendFile)(this.path, chunk2, { mode: 384 });
43867
43963
  }
43868
43964
  }).catch(() => {
43869
43965
  this.needsRewrite = true;
@@ -44067,7 +44163,7 @@ var CloudSync = class {
44067
44163
  var import_node_crypto8 = require("crypto");
44068
44164
 
44069
44165
  // src/daemon/workers/abuse-evidence.ts
44070
- var import_node_net7 = require("net");
44166
+ var import_node_net9 = require("net");
44071
44167
  var NEVER_REPORT_RANGES = [
44072
44168
  ...DEFAULT_PROTECTED,
44073
44169
  "100.64.0.0/10",
@@ -44143,7 +44239,7 @@ function summarizeEvidence(events) {
44143
44239
  };
44144
44240
  }
44145
44241
  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" };
44242
+ if ((0, import_node_net9.isIP)(ip) === 0) return { reportable: false, reason: "not an IP address" };
44147
44243
  if (isProtected(ip, config.neverReport)) {
44148
44244
  return { reportable: false, reason: "address is in a never-report range (private/CGNAT/reserved/allowlisted)" };
44149
44245
  }
@@ -44293,32 +44389,32 @@ function resolveConfig(section) {
44293
44389
  }
44294
44390
 
44295
44391
  // src/core/abuse-report-log.ts
44296
- var import_node_fs35 = require("fs");
44297
- var import_node_path26 = require("path");
44392
+ var import_node_fs36 = require("fs");
44393
+ var import_node_path27 = require("path");
44298
44394
  init_paths();
44299
44395
  var ABUSE_DIRNAME = "abuse-reports";
44300
44396
  var LOG_FILE2 = "reports.jsonl";
44301
44397
  function resolveAbuseDir(dir) {
44302
44398
  if (dir) return dir;
44303
44399
  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);
44400
+ const system = (0, import_node_path27.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
44401
+ if ((0, import_node_fs36.existsSync)(system)) return system;
44402
+ return (0, import_node_path27.join)(PATHS.stateDir, ABUSE_DIRNAME);
44307
44403
  }
44308
44404
  function logPath(dir) {
44309
- return (0, import_node_path26.join)(resolveAbuseDir(dir), LOG_FILE2);
44405
+ return (0, import_node_path27.join)(resolveAbuseDir(dir), LOG_FILE2);
44310
44406
  }
44311
44407
  function appendReport(record, dir) {
44312
44408
  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)}
44409
+ (0, import_node_fs36.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
44410
+ (0, import_node_fs36.appendFileSync)(path2, `${JSON.stringify(record)}
44315
44411
  `, { mode: 420 });
44316
44412
  }
44317
44413
  function readReports(dir) {
44318
44414
  const path2 = logPath(dir);
44319
44415
  let raw;
44320
44416
  try {
44321
- raw = (0, import_node_fs35.readFileSync)(path2, "utf-8");
44417
+ raw = (0, import_node_fs36.readFileSync)(path2, "utf-8");
44322
44418
  } catch {
44323
44419
  return [];
44324
44420
  }
@@ -44494,20 +44590,27 @@ var AbuseReporter = class {
44494
44590
  };
44495
44591
 
44496
44592
  // src/daemon/workers/remediation-consumer.ts
44497
- var import_node_net9 = require("net");
44593
+ var import_node_net11 = require("net");
44498
44594
  init_cli_config();
44499
44595
 
44500
44596
  // src/daemon/workers/allowlist-sync.ts
44501
- var import_node_net8 = require("net");
44597
+ var import_node_net10 = require("net");
44502
44598
  init_cli_config();
44503
44599
  function isAddressOrCidr(value) {
44504
44600
  const [network, prefix, extra] = value.split("/");
44505
- const family = (0, import_node_net8.isIP)(network);
44601
+ const family = (0, import_node_net10.isIP)(network);
44506
44602
  if (family === 0 || extra !== void 0) return false;
44507
44603
  if (prefix === void 0) return true;
44508
44604
  if (!/^\d{1,3}$/.test(prefix)) return false;
44509
44605
  return Number(prefix) <= (family === 4 ? 32 : 128);
44510
44606
  }
44607
+ var CLOUD_MIN_PREFIX = { 4: 8, 6: 16 };
44608
+ function isCloudAllowEntry(value) {
44609
+ if (!isAddressOrCidr(value)) return false;
44610
+ const [network, prefix] = value.split("/");
44611
+ if (prefix === void 0) return true;
44612
+ return Number(prefix) >= CLOUD_MIN_PREFIX[(0, import_node_net10.isIP)(network)];
44613
+ }
44511
44614
  var AllowlistSync = class {
44512
44615
  constructor(manager, opts) {
44513
44616
  this.manager = manager;
@@ -44543,7 +44646,8 @@ var AllowlistSync = class {
44543
44646
  for (const entry of entries) {
44544
44647
  if (entry.type !== "ip" && entry.type !== "cidr") continue;
44545
44648
  const value = String(entry.value ?? "").trim();
44546
- if (isAddressOrCidr(value)) wanted.add(value);
44649
+ if (isCloudAllowEntry(value)) wanted.add(value);
44650
+ 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
44651
  }
44548
44652
  const added2 = [];
44549
44653
  const protectedNow = new Set(this.manager.getProtected());
@@ -44651,7 +44755,7 @@ var RemediationConsumer = class {
44651
44755
  try {
44652
44756
  switch (action.action_type) {
44653
44757
  case "block": {
44654
- if ((0, import_node_net9.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
44758
+ if ((0, import_node_net11.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
44655
44759
  let ttlSeconds = this.manager.status().max_ban_seconds;
44656
44760
  if (action.expires_at) {
44657
44761
  const until = Date.parse(action.expires_at);
@@ -44670,7 +44774,7 @@ var RemediationConsumer = class {
44670
44774
  return { status: "executed", dry_run: result.entry?.dry_run === true, executed_at };
44671
44775
  }
44672
44776
  case "unblock": {
44673
- if ((0, import_node_net9.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
44777
+ if ((0, import_node_net11.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
44674
44778
  const wasBanned = this.manager.getBlocklist().some((b) => b.ip === target);
44675
44779
  const result = await this.manager.unban(target, {
44676
44780
  forget: true,
@@ -44683,13 +44787,16 @@ var RemediationConsumer = class {
44683
44787
  return { status: "executed", dry_run: this.manager.status().dry_run, executed_at };
44684
44788
  }
44685
44789
  case "allowlist_add":
44686
- if (!isAddressOrCidr(target)) return failed(`not an IP address or CIDR: ${target}`);
44790
+ if (!isCloudAllowEntry(target)) return failed(`not an IP address or CIDR the dashboard may protect: ${target}`);
44687
44791
  this.manager.addToAllowlist(target);
44688
44792
  return { status: "executed", executed_at };
44689
44793
  case "allowlist_remove":
44690
44794
  if (DEFAULT_PROTECTED.includes(target)) {
44691
44795
  return failed(`${target} is a built-in protected range and cannot be removed`);
44692
44796
  }
44797
+ if (this.manager.isPinned(target)) {
44798
+ return failed(`${target} is protected by this server's own configuration and cannot be removed from the dashboard`);
44799
+ }
44693
44800
  this.manager.removeFromAllowlist(target);
44694
44801
  return { status: "executed", executed_at };
44695
44802
  case "restart": {
@@ -44722,8 +44829,8 @@ var RemediationConsumer = class {
44722
44829
 
44723
44830
  // src/daemon/workers/auto-update.ts
44724
44831
  var import_node_child_process10 = require("child_process");
44725
- var import_node_fs36 = require("fs");
44726
- var import_node_path27 = require("path");
44832
+ var import_node_fs37 = require("fs");
44833
+ var import_node_path28 = require("path");
44727
44834
  init_backoff();
44728
44835
  var PKG_NAME = "@profullstack/threatcrush";
44729
44836
  var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
@@ -44767,12 +44874,12 @@ function pickUpdate(doc, current, opts) {
44767
44874
  return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
44768
44875
  }
44769
44876
  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`;
44877
+ const expected = `${import_node_path28.sep}lib${import_node_path28.sep}node_modules${import_node_path28.sep}@profullstack${import_node_path28.sep}threatcrush`;
44771
44878
  if (!opts.pkgRoot.endsWith(expected)) {
44772
44879
  return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
44773
44880
  }
44774
- const nodeBin = (0, import_node_path27.dirname)(opts.execPath);
44775
- const npm = (0, import_node_path27.join)(nodeBin, "npm");
44881
+ const nodeBin = (0, import_node_path28.dirname)(opts.execPath);
44882
+ const npm = (0, import_node_path28.join)(nodeBin, "npm");
44776
44883
  if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
44777
44884
  if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
44778
44885
  const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
@@ -44804,10 +44911,10 @@ function installPlan(opts) {
44804
44911
  }
44805
44912
  function ownerOf(path2, passwd = "/etc/passwd") {
44806
44913
  try {
44807
- const st = (0, import_node_fs36.statSync)(path2);
44914
+ const st = (0, import_node_fs37.statSync)(path2);
44808
44915
  let home = st.uid === 0 ? "/root" : "";
44809
44916
  try {
44810
- for (const line2 of (0, import_node_fs36.readFileSync)(passwd, "utf8").split("\n")) {
44917
+ for (const line2 of (0, import_node_fs37.readFileSync)(passwd, "utf8").split("\n")) {
44811
44918
  const f = line2.split(":");
44812
44919
  if (Number(f[2]) === st.uid && f[5]) home = f[5];
44813
44920
  }
@@ -44829,7 +44936,7 @@ function updateSettings(section, env3 = process.env) {
44829
44936
  };
44830
44937
  }
44831
44938
  function defaultRun(argv, env3) {
44832
- return new Promise((resolve7) => {
44939
+ return new Promise((resolve8) => {
44833
44940
  const child = (0, import_node_child_process10.spawn)(argv[0], argv.slice(1), {
44834
44941
  env: { ...process.env, ...env3 },
44835
44942
  stdio: ["ignore", "pipe", "pipe"]
@@ -44840,8 +44947,8 @@ function defaultRun(argv, env3) {
44840
44947
  };
44841
44948
  child.stdout?.on("data", keep);
44842
44949
  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 }));
44950
+ child.on("error", (err) => resolve8({ code: -1, output: err.message }));
44951
+ child.on("close", (code) => resolve8({ code: code ?? -1, output }));
44845
44952
  });
44846
44953
  }
44847
44954
  var AutoUpdate = class {
@@ -44917,7 +45024,7 @@ var AutoUpdate = class {
44917
45024
  uid: process.getuid?.() ?? -1,
44918
45025
  owner: ownerOf(this.opts.pkgRoot),
44919
45026
  underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
44920
- npmExists: import_node_fs36.existsSync
45027
+ npmExists: import_node_fs37.existsSync
44921
45028
  });
44922
45029
  if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
44923
45030
  this.recordAttempt(target);
@@ -44953,7 +45060,7 @@ var AutoUpdate = class {
44953
45060
  }
44954
45061
  lastAttempt() {
44955
45062
  try {
44956
- const v = JSON.parse((0, import_node_fs36.readFileSync)(this.opts.statePath, "utf8"));
45063
+ const v = JSON.parse((0, import_node_fs37.readFileSync)(this.opts.statePath, "utf8"));
44957
45064
  return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
44958
45065
  } catch {
44959
45066
  return null;
@@ -44961,7 +45068,7 @@ var AutoUpdate = class {
44961
45068
  }
44962
45069
  recordAttempt(version) {
44963
45070
  try {
44964
- (0, import_node_fs36.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
45071
+ (0, import_node_fs37.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
44965
45072
  } catch (err) {
44966
45073
  this.opts.log(`[update] could not record attempt: ${err.message}`);
44967
45074
  }
@@ -44970,9 +45077,9 @@ var AutoUpdate = class {
44970
45077
 
44971
45078
  // src/daemon/workers/threat-feeds.ts
44972
45079
  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");
45080
+ var import_node_fs38 = require("fs");
45081
+ var import_node_path29 = require("path");
45082
+ var import_node_net12 = require("net");
44976
45083
  init_backoff();
44977
45084
  var EGRESS_TABLE = "threatcrush_egress";
44978
45085
  var DEFAULT_REFRESH_MS = 36e5;
@@ -44991,8 +45098,8 @@ function threatFeedSettings(section) {
44991
45098
  };
44992
45099
  }
44993
45100
  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);
45101
+ const v4 = ips.filter((ip) => (0, import_node_net12.isIP)(ip) === 4);
45102
+ const v6 = ips.filter((ip) => (0, import_node_net12.isIP)(ip) === 6);
44996
45103
  const set = (name, type, items) => ` set ${name} { type ${type};${items.length ? ` elements = { ${items.join(", ")} }` : ""} }`;
44997
45104
  const chain = (name, hook) => [
44998
45105
  ` chain ${name} {`,
@@ -45017,7 +45124,7 @@ function splitAddr(addr) {
45017
45124
  const m = /^\[?(.+?)\]?:(\d+|\*)$/.exec(addr);
45018
45125
  if (!m) return null;
45019
45126
  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;
45127
+ return (0, import_node_net12.isIP)(ip) ? { ip, port: m[2] === "*" ? 0 : Number(m[2]) } : null;
45021
45128
  }
45022
45129
  function parseSs(text) {
45023
45130
  const out = [];
@@ -45143,14 +45250,14 @@ var ThreatFeeds = class {
45143
45250
  */
45144
45251
  writeResolverFiles(set) {
45145
45252
  const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
45146
- const dir = this.opts.resolverDir ?? (0, import_node_path28.dirname)(this.opts.cachePath);
45253
+ const dir = this.opts.resolverDir ?? (0, import_node_path29.dirname)(this.opts.cachePath);
45147
45254
  const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
45148
45255
  const write = (name, content) => {
45149
- const path2 = (0, import_node_path28.join)(dir, name);
45256
+ const path2 = (0, import_node_path29.join)(dir, name);
45150
45257
  if (this.resolverWritten.get(name) === content) return false;
45151
45258
  try {
45152
- (0, import_node_fs37.writeFileSync)(`${path2}.tmp`, content);
45153
- (0, import_node_fs37.renameSync)(`${path2}.tmp`, path2);
45259
+ (0, import_node_fs38.writeFileSync)(`${path2}.tmp`, content);
45260
+ (0, import_node_fs38.renameSync)(`${path2}.tmp`, path2);
45154
45261
  this.resolverWritten.set(name, content);
45155
45262
  return true;
45156
45263
  } catch (err) {
@@ -45161,11 +45268,11 @@ var ThreatFeeds = class {
45161
45268
  const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
45162
45269
  const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
45163
45270
  const via = [];
45164
- if ((0, import_node_fs37.existsSync)(hooks.dnsmasq)) {
45271
+ if ((0, import_node_fs38.existsSync)(hooks.dnsmasq)) {
45165
45272
  via.push("dnsmasq");
45166
45273
  if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
45167
45274
  }
45168
- if ((0, import_node_fs37.existsSync)(hooks.unbound)) {
45275
+ if ((0, import_node_fs38.existsSync)(hooks.unbound)) {
45169
45276
  via.push("unbound");
45170
45277
  if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
45171
45278
  this.run("systemctl", ["reload", "unbound.service"]);
@@ -45226,8 +45333,8 @@ var ThreatFeeds = class {
45226
45333
  };
45227
45334
 
45228
45335
  // src/daemon/workers/privilege-watch.ts
45229
- var import_node_fs38 = require("fs");
45230
- var import_node_path29 = require("path");
45336
+ var import_node_fs39 = require("fs");
45337
+ var import_node_path30 = require("path");
45231
45338
  var import_node_child_process12 = require("child_process");
45232
45339
 
45233
45340
  // src/core/privileges/index.ts
@@ -45418,31 +45525,31 @@ function countryName(code) {
45418
45525
  var fsIO = {
45419
45526
  readFile: (p) => {
45420
45527
  try {
45421
- return (0, import_node_fs38.readFileSync)(p, "utf-8");
45528
+ return (0, import_node_fs39.readFileSync)(p, "utf-8");
45422
45529
  } catch {
45423
45530
  return null;
45424
45531
  }
45425
45532
  },
45426
45533
  readDir: (p) => {
45427
45534
  try {
45428
- return (0, import_node_fs38.readdirSync)(p);
45535
+ return (0, import_node_fs39.readdirSync)(p);
45429
45536
  } catch {
45430
45537
  return null;
45431
45538
  }
45432
45539
  },
45433
- exists: (p) => (0, import_node_fs38.existsSync)(p)
45540
+ exists: (p) => (0, import_node_fs39.existsSync)(p)
45434
45541
  };
45435
45542
  function readJson(path2) {
45436
45543
  try {
45437
- return JSON.parse((0, import_node_fs38.readFileSync)(path2, "utf-8"));
45544
+ return JSON.parse((0, import_node_fs39.readFileSync)(path2, "utf-8"));
45438
45545
  } catch {
45439
45546
  return null;
45440
45547
  }
45441
45548
  }
45442
45549
  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);
45550
+ (0, import_node_fs39.mkdirSync)((0, import_node_path30.dirname)(path2), { recursive: true });
45551
+ (0, import_node_fs39.writeFileSync)(`${path2}.tmp`, JSON.stringify(value));
45552
+ (0, import_node_fs39.renameSync)(`${path2}.tmp`, path2);
45446
45553
  }
45447
45554
  function defaultRun3(cmd, args) {
45448
45555
  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 +45705,7 @@ var PrivilegeWatch = class {
45598
45705
  * raised a "new country" alert on its first run; on dev2 it did, at once.
45599
45706
  */
45600
45707
  async backfillLogins() {
45601
- if ((0, import_node_fs38.existsSync)(this.opts.loginsPath)) return;
45708
+ if ((0, import_node_fs39.existsSync)(this.opts.loginsPath)) return;
45602
45709
  const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
45603
45710
  const byUser = parseAcceptedLogins(out ?? "");
45604
45711
  const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
@@ -45611,7 +45718,7 @@ var PrivilegeWatch = class {
45611
45718
  return;
45612
45719
  }
45613
45720
  }
45614
- if ((0, import_node_fs38.existsSync)(this.opts.loginsPath)) return;
45721
+ if ((0, import_node_fs39.existsSync)(this.opts.loginsPath)) return;
45615
45722
  const at = this.now().toISOString();
45616
45723
  const history = {};
45617
45724
  for (const [user, userIps] of byUser) {
@@ -45823,8 +45930,8 @@ var RuleEngine = class {
45823
45930
  };
45824
45931
 
45825
45932
  // src/daemon/rules/loader.ts
45826
- var import_node_fs39 = require("fs");
45827
- var import_node_path30 = require("path");
45933
+ var import_node_fs40 = require("fs");
45934
+ var import_node_path31 = require("path");
45828
45935
 
45829
45936
  // src/daemon/rules/default-rules.ts
45830
45937
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
@@ -46294,11 +46401,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
46294
46401
  function loadAllRules(customDir) {
46295
46402
  const rules = [...DEFAULT_RULES];
46296
46403
  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"));
46404
+ if ((0, import_node_fs40.existsSync)(dir)) {
46405
+ const files = (0, import_node_fs40.readdirSync)(dir).filter((f) => f.endsWith(".json"));
46299
46406
  for (const file of files) {
46300
46407
  try {
46301
- const raw = (0, import_node_fs39.readFileSync)((0, import_node_path30.join)(dir, file), "utf-8");
46408
+ const raw = (0, import_node_fs40.readFileSync)((0, import_node_path31.join)(dir, file), "utf-8");
46302
46409
  const parsed = JSON.parse(raw);
46303
46410
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
46304
46411
  for (const rule of customRules) {
@@ -46330,23 +46437,23 @@ function loadAllRules(customDir) {
46330
46437
 
46331
46438
  // src/daemon/firewall/adapters.ts
46332
46439
  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");
46440
+ var import_node_fs41 = require("fs");
46441
+ var import_node_path32 = require("path");
46442
+ var import_node_net13 = require("net");
46336
46443
  function assertValidFirewallIp(ip) {
46337
- if ((0, import_node_net11.isIP)(ip) !== 4) {
46444
+ if ((0, import_node_net13.isIP)(ip) !== 4) {
46338
46445
  throw new Error(`Invalid IPv4 address: ${ip}`);
46339
46446
  }
46340
46447
  }
46341
46448
  function assertBannableIp(ip) {
46342
- if ((0, import_node_net11.isIP)(ip) === 0) {
46449
+ if ((0, import_node_net13.isIP)(ip) === 0) {
46343
46450
  throw new Error(`Invalid IP address: ${ip}`);
46344
46451
  }
46345
46452
  }
46346
46453
  function writeIfAbsent(path2, contents) {
46347
- (0, import_node_fs40.mkdirSync)((0, import_node_path31.dirname)(path2), { recursive: true });
46454
+ (0, import_node_fs41.mkdirSync)((0, import_node_path32.dirname)(path2), { recursive: true });
46348
46455
  try {
46349
- (0, import_node_fs40.writeFileSync)(path2, contents, { flag: "wx" });
46456
+ (0, import_node_fs41.writeFileSync)(path2, contents, { flag: "wx" });
46350
46457
  } catch (err) {
46351
46458
  if (err.code !== "EEXIST") throw err;
46352
46459
  }
@@ -46445,7 +46552,7 @@ var Fail2banAdapter = class {
46445
46552
  const status = this.client(["status", this.jail]);
46446
46553
  const line2 = status.split("\n").find((l) => /Banned IP list:/i.test(l));
46447
46554
  if (!line2) return [];
46448
- return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net11.isIP)(s) !== 0);
46555
+ return line2.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net13.isIP)(s) !== 0);
46449
46556
  } catch {
46450
46557
  return [];
46451
46558
  }
@@ -46455,10 +46562,10 @@ var Fail2banAdapter = class {
46455
46562
  function parseBannedList(output) {
46456
46563
  const found = [];
46457
46564
  for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
46458
- if ((0, import_node_net11.isIP)(match[1]) !== 0) found.push(match[1]);
46565
+ if ((0, import_node_net13.isIP)(match[1]) !== 0) found.push(match[1]);
46459
46566
  }
46460
46567
  if (found.length > 0) return found;
46461
- return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net11.isIP)(s) !== 0);
46568
+ return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net13.isIP)(s) !== 0);
46462
46569
  }
46463
46570
  var NftablesAdapter = class {
46464
46571
  name = "nftables";
@@ -46605,9 +46712,9 @@ function detectFirewallAdapter(backend = "auto") {
46605
46712
  }
46606
46713
 
46607
46714
  // src/daemon/firewall/remediation.ts
46608
- var import_node_fs41 = require("fs");
46715
+ var import_node_fs42 = require("fs");
46609
46716
  var import_node_child_process14 = require("child_process");
46610
- var import_node_net12 = require("net");
46717
+ var import_node_net14 = require("net");
46611
46718
  init_paths();
46612
46719
  init_backoff();
46613
46720
 
@@ -46676,19 +46783,19 @@ var defaultDiscovery = {
46676
46783
  const snapshot = takeSnapshot({
46677
46784
  readFile: (p) => {
46678
46785
  try {
46679
- return (0, import_node_fs41.readFileSync)(p, "utf-8");
46786
+ return (0, import_node_fs42.readFileSync)(p, "utf-8");
46680
46787
  } catch {
46681
46788
  return null;
46682
46789
  }
46683
46790
  },
46684
46791
  readDir: (p) => {
46685
46792
  try {
46686
- return (0, import_node_fs41.readdirSync)(p);
46793
+ return (0, import_node_fs42.readdirSync)(p);
46687
46794
  } catch {
46688
46795
  return null;
46689
46796
  }
46690
46797
  },
46691
- exists: (p) => (0, import_node_fs41.existsSync)(p)
46798
+ exists: (p) => (0, import_node_fs42.existsSync)(p)
46692
46799
  });
46693
46800
  const out = /* @__PURE__ */ new Set();
46694
46801
  for (const keys of Object.values(snapshot.keys)) {
@@ -46696,12 +46803,12 @@ var defaultDiscovery = {
46696
46803
  }
46697
46804
  return out;
46698
46805
  },
46699
- keyLoginJournal: (sinceSeconds) => new Promise((resolve7) => {
46806
+ keyLoginJournal: (sinceSeconds) => new Promise((resolve8) => {
46700
46807
  (0, import_node_child_process14.execFile)(
46701
46808
  "journalctl",
46702
46809
  ["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
46703
46810
  { maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
46704
- (_err, stdout) => resolve7(stdout ?? "")
46811
+ (_err, stdout) => resolve8(stdout ?? "")
46705
46812
  );
46706
46813
  })
46707
46814
  };
@@ -46736,6 +46843,7 @@ var RemediationManager = class {
46736
46843
  this.config.allowlist = [...this.config.allowlist];
46737
46844
  this.protectedList = [...DEFAULT_PROTECTED, ...SHARED_INFRASTRUCTURE, ...this.config.allowlist];
46738
46845
  for (const gateway of defaultGateways()) this.protectedList.push(gateway);
46846
+ this.pinned = new Set(this.protectedList);
46739
46847
  if (this.adapter.enforces === false) this.config.dry_run = true;
46740
46848
  this.loadState();
46741
46849
  this.refreshSshProtection();
@@ -46751,6 +46859,12 @@ var RemediationManager = class {
46751
46859
  blocklist = [];
46752
46860
  strikes = {};
46753
46861
  protectedList = [];
46862
+ /**
46863
+ * What was protected at start: built-ins, shared infrastructure, the
46864
+ * operator's `[remediation] allowlist`, default gateways. The dashboard may
46865
+ * add to the protected set but never take these out of it.
46866
+ */
46867
+ pinned = /* @__PURE__ */ new Set();
46754
46868
  /** Operator address → last time seen (ms), persisted. */
46755
46869
  operators = {};
46756
46870
  expiryTimer = null;
@@ -46823,7 +46937,7 @@ var RemediationManager = class {
46823
46937
  if (remediation?.action !== "block") return;
46824
46938
  }
46825
46939
  const ip = event.source_ip;
46826
- if (!ip || (0, import_node_net12.isIP)(ip) === 0) return;
46940
+ if (!ip || (0, import_node_net14.isIP)(ip) === 0) return;
46827
46941
  if (this.isAllowlisted(ip)) return;
46828
46942
  if (this.blocklist.some((b) => b.ip === ip)) return;
46829
46943
  if (this.config.spare_verified_crawlers) {
@@ -46842,7 +46956,7 @@ var RemediationManager = class {
46842
46956
  * 4th offence and so on, clamped to `max_ban_seconds`.
46843
46957
  */
46844
46958
  async ban(ip, reason, opts = {}) {
46845
- if ((0, import_node_net12.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
46959
+ if ((0, import_node_net14.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
46846
46960
  if (this.isAllowlisted(ip)) {
46847
46961
  return { ok: false, error: `${ip} is protected and can never be blocked` };
46848
46962
  }
@@ -46999,6 +47113,10 @@ var RemediationManager = class {
46999
47113
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
47000
47114
  if (!this.config.allowlist.includes(ip)) this.config.allowlist.push(ip);
47001
47115
  }
47116
+ /** Protected since start (built-in, shared infrastructure, operator config, gateway): not removable from the cloud. */
47117
+ isPinned(ip) {
47118
+ return this.pinned.has(ip);
47119
+ }
47002
47120
  removeFromAllowlist(ip) {
47003
47121
  if (DEFAULT_PROTECTED.includes(ip)) return;
47004
47122
  this.protectedList = this.protectedList.filter((a) => a !== ip);
@@ -47105,7 +47223,7 @@ var RemediationManager = class {
47105
47223
  if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
47106
47224
  const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
47107
47225
  for (const [ip, at] of Object.entries(saved)) {
47108
- if (typeof at !== "number" || at < cutoff || !(0, import_node_net12.isIP)(ip)) continue;
47226
+ if (typeof at !== "number" || at < cutoff || !(0, import_node_net14.isIP)(ip)) continue;
47109
47227
  this.operators[ip] = at;
47110
47228
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
47111
47229
  }
@@ -47129,7 +47247,7 @@ var RemediationManager = class {
47129
47247
  }
47130
47248
  logLine(line2) {
47131
47249
  try {
47132
- (0, import_node_fs41.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47250
+ (0, import_node_fs42.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47133
47251
  `);
47134
47252
  } catch {
47135
47253
  }
@@ -47172,19 +47290,19 @@ function remediationSettings(section) {
47172
47290
  init_backoff();
47173
47291
 
47174
47292
  // src/daemon/watchdog-service.ts
47175
- var import_node_fs42 = require("fs");
47176
- var import_node_path32 = require("path");
47293
+ var import_node_fs43 = require("fs");
47294
+ var import_node_path33 = require("path");
47177
47295
  function defaultShareGid() {
47178
47296
  const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
47179
47297
  if (!isRoot4) return void 0;
47180
47298
  try {
47181
- return (0, import_node_fs42.statSync)("/var/log/auth.log").gid;
47299
+ return (0, import_node_fs43.statSync)("/var/log/auth.log").gid;
47182
47300
  } catch {
47183
47301
  return void 0;
47184
47302
  }
47185
47303
  }
47186
47304
  function startWatchdog(opts) {
47187
- const dir = opts.config?.dir ?? (0, import_node_path32.join)(opts.stateDir, WATCHDOG_DIRNAME);
47305
+ const dir = opts.config?.dir ?? (0, import_node_path33.join)(opts.stateDir, WATCHDOG_DIRNAME);
47188
47306
  const base = { dir, logged: 0, answered: 0, errored: 0 };
47189
47307
  if (opts.config?.enabled === false) {
47190
47308
  opts.log("[watchdog] off ([watchdog] enabled = false)");
@@ -47299,7 +47417,7 @@ function versionOfNode(path2) {
47299
47417
  // src/daemon/index.ts
47300
47418
  function readVersion2() {
47301
47419
  try {
47302
- const pkg = JSON.parse((0, import_node_fs43.readFileSync)((0, import_node_path33.join)(__dirname, "..", "package.json"), "utf-8"));
47420
+ const pkg = JSON.parse((0, import_node_fs44.readFileSync)((0, import_node_path34.join)(__dirname, "..", "package.json"), "utf-8"));
47303
47421
  return pkg.version || "0.0.0";
47304
47422
  } catch {
47305
47423
  return "0.0.0";
@@ -47308,7 +47426,7 @@ function readVersion2() {
47308
47426
  async function runHardeningChecks() {
47309
47427
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
47310
47428
  process.execPath,
47311
- [(0, import_node_path33.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
47429
+ [(0, import_node_path34.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
47312
47430
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
47313
47431
  );
47314
47432
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -47322,7 +47440,7 @@ async function runHardeningChecks() {
47322
47440
  async function runPatchCheck() {
47323
47441
  const { stdout } = await (0, import_node_util4.promisify)(import_node_child_process16.execFile)(
47324
47442
  process.execPath,
47325
- [(0, import_node_path33.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
47443
+ [(0, import_node_path34.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
47326
47444
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
47327
47445
  );
47328
47446
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -47330,7 +47448,7 @@ async function runPatchCheck() {
47330
47448
  }
47331
47449
  function logLine(line2) {
47332
47450
  try {
47333
- (0, import_node_fs43.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47451
+ (0, import_node_fs44.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line2}
47334
47452
  `);
47335
47453
  } catch {
47336
47454
  }
@@ -47372,7 +47490,7 @@ async function runDaemon() {
47372
47490
  } catch (err) {
47373
47491
  logLine(`[daemon] state db unavailable: ${err.message}`);
47374
47492
  }
47375
- const config = loadConfig((0, import_node_fs43.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
47493
+ const config = loadConfig((0, import_node_fs44.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
47376
47494
  configureAttackDetection(config.detection);
47377
47495
  const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
47378
47496
  const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
@@ -47436,7 +47554,7 @@ async function runDaemon() {
47436
47554
  const threatFeeds = new ThreatFeeds({
47437
47555
  settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
47438
47556
  enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
47439
- cachePath: (0, import_node_path33.join)(PATHS.stateDir, "threat-feeds.json"),
47557
+ cachePath: (0, import_node_path34.join)(PATHS.stateDir, "threat-feeds.json"),
47440
47558
  bus,
47441
47559
  log: logLine
47442
47560
  });
@@ -47444,14 +47562,18 @@ async function runDaemon() {
47444
47562
  const privilegeWatch = new PrivilegeWatch({
47445
47563
  settings: privilegeSettings(config.privileged),
47446
47564
  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"),
47565
+ snapshotPath: (0, import_node_path34.join)(PATHS.stateDir, "privileges.json"),
47566
+ loginsPath: (0, import_node_path34.join)(PATHS.stateDir, "login-countries.json"),
47567
+ cursorPath: (0, import_node_path34.join)(PATHS.stateDir, "sudo-cursor.json"),
47450
47568
  log: logLine
47451
47569
  });
47452
47570
  privilegeWatch.start();
47453
47571
  new AlertDispatcher(bus, config);
47454
- const runsWorker = new RunsWorker(bus);
47572
+ const runsWorker = new RunsWorker(bus, {
47573
+ enabled: config.cloud?.enabled !== false && config.cloud?.runs === true,
47574
+ scanRoots: Array.isArray(config.cloud?.run_scan_paths) ? config.cloud.run_scan_paths.filter((p) => typeof p === "string") : [],
47575
+ log: logLine
47576
+ });
47455
47577
  try {
47456
47578
  await runsWorker.start();
47457
47579
  } catch (err) {
@@ -47470,7 +47592,7 @@ async function runDaemon() {
47470
47592
  version,
47471
47593
  hostname: (0, import_node_os13.hostname)(),
47472
47594
  minSeverity,
47473
- spoolPath: (0, import_node_path33.join)(PATHS.stateDir, "cloud-spool.jsonl"),
47595
+ spoolPath: (0, import_node_path34.join)(PATHS.stateDir, "cloud-spool.jsonl"),
47474
47596
  log: logLine,
47475
47597
  ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
47476
47598
  runHardening: runHardeningChecks
@@ -47494,8 +47616,8 @@ async function runDaemon() {
47494
47616
  const autoUpdate = autoUpdateRef = new AutoUpdate({
47495
47617
  version,
47496
47618
  settings: updateSettings(config.update),
47497
- pkgRoot: (0, import_node_path33.join)(__dirname, ".."),
47498
- statePath: (0, import_node_path33.join)(PATHS.stateDir, "auto-update.json"),
47619
+ pkgRoot: (0, import_node_path34.join)(__dirname, ".."),
47620
+ statePath: (0, import_node_path34.join)(PATHS.stateDir, "auto-update.json"),
47499
47621
  bus,
47500
47622
  log: logLine,
47501
47623
  restartDaemon
@@ -47585,7 +47707,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
47585
47707
  function isRoot2() {
47586
47708
  return typeof process.getuid === "function" && process.getuid() === 0;
47587
47709
  }
47588
- var DAEMON_ENTRY = (0, import_node_path34.join)(__dirname, "daemon.js");
47710
+ var DAEMON_ENTRY = (0, import_node_path35.join)(__dirname, "daemon.js");
47589
47711
  async function daemonForeground() {
47590
47712
  await runDaemon();
47591
47713
  }
@@ -47606,7 +47728,7 @@ async function daemonStart() {
47606
47728
  return;
47607
47729
  }
47608
47730
  ensureRuntimeDirs();
47609
- if (!(0, import_node_fs44.existsSync)(DAEMON_ENTRY)) {
47731
+ if (!(0, import_node_fs45.existsSync)(DAEMON_ENTRY)) {
47610
47732
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
47611
47733
  console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
47612
47734
  return;
@@ -47614,8 +47736,8 @@ async function daemonStart() {
47614
47736
  let out;
47615
47737
  let err;
47616
47738
  try {
47617
- out = (0, import_node_fs45.openSync)(PATHS.logFile, "a");
47618
- err = (0, import_node_fs45.openSync)(PATHS.logFile, "a");
47739
+ out = (0, import_node_fs46.openSync)(PATHS.logFile, "a");
47740
+ err = (0, import_node_fs46.openSync)(PATHS.logFile, "a");
47619
47741
  } catch (e) {
47620
47742
  const code = e.code;
47621
47743
  console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
@@ -47703,12 +47825,12 @@ async function waitForExit(pid, timeoutMs) {
47703
47825
  }
47704
47826
  async function releaseStaleSocket() {
47705
47827
  const deadline = Date.now() + 2e3;
47706
- while ((0, import_node_fs44.existsSync)(PATHS.socket) && Date.now() < deadline) {
47828
+ while ((0, import_node_fs45.existsSync)(PATHS.socket) && Date.now() < deadline) {
47707
47829
  await new Promise((r) => setTimeout(r, 50));
47708
47830
  }
47709
- if ((0, import_node_fs44.existsSync)(PATHS.socket)) {
47831
+ if ((0, import_node_fs45.existsSync)(PATHS.socket)) {
47710
47832
  try {
47711
- (0, import_node_fs44.unlinkSync)(PATHS.socket);
47833
+ (0, import_node_fs45.unlinkSync)(PATHS.socket);
47712
47834
  } catch {
47713
47835
  }
47714
47836
  }
@@ -47716,26 +47838,26 @@ async function releaseStaleSocket() {
47716
47838
 
47717
47839
  // src/commands/service.ts
47718
47840
  var import_node_child_process18 = require("child_process");
47719
- var import_node_fs46 = require("fs");
47720
- var import_node_path35 = require("path");
47841
+ var import_node_fs47 = require("fs");
47842
+ var import_node_path36 = require("path");
47721
47843
  var import_node_os14 = require("os");
47722
47844
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
47723
47845
  var DAEMON_UNIT_NAME = "threatcrushd.service";
47724
47846
  function resolveTemplate() {
47725
- const templatePath = (0, import_node_path35.join)(__dirname, "systemd", "threatcrushd.service");
47726
- if (!(0, import_node_fs46.existsSync)(templatePath)) {
47847
+ const templatePath = (0, import_node_path36.join)(__dirname, "systemd", "threatcrushd.service");
47848
+ if (!(0, import_node_fs47.existsSync)(templatePath)) {
47727
47849
  throw new Error(`systemd unit template not found at ${templatePath}`);
47728
47850
  }
47729
- return (0, import_node_fs46.readFileSync)(templatePath, "utf-8");
47851
+ return (0, import_node_fs47.readFileSync)(templatePath, "utf-8");
47730
47852
  }
47731
47853
  function stableBinPath(binPath) {
47732
47854
  const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
47733
47855
  if (stable === binPath) return binPath;
47734
- return (0, import_node_fs46.existsSync)(stable) ? stable : binPath;
47856
+ return (0, import_node_fs47.existsSync)(stable) ? stable : binPath;
47735
47857
  }
47736
47858
  function resolveBinPath() {
47737
47859
  const arg = process.argv[1];
47738
- if (arg && (0, import_node_fs46.existsSync)(arg)) return stableBinPath(arg);
47860
+ if (arg && (0, import_node_fs47.existsSync)(arg)) return stableBinPath(arg);
47739
47861
  try {
47740
47862
  return (0, import_node_child_process18.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
47741
47863
  } catch {
@@ -47745,11 +47867,11 @@ function resolveBinPath() {
47745
47867
  function stableNodePath(execPath) {
47746
47868
  const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
47747
47869
  if (stable === execPath) return execPath;
47748
- return (0, import_node_fs46.existsSync)(stable) ? stable : execPath;
47870
+ return (0, import_node_fs47.existsSync)(stable) ? stable : execPath;
47749
47871
  }
47750
47872
  function looksLikeNodeScript(path2) {
47751
47873
  try {
47752
- const head = (0, import_node_fs46.readFileSync)(path2, "utf-8").slice(0, 120);
47874
+ const head = (0, import_node_fs47.readFileSync)(path2, "utf-8").slice(0, 120);
47753
47875
  return /^#!.*\bnode\b/.test(head);
47754
47876
  } catch {
47755
47877
  return false;
@@ -47789,7 +47911,7 @@ function callerHome() {
47789
47911
  try {
47790
47912
  const line2 = (0, import_node_child_process18.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
47791
47913
  const home = line2.split(":")[5];
47792
- return home && (0, import_node_fs46.existsSync)(home) ? home : null;
47914
+ return home && (0, import_node_fs47.existsSync)(home) ? home : null;
47793
47915
  } catch {
47794
47916
  return null;
47795
47917
  }
@@ -47797,13 +47919,13 @@ function callerHome() {
47797
47919
  function stopUserModeDaemon() {
47798
47920
  const home = callerHome();
47799
47921
  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;
47922
+ const runDir = (0, import_node_path36.join)(home, ".threatcrush", "run");
47923
+ const pidFile = (0, import_node_path36.join)(runDir, "threatcrushd.pid");
47924
+ const socket = (0, import_node_path36.join)(runDir, "threatcrushd.sock");
47925
+ if (!(0, import_node_fs47.existsSync)(pidFile) && !(0, import_node_fs47.existsSync)(socket)) return;
47804
47926
  let pid = null;
47805
47927
  try {
47806
- pid = Number.parseInt((0, import_node_fs46.readFileSync)(pidFile, "utf-8").trim(), 10);
47928
+ pid = Number.parseInt((0, import_node_fs47.readFileSync)(pidFile, "utf-8").trim(), 10);
47807
47929
  } catch {
47808
47930
  pid = null;
47809
47931
  }
@@ -47816,7 +47938,7 @@ function stopUserModeDaemon() {
47816
47938
  }
47817
47939
  for (const path2 of [socket, pidFile]) {
47818
47940
  try {
47819
- if ((0, import_node_fs46.existsSync)(path2)) (0, import_node_fs46.rmSync)(path2);
47941
+ if ((0, import_node_fs47.existsSync)(path2)) (0, import_node_fs47.rmSync)(path2);
47820
47942
  } catch {
47821
47943
  }
47822
47944
  }
@@ -47834,7 +47956,7 @@ async function installServiceCommand() {
47834
47956
  }
47835
47957
  const noSystemd = systemdUnavailableReason({
47836
47958
  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")
47959
+ booted: (0, import_node_fs47.existsSync)("/run/systemd/system")
47838
47960
  });
47839
47961
  if (noSystemd) {
47840
47962
  console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
@@ -47856,7 +47978,7 @@ async function installServiceCommand() {
47856
47978
  const isNodeScript = looksLikeNodeScript(binPath);
47857
47979
  let nodePath = stableNodePath(process.execPath);
47858
47980
  if (isNodeScript && nodeVersionDir(binPath)) {
47859
- binPath = (0, import_node_fs46.realpathSync)(binPath);
47981
+ binPath = (0, import_node_fs47.realpathSync)(binPath);
47860
47982
  nodePath = process.execPath;
47861
47983
  }
47862
47984
  if (isNodeScript) {
@@ -47869,9 +47991,9 @@ async function installServiceCommand() {
47869
47991
  }
47870
47992
  }
47871
47993
  const exec = execStartCommand(binPath, nodePath, isNodeScript);
47872
- const configDir = (0, import_node_path35.join)((0, import_node_os14.homedir)(), ".threatcrush");
47994
+ const configDir = (0, import_node_path36.join)((0, import_node_os14.homedir)(), ".threatcrush");
47873
47995
  const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
47874
- (0, import_node_fs46.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
47996
+ (0, import_node_fs47.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
47875
47997
  console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
47876
47998
  console.log(source_default.dim(` ExecStart=${exec}`));
47877
47999
  const nodeDir = nodeVersionDir(nodePath);
@@ -47924,9 +48046,9 @@ function renderLogrotate(logDir = "/var/log/threatcrush") {
47924
48046
  ].join("\n");
47925
48047
  }
47926
48048
  function installLogrotate() {
47927
- if (!(0, import_node_fs46.existsSync)((0, import_node_path35.dirname)(LOGROTATE_PATH))) return;
48049
+ if (!(0, import_node_fs47.existsSync)((0, import_node_path36.dirname)(LOGROTATE_PATH))) return;
47928
48050
  try {
47929
- (0, import_node_fs46.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
48051
+ (0, import_node_fs47.writeFileSync)(LOGROTATE_PATH, renderLogrotate(), { mode: 420 });
47930
48052
  console.log(source_default.green(` \u2713 Log rotation: ${LOGROTATE_PATH} (daily or 200M, keeps 7)`));
47931
48053
  } catch (err) {
47932
48054
  console.log(source_default.yellow(` ! Could not install log rotation: ${err.message}`));
@@ -47948,20 +48070,20 @@ function ensureSystemDirs(configDir) {
47948
48070
  ];
47949
48071
  let admGid2 = null;
47950
48072
  try {
47951
- admGid2 = (0, import_node_fs46.statSync)("/var/log/auth.log").gid;
48073
+ admGid2 = (0, import_node_fs47.statSync)("/var/log/auth.log").gid;
47952
48074
  } catch {
47953
48075
  }
47954
48076
  for (const { path: path2, groupWritable, sticky } of dirs) {
47955
48077
  try {
47956
- (0, import_node_fs46.mkdirSync)(path2, { recursive: true });
48078
+ (0, import_node_fs47.mkdirSync)(path2, { recursive: true });
47957
48079
  } catch {
47958
48080
  }
47959
48081
  try {
47960
48082
  if (groupWritable && admGid2 !== null) {
47961
- (0, import_node_fs46.chmodSync)(path2, sticky ? 1533 : 509);
48083
+ (0, import_node_fs47.chmodSync)(path2, sticky ? 1533 : 509);
47962
48084
  (0, import_node_child_process18.execSync)(`chgrp adm ${path2}`, { stdio: "ignore" });
47963
48085
  } else {
47964
- (0, import_node_fs46.chmodSync)(path2, 493);
48086
+ (0, import_node_fs47.chmodSync)(path2, 493);
47965
48087
  }
47966
48088
  } catch {
47967
48089
  }
@@ -47989,7 +48111,7 @@ async function uninstallServiceCommand() {
47989
48111
  } catch {
47990
48112
  }
47991
48113
  try {
47992
- if ((0, import_node_fs46.existsSync)(UNIT_PATH)) {
48114
+ if ((0, import_node_fs47.existsSync)(UNIT_PATH)) {
47993
48115
  (0, import_node_child_process18.execSync)(`rm -f ${UNIT_PATH}`);
47994
48116
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
47995
48117
  }
@@ -48003,7 +48125,7 @@ async function uninstallServiceCommand() {
48003
48125
  }
48004
48126
 
48005
48127
  // src/commands/save.ts
48006
- var import_node_fs47 = require("fs");
48128
+ var import_node_fs48 = require("fs");
48007
48129
  var import_toml5 = __toESM(require_toml());
48008
48130
  init_cli_config();
48009
48131
  init_paths();
@@ -48042,9 +48164,9 @@ async function saveCommand(opts = {}) {
48042
48164
  }
48043
48165
  const path2 = opts.config ?? PATHS.configFile;
48044
48166
  let config = {};
48045
- if ((0, import_node_fs47.existsSync)(path2)) {
48167
+ if ((0, import_node_fs48.existsSync)(path2)) {
48046
48168
  try {
48047
- config = import_toml5.default.parse((0, import_node_fs47.readFileSync)(path2, "utf-8"));
48169
+ config = import_toml5.default.parse((0, import_node_fs48.readFileSync)(path2, "utf-8"));
48048
48170
  } catch (err) {
48049
48171
  console.log(source_default.red(` \u2717 ${path2} is not valid TOML: ${err.message}
48050
48172
  `));
@@ -48157,17 +48279,17 @@ function welcomeCommand() {
48157
48279
  }
48158
48280
 
48159
48281
  // src/commands/properties.ts
48160
- var import_node_fs48 = require("fs");
48161
- var import_node_path36 = require("path");
48282
+ var import_node_fs49 = require("fs");
48283
+ var import_node_path37 = require("path");
48162
48284
  var import_node_readline4 = __toESM(require("readline"));
48163
48285
  init_cli_config();
48164
48286
  var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
48165
48287
  var KINDS = ["url", "api", "domain", "ip", "repo"];
48166
48288
  function prompt(question) {
48167
48289
  const rl = import_node_readline4.default.createInterface({ input: process.stdin, output: process.stdout });
48168
- return new Promise((resolve7) => rl.question(question, (answer) => {
48290
+ return new Promise((resolve8) => rl.question(question, (answer) => {
48169
48291
  rl.close();
48170
- resolve7(answer.trim());
48292
+ resolve8(answer.trim());
48171
48293
  }));
48172
48294
  }
48173
48295
  async function requireAuth() {
@@ -48488,8 +48610,8 @@ async function propertiesRunsCommand(opts) {
48488
48610
  }
48489
48611
  }
48490
48612
  function parseImportFile(path2) {
48491
- const ext = (0, import_node_path36.extname)(path2).toLowerCase();
48492
- const raw = (0, import_node_fs48.readFileSync)(path2, "utf-8");
48613
+ const ext = (0, import_node_path37.extname)(path2).toLowerCase();
48614
+ const raw = (0, import_node_fs49.readFileSync)(path2, "utf-8");
48493
48615
  if (ext === ".json") {
48494
48616
  const parsed = JSON.parse(raw);
48495
48617
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -48684,7 +48806,7 @@ async function rulesCommand(opts) {
48684
48806
  }
48685
48807
 
48686
48808
  // src/commands/harden.ts
48687
- var import_node_fs49 = require("fs");
48809
+ var import_node_fs50 = require("fs");
48688
48810
  var import_node_child_process19 = require("child_process");
48689
48811
  init_cli_config();
48690
48812
  function tryExec(cmd) {
@@ -48696,7 +48818,7 @@ function tryExec(cmd) {
48696
48818
  }
48697
48819
  function tryRead(path2) {
48698
48820
  try {
48699
- return (0, import_node_fs49.readFileSync)(path2, "utf-8");
48821
+ return (0, import_node_fs50.readFileSync)(path2, "utf-8");
48700
48822
  } catch {
48701
48823
  return null;
48702
48824
  }
@@ -48800,8 +48922,8 @@ function checkSshWeakConfig() {
48800
48922
  };
48801
48923
  }
48802
48924
  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");
48925
+ 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");
48926
+ const dnfAuto = (0, import_node_fs50.existsSync)("/etc/dnf/automatic.conf");
48805
48927
  if (unattended || dnfAuto) {
48806
48928
  return {
48807
48929
  key: "auto-updates",
@@ -48927,7 +49049,7 @@ function checkFail2ban() {
48927
49049
  explanation: "fail2ban is installed and running."
48928
49050
  };
48929
49051
  }
48930
- if ((0, import_node_fs49.existsSync)("/etc/fail2ban/fail2ban.conf")) {
49052
+ if ((0, import_node_fs50.existsSync)("/etc/fail2ban/fail2ban.conf")) {
48931
49053
  return {
48932
49054
  key: checkKey,
48933
49055
  status: "warn",
@@ -49113,8 +49235,8 @@ async function hardenCommand(opts) {
49113
49235
  }
49114
49236
 
49115
49237
  // src/core/patches/index.ts
49116
- var import_node_fs50 = require("fs");
49117
- var import_node_path37 = require("path");
49238
+ var import_node_fs51 = require("fs");
49239
+ var import_node_path38 = require("path");
49118
49240
  var import_node_child_process20 = require("child_process");
49119
49241
  var import_node_util5 = require("util");
49120
49242
 
@@ -49274,9 +49396,9 @@ async function osvRecords(doFetch, ecosystem, source, version) {
49274
49396
  function newestReleaseMtime(dir) {
49275
49397
  try {
49276
49398
  let newest = 0;
49277
- for (const name of (0, import_node_fs50.readdirSync)(dir)) {
49399
+ for (const name of (0, import_node_fs51.readdirSync)(dir)) {
49278
49400
  if (!/Release$/.test(name)) continue;
49279
- newest = Math.max(newest, (0, import_node_fs50.statSync)((0, import_node_path37.join)(dir, name)).mtimeMs);
49401
+ newest = Math.max(newest, (0, import_node_fs51.statSync)((0, import_node_path38.join)(dir, name)).mtimeMs);
49280
49402
  }
49281
49403
  return newest > 0 ? new Date(newest) : null;
49282
49404
  } catch {
@@ -49293,7 +49415,7 @@ async function checkPatches(opts = {}) {
49293
49415
  let osText = opts.osRelease;
49294
49416
  if (osText === void 0) {
49295
49417
  try {
49296
- osText = (0, import_node_fs50.readFileSync)("/etc/os-release", "utf-8");
49418
+ osText = (0, import_node_fs51.readFileSync)("/etc/os-release", "utf-8");
49297
49419
  } catch {
49298
49420
  osText = "";
49299
49421
  }
@@ -49519,25 +49641,25 @@ async function patchesCommand(opts) {
49519
49641
  }
49520
49642
 
49521
49643
  // src/commands/feeds.ts
49522
- var import_node_net13 = require("net");
49523
- var import_node_path39 = require("path");
49644
+ var import_node_net15 = require("net");
49645
+ var import_node_path40 = require("path");
49524
49646
  init_paths();
49525
49647
 
49526
49648
  // src/commands/feeds-resolver.ts
49527
49649
  var import_node_child_process21 = require("child_process");
49528
- var import_node_fs51 = require("fs");
49529
- var import_node_path38 = require("path");
49650
+ var import_node_fs52 = require("fs");
49651
+ var import_node_path39 = require("path");
49530
49652
  var realIO = {
49531
- exists: (p) => (0, import_node_fs51.existsSync)(p),
49653
+ exists: (p) => (0, import_node_fs52.existsSync)(p),
49532
49654
  read: (p) => {
49533
49655
  try {
49534
- return (0, import_node_fs51.readFileSync)(p, "utf-8");
49656
+ return (0, import_node_fs52.readFileSync)(p, "utf-8");
49535
49657
  } catch {
49536
49658
  return null;
49537
49659
  }
49538
49660
  },
49539
- write: (p, c) => (0, import_node_fs51.writeFileSync)(p, c),
49540
- remove: (p) => (0, import_node_fs51.rmSync)(p, { force: true }),
49661
+ write: (p, c) => (0, import_node_fs52.writeFileSync)(p, c),
49662
+ remove: (p) => (0, import_node_fs52.rmSync)(p, { force: true }),
49541
49663
  run: (cmd, args) => {
49542
49664
  const r = (0, import_node_child_process21.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 3e4 });
49543
49665
  return { code: r.status ?? 1, out: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
@@ -49547,17 +49669,17 @@ var APPARMOR_LOCAL = "/etc/apparmor.d/local/usr.sbin.unbound";
49547
49669
  var APPARMOR_PROFILE = "/etc/apparmor.d/usr.sbin.unbound";
49548
49670
  function hookContent(resolver, stateDir) {
49549
49671
  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)}"
49672
+ return resolver === "dnsmasq" ? `${head}addn-hosts=${(0, import_node_path39.join)(stateDir, RESOLVER_FILES.hosts)}
49673
+ ` : `${head}include: "${(0, import_node_path39.join)(stateDir, RESOLVER_FILES.unbound)}"
49552
49674
  `;
49553
49675
  }
49554
49676
  function apparmorRule(stateDir) {
49555
- return ` ${(0, import_node_path38.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
49677
+ return ` ${(0, import_node_path39.join)(stateDir, RESOLVER_FILES.unbound)} r, # threatcrush`;
49556
49678
  }
49557
49679
  function detectResolvers(io = realIO) {
49558
49680
  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");
49681
+ if (io.exists((0, import_node_path39.dirname)(RESOLVER_HOOKS.dnsmasq)) && io.run("dnsmasq", ["--version"]).code === 0) found.push("dnsmasq");
49682
+ if (io.exists((0, import_node_path39.dirname)(RESOLVER_HOOKS.unbound)) && io.run("unbound-checkconf", ["-h"]).code !== 127) found.push("unbound");
49561
49683
  return found;
49562
49684
  }
49563
49685
  function check(resolver, io) {
@@ -49570,7 +49692,7 @@ function restartIfActive(resolver, io) {
49570
49692
  }
49571
49693
  function installHook(resolver, stateDir, io = realIO) {
49572
49694
  const hook = RESOLVER_HOOKS[resolver];
49573
- const file = (0, import_node_path38.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
49695
+ const file = (0, import_node_path39.join)(stateDir, resolver === "dnsmasq" ? RESOLVER_FILES.hosts : RESOLVER_FILES.unbound);
49574
49696
  if (!io.exists(file)) io.write(file, resolver === "dnsmasq" ? hostsBlocklist([]) : unboundBlocklist([]));
49575
49697
  io.write(hook, hookContent(resolver, stateDir));
49576
49698
  if (resolver === "unbound" && io.exists(APPARMOR_LOCAL)) {
@@ -49631,8 +49753,8 @@ function resolverCommand(sub, stateDir, io = realIO) {
49631
49753
  }
49632
49754
  return failed ? 1 : 0;
49633
49755
  }
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));
49756
+ const hosts = io.read((0, import_node_path39.join)(stateDir, RESOLVER_FILES.hosts));
49757
+ const unbound = io.read((0, import_node_path39.join)(stateDir, RESOLVER_FILES.unbound));
49636
49758
  console.log(` resolvers here: ${found.join(", ") || "none that can block (systemd-resolved only?)"}`);
49637
49759
  for (const r of ["dnsmasq", "unbound"]) {
49638
49760
  console.log(` ${r.padEnd(8)} hook ${io.exists(RESOLVER_HOOKS[r]) ? source_default.green("installed") : source_default.gray("not installed")}`);
@@ -49644,11 +49766,11 @@ function resolverCommand(sub, stateDir, io = realIO) {
49644
49766
  // src/commands/feeds.ts
49645
49767
  async function loadSet() {
49646
49768
  for (const dir of [SYSTEM_PATHS.stateDir, USER_PATHS.stateDir]) {
49647
- const path2 = (0, import_node_path39.join)(dir, "threat-feeds.json");
49769
+ const path2 = (0, import_node_path40.join)(dir, "threat-feeds.json");
49648
49770
  const set = readFeedCache(path2);
49649
49771
  if (set) return { set, from: path2 };
49650
49772
  }
49651
- const settings = threatFeedSettings(loadConfig((0, import_node_path39.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
49773
+ const settings = threatFeedSettings(loadConfig((0, import_node_path40.join)(SYSTEM_PATHS.configDir, "threatcrushd.conf")).threat_feeds);
49652
49774
  return { set: await fetchFeeds(settings), from: "abuse.ch (live; no daemon cache readable)" };
49653
49775
  }
49654
49776
  async function feedsCommand(action, value, opts) {
@@ -49663,8 +49785,8 @@ async function feedsCommand(action, value, opts) {
49663
49785
  process.exitCode = 2;
49664
49786
  return;
49665
49787
  }
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);
49788
+ const ipHit = (0, import_node_net15.isIP)(value) ? matchIp(value, set) : null;
49789
+ const domainHit = (0, import_node_net15.isIP)(value) ? null : matchDomain(value, set);
49668
49790
  const listed = ipHit ?? domainHit?.indicator ?? null;
49669
49791
  if (opts.json) {
49670
49792
  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 +49815,13 @@ async function feedsCommand(action, value, opts) {
49693
49815
 
49694
49816
  // src/commands/reputation.ts
49695
49817
  var import_node_os15 = require("os");
49696
- var import_node_fs52 = require("fs");
49697
- var import_node_path40 = require("path");
49818
+ var import_node_fs53 = require("fs");
49819
+ var import_node_path41 = require("path");
49698
49820
  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");
49821
+ var CONFIG_PATH4 = (0, import_node_path41.join)((0, import_node_os15.homedir)(), ".threatcrush", "config.json");
49700
49822
  function readConfig3() {
49701
49823
  try {
49702
- return JSON.parse((0, import_node_fs52.readFileSync)(CONFIG_PATH4, "utf-8"));
49824
+ return JSON.parse((0, import_node_fs53.readFileSync)(CONFIG_PATH4, "utf-8"));
49703
49825
  } catch {
49704
49826
  return {};
49705
49827
  }
@@ -49887,7 +50009,7 @@ async function reputationSubscribeCommand(opts) {
49887
50009
  }
49888
50010
 
49889
50011
  // src/commands/privileged.ts
49890
- var import_node_fs53 = require("fs");
50012
+ var import_node_fs54 = require("fs");
49891
50013
  init_paths();
49892
50014
  var SEV2 = {
49893
50015
  critical: source_default.red.bold,
@@ -49900,19 +50022,19 @@ async function privilegedCommand(opts) {
49900
50022
  const snapshot = takeSnapshot({
49901
50023
  readFile: (p) => {
49902
50024
  try {
49903
- return (0, import_node_fs53.readFileSync)(p, "utf-8");
50025
+ return (0, import_node_fs54.readFileSync)(p, "utf-8");
49904
50026
  } catch {
49905
50027
  return null;
49906
50028
  }
49907
50029
  },
49908
50030
  readDir: (p) => {
49909
50031
  try {
49910
- return (0, import_node_fs53.readdirSync)(p);
50032
+ return (0, import_node_fs54.readdirSync)(p);
49911
50033
  } catch {
49912
50034
  return null;
49913
50035
  }
49914
50036
  },
49915
- exists: (p) => (0, import_node_fs53.existsSync)(p)
50037
+ exists: (p) => (0, import_node_fs54.existsSync)(p)
49916
50038
  });
49917
50039
  let events = [];
49918
50040
  let ledgerNote = "";
@@ -50094,7 +50216,7 @@ async function allowlistCommand(opts) {
50094
50216
  }
50095
50217
 
50096
50218
  // src/commands/abuse.ts
50097
- var import_node_fs54 = require("fs");
50219
+ var import_node_fs55 = require("fs");
50098
50220
  init_paths();
50099
50221
  function rows(records) {
50100
50222
  if (records.length === 0) {
@@ -50154,7 +50276,7 @@ function abuseRetractCommand(id, opts = {}) {
50154
50276
  );
50155
50277
  }
50156
50278
  function abuseStatusCommand(opts = {}) {
50157
- const config = loadConfig((0, import_node_fs54.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
50279
+ const config = loadConfig((0, import_node_fs55.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
50158
50280
  const cfg = resolveConfig(config.abuse_reporter);
50159
50281
  const hasKey2 = Boolean(cfg.keys.abuseipdb || cfg.keys.stopforumspam);
50160
50282
  const active2 = cfg.enabled && (cfg.dryRun || hasKey2);
@@ -50324,7 +50446,7 @@ function installUserAgent(target = globalThis) {
50324
50446
  // src/core/cloud-upload.ts
50325
50447
  var import_node_child_process23 = require("child_process");
50326
50448
  var import_node_os16 = require("os");
50327
- var import_node_path41 = require("path");
50449
+ var import_node_path42 = require("path");
50328
50450
  init_cli_config();
50329
50451
  function uploadDisabled(upload, env3 = process.env) {
50330
50452
  if (upload === false) return true;
@@ -50343,8 +50465,8 @@ function cleanUrl(raw) {
50343
50465
  return raw.split(/[?#]/)[0];
50344
50466
  }
50345
50467
  }
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);
50468
+ 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()) {
50469
+ const abs = (0, import_node_path42.resolve)(path2);
50348
50470
  try {
50349
50471
  const root = run(["rev-parse", "--show-toplevel"]);
50350
50472
  const sub = abs === root ? "." : abs.slice(root.length + 1);
@@ -50716,7 +50838,7 @@ ${source_default.dim(" C R U S H")}
50716
50838
  var API_URL8 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
50717
50839
  var PKG_NAME2 = "@profullstack/threatcrush";
50718
50840
  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");
50841
+ var INSTALL_CONFIG_PATH = (0, import_node_path43.join)((0, import_node_os17.homedir)(), ".threatcrush", "install.json");
50720
50842
  function detectPackageManager() {
50721
50843
  try {
50722
50844
  const npmGlobal = (0, import_node_child_process24.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
@@ -50742,7 +50864,7 @@ function detectPackageManager() {
50742
50864
  }
50743
50865
  function readInstallConfig() {
50744
50866
  try {
50745
- return JSON.parse((0, import_node_fs55.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
50867
+ return JSON.parse((0, import_node_fs56.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
50746
50868
  } catch {
50747
50869
  return {};
50748
50870
  }
@@ -51152,7 +51274,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
51152
51274
  program2.command("logs").description("Tail daemon logs").action(async () => {
51153
51275
  console.log(LOGO2);
51154
51276
  const logPath2 = PATHS.logFile;
51155
- if (!(0, import_node_fs55.existsSync)(logPath2)) {
51277
+ if (!(0, import_node_fs56.existsSync)(logPath2)) {
51156
51278
  console.log(source_default.yellow(` No log file found at ${logPath2}`));
51157
51279
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
51158
51280
  return;
@@ -51220,10 +51342,10 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
51220
51342
  program2.command("remove").description("Uninstall ThreatCrush and the installed bundle").alias("uninstall").action(async () => {
51221
51343
  console.log(LOGO2);
51222
51344
  const rl = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
51223
- const confirm = await new Promise((resolve7) => {
51345
+ const confirm = await new Promise((resolve8) => {
51224
51346
  rl.question(source_default.yellow(" Are you sure you want to uninstall ThreatCrush? (y/N): "), (answer) => {
51225
51347
  rl.close();
51226
- resolve7(answer.trim().toLowerCase());
51348
+ resolve8(answer.trim().toLowerCase());
51227
51349
  });
51228
51350
  });
51229
51351
  if (confirm !== "y" && confirm !== "yes") {
@@ -51325,19 +51447,19 @@ storeCmd.command("search <query>").description("Search for modules in the store"
51325
51447
  });
51326
51448
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
51327
51449
  console.log(LOGO2);
51328
- const configPath = (0, import_node_path42.join)((0, import_node_os17.homedir)(), ".threatcrush", "config.json");
51450
+ const configPath = (0, import_node_path43.join)((0, import_node_os17.homedir)(), ".threatcrush", "config.json");
51329
51451
  let email = "";
51330
51452
  try {
51331
- const config = JSON.parse((0, import_node_fs55.readFileSync)(configPath, "utf-8"));
51453
+ const config = JSON.parse((0, import_node_fs56.readFileSync)(configPath, "utf-8"));
51332
51454
  email = config.email || "";
51333
51455
  } catch {
51334
51456
  }
51335
51457
  if (!email) {
51336
51458
  const rl2 = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
51337
- email = await new Promise((resolve7) => {
51459
+ email = await new Promise((resolve8) => {
51338
51460
  rl2.question(source_default.green(" Enter your email: "), (answer) => {
51339
51461
  rl2.close();
51340
- resolve7(answer.trim());
51462
+ resolve8(answer.trim());
51341
51463
  });
51342
51464
  });
51343
51465
  if (!email || !email.includes("@")) {
@@ -51345,9 +51467,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
51345
51467
  return;
51346
51468
  }
51347
51469
  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));
51470
+ const dir = (0, import_node_path43.join)((0, import_node_os17.homedir)(), ".threatcrush");
51471
+ if (!(0, import_node_fs56.existsSync)(dir)) (0, import_node_fs56.mkdirSync)(dir, { recursive: true });
51472
+ (0, import_node_fs56.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
51351
51473
  console.log(source_default.dim(` Saved email to ${configPath}`));
51352
51474
  } catch {
51353
51475
  }
@@ -51391,10 +51513,10 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
51391
51513
  }
51392
51514
  console.log();
51393
51515
  const rl = import_readline.default.createInterface({ input: process.stdin, output: process.stdout });
51394
- const confirm = await new Promise((resolve7) => {
51516
+ const confirm = await new Promise((resolve8) => {
51395
51517
  rl.question(source_default.yellow(" Publish this module? (y/N): "), (answer) => {
51396
51518
  rl.close();
51397
- resolve7(answer.trim().toLowerCase());
51519
+ resolve8(answer.trim().toLowerCase());
51398
51520
  });
51399
51521
  });
51400
51522
  if (confirm !== "y" && confirm !== "yes") {