@profullstack/threatcrush 0.13.23 → 0.13.25

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
@@ -13920,6 +13920,91 @@ var init_demo = __esm({
13920
13920
  }
13921
13921
  });
13922
13922
 
13923
+ // src/tui/clipboard.ts
13924
+ function nativeHelpers(env2, platform) {
13925
+ const overSsh = !!(env2.SSH_CONNECTION || env2.SSH_TTY);
13926
+ const helpers = [];
13927
+ if (platform === "darwin" && !overSsh) helpers.push(["pbcopy", []]);
13928
+ if (env2.WAYLAND_DISPLAY) helpers.push(["wl-copy", []]);
13929
+ if (env2.DISPLAY) {
13930
+ helpers.push(["xclip", ["-selection", "clipboard"]]);
13931
+ helpers.push(["xsel", ["--clipboard", "--input"]]);
13932
+ }
13933
+ return helpers;
13934
+ }
13935
+ function copyToClipboard(text, deps = defaultDeps()) {
13936
+ const via = [];
13937
+ const { env: env2 } = deps;
13938
+ for (const [cmd, args] of nativeHelpers(env2, deps.platform)) {
13939
+ if (deps.run(cmd, args, text)) {
13940
+ via.push(cmd);
13941
+ break;
13942
+ }
13943
+ }
13944
+ if (env2.TMUX) {
13945
+ if (deps.run("tmux", ["load-buffer", "-w", "-"], text) || deps.run("tmux", ["load-buffer", "-"], text)) {
13946
+ via.push("tmux");
13947
+ }
13948
+ }
13949
+ try {
13950
+ deps.write(clipboardSequence(text));
13951
+ if (env2.TMUX) deps.write(clipboardSequence(text, true));
13952
+ via.push("osc52");
13953
+ } catch {
13954
+ }
13955
+ let file;
13956
+ try {
13957
+ const path = (0, import_node_path6.join)(deps.fileDir, "last-copy.txt");
13958
+ deps.saveFile(path, text.endsWith("\n") ? text : `${text}
13959
+ `);
13960
+ file = path;
13961
+ } catch {
13962
+ }
13963
+ return { via, file };
13964
+ }
13965
+ function describeCopy(result, home = (0, import_node_os3.homedir)()) {
13966
+ const file = result.file ? result.file.replace(home, "~") : null;
13967
+ const native = result.via.filter((v) => v !== "osc52");
13968
+ if (native.length > 0) {
13969
+ return `copied (${result.via.join(" + ")})${file ? ` \xB7 also ${file}` : ""}`;
13970
+ }
13971
+ if (result.via.includes("osc52")) {
13972
+ return `sent to terminal clipboard (OSC 52; iTerm2: allow clipboard access)${file ? ` \xB7 saved ${file}` : ""}`;
13973
+ }
13974
+ return file ? `could not reach a clipboard \xB7 saved ${file}` : "copy failed: no clipboard available";
13975
+ }
13976
+ var import_node_child_process, import_node_fs8, import_node_os3, import_node_path6, defaultDeps;
13977
+ var init_clipboard = __esm({
13978
+ "src/tui/clipboard.ts"() {
13979
+ "use strict";
13980
+ import_node_child_process = require("child_process");
13981
+ import_node_fs8 = require("fs");
13982
+ import_node_os3 = require("os");
13983
+ import_node_path6 = require("path");
13984
+ init_dist();
13985
+ defaultDeps = () => ({
13986
+ env: process.env,
13987
+ platform: process.platform,
13988
+ run: (cmd, args, input) => {
13989
+ try {
13990
+ const r = (0, import_node_child_process.spawnSync)(cmd, args, { input, stdio: ["pipe", "ignore", "ignore"], timeout: 1500 });
13991
+ return !r.error && r.status === 0;
13992
+ } catch {
13993
+ return false;
13994
+ }
13995
+ },
13996
+ write: (data) => {
13997
+ process.stdout.write(data);
13998
+ },
13999
+ saveFile: (path, text) => {
14000
+ (0, import_node_fs8.mkdirSync)((0, import_node_path6.dirname)(path), { recursive: true });
14001
+ (0, import_node_fs8.writeFileSync)(path, text, { mode: 384 });
14002
+ },
14003
+ fileDir: (0, import_node_path6.join)((0, import_node_os3.homedir)(), ".threatcrush")
14004
+ });
14005
+ }
14006
+ });
14007
+
13923
14008
  // src/tui/dashboard.ts
13924
14009
  var dashboard_exports = {};
13925
14010
  __export(dashboard_exports, {
@@ -13941,12 +14026,8 @@ async function startDashboard(options = {}) {
13941
14026
  };
13942
14027
  const copyText = (text) => {
13943
14028
  if (!text) return;
13944
- try {
13945
- process.stdout.write(clipboardSequence(text, !!process.env.TMUX));
13946
- dispatch({ type: "notice", text: `copied to clipboard: ${text.length > 60 ? `${text.slice(0, 57)}...` : text}`, tone: "ok" });
13947
- } catch (err) {
13948
- dispatch({ type: "notice", text: `copy failed: ${err.message}`, tone: "error" });
13949
- }
14029
+ const result = copyToClipboard(text);
14030
+ dispatch({ type: "notice", text: describeCopy(result), tone: result.via.length > 0 || result.file ? "ok" : "error" });
13950
14031
  };
13951
14032
  let client = null;
13952
14033
  let stopped = false;
@@ -14207,6 +14288,7 @@ var init_dashboard = __esm({
14207
14288
  init_theme2();
14208
14289
  init_view();
14209
14290
  init_demo();
14291
+ init_clipboard();
14210
14292
  RECONNECT_MS = 2e3;
14211
14293
  POLL_MS = 2e3;
14212
14294
  }
@@ -16371,13 +16453,13 @@ var source_default = chalk;
16371
16453
 
16372
16454
  // src/index.ts
16373
16455
  var import_readline = __toESM(require("readline"));
16374
- var import_node_child_process15 = require("child_process");
16375
- var import_node_fs40 = require("fs");
16376
- var import_node_path27 = require("path");
16377
- var import_node_os11 = require("os");
16456
+ var import_node_child_process16 = require("child_process");
16457
+ var import_node_fs41 = require("fs");
16458
+ var import_node_path28 = require("path");
16459
+ var import_node_os12 = require("os");
16378
16460
 
16379
16461
  // src/commands/monitor.ts
16380
- var import_node_fs8 = require("fs");
16462
+ var import_node_fs9 = require("fs");
16381
16463
 
16382
16464
  // src/core/log-tail.ts
16383
16465
  var import_node_fs = require("fs");
@@ -23504,9 +23586,9 @@ async function monitorCommand(options) {
23504
23586
  const unreadable = [];
23505
23587
  for (const s of LOG_SOURCES) {
23506
23588
  if (moduleFilter && !moduleFilter.includes(s.name)) continue;
23507
- if (!(0, import_node_fs8.existsSync)(s.path)) continue;
23589
+ if (!(0, import_node_fs9.existsSync)(s.path)) continue;
23508
23590
  try {
23509
- (0, import_node_fs8.accessSync)(s.path, import_node_fs8.constants.R_OK);
23591
+ (0, import_node_fs9.accessSync)(s.path, import_node_fs9.constants.R_OK);
23510
23592
  availableSources.push(s);
23511
23593
  } catch {
23512
23594
  unreadable.push(s);
@@ -23523,11 +23605,11 @@ async function monitorCommand(options) {
23523
23605
  logger.warn("No readable log files found to monitor.");
23524
23606
  logger.info("Available log paths checked:");
23525
23607
  for (const s of LOG_SOURCES) {
23526
- const exists = (0, import_node_fs8.existsSync)(s.path);
23608
+ const exists = (0, import_node_fs9.existsSync)(s.path);
23527
23609
  let readable = false;
23528
23610
  if (exists) {
23529
23611
  try {
23530
- (0, import_node_fs8.accessSync)(s.path, import_node_fs8.constants.R_OK);
23612
+ (0, import_node_fs9.accessSync)(s.path, import_node_fs9.constants.R_OK);
23531
23613
  readable = true;
23532
23614
  } catch {
23533
23615
  readable = false;
@@ -23669,14 +23751,14 @@ async function runDemoMode() {
23669
23751
  }
23670
23752
 
23671
23753
  // src/commands/watchdog.ts
23672
- var import_node_fs10 = require("fs");
23673
- var import_node_path7 = require("path");
23754
+ var import_node_fs11 = require("fs");
23755
+ var import_node_path8 = require("path");
23674
23756
  init_paths();
23675
23757
 
23676
23758
  // src/core/watchdog.ts
23677
- var import_node_fs9 = require("fs");
23759
+ var import_node_fs10 = require("fs");
23678
23760
  var import_node_crypto2 = require("crypto");
23679
- var import_node_path6 = require("path");
23761
+ var import_node_path7 = require("path");
23680
23762
  var WATCHDOG_DIRNAME = "watchdog";
23681
23763
  var LOG_FILE = "attacks.jsonl";
23682
23764
  var ROTATED_FILE = "attacks.1.jsonl";
@@ -23761,7 +23843,7 @@ function dedupeKey(r) {
23761
23843
  }
23762
23844
  function isShared(dir) {
23763
23845
  try {
23764
- return ((0, import_node_fs9.statSync)(dir).mode & 1024) !== 0;
23846
+ return ((0, import_node_fs10.statSync)(dir).mode & 1024) !== 0;
23765
23847
  } catch {
23766
23848
  return false;
23767
23849
  }
@@ -23775,12 +23857,12 @@ var WatchdogLog = class {
23775
23857
  stats = { logged: 0, answered: 0, errored: 0 };
23776
23858
  constructor(dir, options = {}) {
23777
23859
  this.dir = dir;
23778
- this.file = (0, import_node_path6.join)(dir, LOG_FILE);
23860
+ this.file = (0, import_node_path7.join)(dir, LOG_FILE);
23779
23861
  this.shareGid = options.shareGid;
23780
- (0, import_node_fs9.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
23862
+ (0, import_node_fs10.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
23781
23863
  if (this.shareGid !== void 0) {
23782
- (0, import_node_fs9.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
23783
- (0, import_node_fs9.chmodSync)(dir, 1528);
23864
+ (0, import_node_fs10.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
23865
+ (0, import_node_fs10.chmodSync)(dir, 1528);
23784
23866
  }
23785
23867
  for (const r of readTail(this.file, 512 * 1024)) this.remember(dedupeKey(r));
23786
23868
  }
@@ -23809,16 +23891,16 @@ var WatchdogLog = class {
23809
23891
  const chunk = this.buffer.join("\n") + "\n";
23810
23892
  this.buffer = [];
23811
23893
  try {
23812
- if ((0, import_node_fs9.statSync)(this.file).size > ROTATE_BYTES) {
23813
- (0, import_node_fs9.renameSync)(this.file, (0, import_node_path6.join)(this.dir, ROTATED_FILE));
23894
+ if ((0, import_node_fs10.statSync)(this.file).size > ROTATE_BYTES) {
23895
+ (0, import_node_fs10.renameSync)(this.file, (0, import_node_path7.join)(this.dir, ROTATED_FILE));
23814
23896
  }
23815
23897
  } catch {
23816
23898
  }
23817
- (0, import_node_fs9.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
23899
+ (0, import_node_fs10.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
23818
23900
  if (this.shareGid !== void 0) {
23819
23901
  try {
23820
- (0, import_node_fs9.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
23821
- (0, import_node_fs9.chmodSync)(this.file, 432);
23902
+ (0, import_node_fs10.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
23903
+ (0, import_node_fs10.chmodSync)(this.file, 432);
23822
23904
  } catch {
23823
23905
  }
23824
23906
  }
@@ -23839,50 +23921,50 @@ function parseLines(text) {
23839
23921
  function readTail(file, bytes) {
23840
23922
  let fd;
23841
23923
  try {
23842
- fd = (0, import_node_fs9.openSync)(file, "r");
23924
+ fd = (0, import_node_fs10.openSync)(file, "r");
23843
23925
  } catch (err) {
23844
23926
  if (err.code === "ENOENT") return [];
23845
23927
  throw err;
23846
23928
  }
23847
23929
  try {
23848
- const size = (0, import_node_fs9.fstatSync)(fd).size;
23930
+ const size = (0, import_node_fs10.fstatSync)(fd).size;
23849
23931
  const start = Math.max(0, size - bytes);
23850
23932
  const buf = Buffer.alloc(size - start);
23851
- (0, import_node_fs9.readSync)(fd, buf, 0, buf.length, start);
23933
+ (0, import_node_fs10.readSync)(fd, buf, 0, buf.length, start);
23852
23934
  let text = buf.toString("utf8");
23853
23935
  if (start > 0) text = text.slice(text.indexOf("\n") + 1);
23854
23936
  return parseLines(text);
23855
23937
  } finally {
23856
- (0, import_node_fs9.closeSync)(fd);
23938
+ (0, import_node_fs10.closeSync)(fd);
23857
23939
  }
23858
23940
  }
23859
23941
  function readAttacks(dir) {
23860
23942
  const out = [];
23861
23943
  for (const name of [ROTATED_FILE, LOG_FILE]) {
23862
- const file = (0, import_node_path6.join)(dir, name);
23863
- if ((0, import_node_fs9.existsSync)(file)) out.push(...parseLines((0, import_node_fs9.readFileSync)(file, "utf8")));
23944
+ const file = (0, import_node_path7.join)(dir, name);
23945
+ if ((0, import_node_fs10.existsSync)(file)) out.push(...parseLines((0, import_node_fs10.readFileSync)(file, "utf8")));
23864
23946
  }
23865
23947
  return out;
23866
23948
  }
23867
23949
  function readTriage(dir) {
23868
- const file = (0, import_node_path6.join)(dir, TRIAGE_FILE);
23869
- if (!(0, import_node_fs9.existsSync)(file)) return {};
23950
+ const file = (0, import_node_path7.join)(dir, TRIAGE_FILE);
23951
+ if (!(0, import_node_fs10.existsSync)(file)) return {};
23870
23952
  try {
23871
- return JSON.parse((0, import_node_fs9.readFileSync)(file, "utf8"));
23953
+ return JSON.parse((0, import_node_fs10.readFileSync)(file, "utf8"));
23872
23954
  } catch {
23873
23955
  return {};
23874
23956
  }
23875
23957
  }
23876
23958
  function writeTriage(dir, map) {
23877
- (0, import_node_fs9.mkdirSync)(dir, { recursive: true });
23878
- const file = (0, import_node_path6.join)(dir, TRIAGE_FILE);
23959
+ (0, import_node_fs10.mkdirSync)(dir, { recursive: true });
23960
+ const file = (0, import_node_path7.join)(dir, TRIAGE_FILE);
23879
23961
  const mode = isShared(dir) ? 432 : 384;
23880
- (0, import_node_fs9.writeFileSync)(`${file}.tmp`, JSON.stringify(map, null, 2) + "\n", { mode });
23962
+ (0, import_node_fs10.writeFileSync)(`${file}.tmp`, JSON.stringify(map, null, 2) + "\n", { mode });
23881
23963
  try {
23882
- (0, import_node_fs9.chmodSync)(`${file}.tmp`, mode);
23964
+ (0, import_node_fs10.chmodSync)(`${file}.tmp`, mode);
23883
23965
  } catch {
23884
23966
  }
23885
- (0, import_node_fs9.renameSync)(`${file}.tmp`, file);
23967
+ (0, import_node_fs10.renameSync)(`${file}.tmp`, file);
23886
23968
  }
23887
23969
  function setTriage(dir, id, update, now = /* @__PURE__ */ new Date()) {
23888
23970
  const map = readTriage(dir);
@@ -24025,9 +24107,9 @@ function outcomeExplainer(o) {
24025
24107
  function resolveWatchdogDir(dir) {
24026
24108
  if (dir) return dir;
24027
24109
  if (process.env.THREATCRUSH_WATCHDOG_DIR) return process.env.THREATCRUSH_WATCHDOG_DIR;
24028
- const system = (0, import_node_path7.join)("/var/lib/threatcrush", WATCHDOG_DIRNAME);
24029
- if ((0, import_node_fs10.existsSync)(system)) return system;
24030
- return (0, import_node_path7.join)(PATHS.stateDir, WATCHDOG_DIRNAME);
24110
+ const system = (0, import_node_path8.join)("/var/lib/threatcrush", WATCHDOG_DIRNAME);
24111
+ if ((0, import_node_fs11.existsSync)(system)) return system;
24112
+ return (0, import_node_path8.join)(PATHS.stateDir, WATCHDOG_DIRNAME);
24031
24113
  }
24032
24114
  function load(dir) {
24033
24115
  return groupFindings(readAttacks(dir), readTriage(dir));
@@ -24063,7 +24145,7 @@ function watchdogListCommand(opts) {
24063
24145
  return;
24064
24146
  }
24065
24147
  if (findings.length === 0) {
24066
- const empty = (0, import_node_fs10.existsSync)((0, import_node_path7.join)(dir, "attacks.jsonl")) ? "Nothing to triage." + (opts.all ? "" : " (refused and triaged findings hidden; --all shows them)") : `No watchdog log at ${dir}. The daemon writes it: threatcrush start (or upgrade + restart an older daemon).`;
24148
+ const empty = (0, import_node_fs11.existsSync)((0, import_node_path8.join)(dir, "attacks.jsonl")) ? "Nothing to triage." + (opts.all ? "" : " (refused and triaged findings hidden; --all shows them)") : `No watchdog log at ${dir}. The daemon writes it: threatcrush start (or upgrade + restart an older daemon).`;
24067
24149
  console.log(source_default.dim(empty));
24068
24150
  return;
24069
24151
  }
@@ -24130,8 +24212,8 @@ function watchdogPathCommand(opts) {
24130
24212
  }
24131
24213
 
24132
24214
  // src/commands/scan.ts
24133
- var import_node_fs13 = require("fs");
24134
- var import_node_path11 = require("path");
24215
+ var import_node_fs14 = require("fs");
24216
+ var import_node_path12 = require("path");
24135
24217
 
24136
24218
  // ../../node_modules/.pnpm/ora@8.2.0/node_modules/ora/index.js
24137
24219
  var import_node_process7 = __toESM(require("process"), 1);
@@ -25058,7 +25140,7 @@ function ora(options) {
25058
25140
  }
25059
25141
 
25060
25142
  // src/core/run-result.ts
25061
- var import_node_os3 = __toESM(require("os"));
25143
+ var import_node_os4 = __toESM(require("os"));
25062
25144
  function emptyCounts() {
25063
25145
  return { critical: 0, high: 0, medium: 0, low: 0, info: 0 };
25064
25146
  }
@@ -25068,7 +25150,7 @@ function summarize(findings) {
25068
25150
  return counts;
25069
25151
  }
25070
25152
  function workerId() {
25071
- return `${import_node_os3.default.hostname()}/${process.pid}`;
25153
+ return `${import_node_os4.default.hostname()}/${process.pid}`;
25072
25154
  }
25073
25155
 
25074
25156
  // ../../packages/scan/src/node-rules.ts
@@ -28045,8 +28127,8 @@ function meetsFailThreshold(findings, threshold) {
28045
28127
  }
28046
28128
 
28047
28129
  // ../../packages/scan/src/node/walk.ts
28048
- var import_node_fs11 = require("fs");
28049
- var import_node_path8 = require("path");
28130
+ var import_node_fs12 = require("fs");
28131
+ var import_node_path9 = require("path");
28050
28132
  function compileExcludes(patterns) {
28051
28133
  const matchers = patterns.map((p) => p.trim()).filter((p) => p.length > 0 && !p.startsWith("#")).map(compilePattern);
28052
28134
  if (matchers.length === 0) return () => false;
@@ -28117,7 +28199,7 @@ function matchPrefix(parts, segs) {
28117
28199
  }
28118
28200
  function readIgnoreFile(root) {
28119
28201
  try {
28120
- return (0, import_node_fs11.readFileSync)((0, import_node_path8.join)(root, ".threatcrushignore"), "utf-8").split("\n");
28202
+ return (0, import_node_fs12.readFileSync)((0, import_node_path9.join)(root, ".threatcrushignore"), "utf-8").split("\n");
28121
28203
  } catch {
28122
28204
  return [];
28123
28205
  }
@@ -28133,16 +28215,16 @@ function scanPath(targetPath, options = {}) {
28133
28215
  let excluded = 0;
28134
28216
  const rootIsDirectory = (() => {
28135
28217
  try {
28136
- return (0, import_node_fs11.statSync)(targetPath).isDirectory();
28218
+ return (0, import_node_fs12.statSync)(targetPath).isDirectory();
28137
28219
  } catch {
28138
28220
  return true;
28139
28221
  }
28140
28222
  })();
28141
- const walkRoot = rootIsDirectory ? targetPath : (0, import_node_path8.dirname)(targetPath);
28223
+ const walkRoot = rootIsDirectory ? targetPath : (0, import_node_path9.dirname)(targetPath);
28142
28224
  const isExcluded = compileExcludes([...options.exclude ?? [], ...readIgnoreFile(walkRoot)]);
28143
28225
  const scanFile = (fullPath, filename) => {
28144
28226
  const relativePath = toRelative(walkRoot, fullPath);
28145
- const extension = (0, import_node_path8.extname)(filename).toLowerCase();
28227
+ const extension = (0, import_node_path9.extname)(filename).toLowerCase();
28146
28228
  const isManifest = filename === "package.json" || filename === "requirements.txt";
28147
28229
  const scannable = SCAN_EXTENSIONS.has(extension) || filename.startsWith(".env");
28148
28230
  const mayDeclareInterpreter = !scannable && !isManifest && extension === "";
@@ -28154,26 +28236,26 @@ function scanPath(targetPath, options = {}) {
28154
28236
  let handle;
28155
28237
  let declared = null;
28156
28238
  try {
28157
- handle = (0, import_node_fs11.openSync)(fullPath, "r");
28239
+ handle = (0, import_node_fs12.openSync)(fullPath, "r");
28158
28240
  } catch {
28159
28241
  unreadable.push(relativePath);
28160
28242
  return;
28161
28243
  }
28162
28244
  try {
28163
- if ((0, import_node_fs11.fstatSync)(handle).size > maxFileBytes) return;
28245
+ if ((0, import_node_fs12.fstatSync)(handle).size > maxFileBytes) return;
28164
28246
  if (mayDeclareInterpreter) {
28165
28247
  const prefix = Buffer.alloc(128);
28166
- const read = (0, import_node_fs11.readSync)(handle, prefix, 0, prefix.length, 0);
28248
+ const read = (0, import_node_fs12.readSync)(handle, prefix, 0, prefix.length, 0);
28167
28249
  declared = languageOfShebang(prefix.subarray(0, read).toString("utf-8").split("\n", 1)[0] ?? "");
28168
28250
  if (!declared) return;
28169
28251
  }
28170
- text = (0, import_node_fs11.readFileSync)(handle, "utf-8");
28252
+ text = (0, import_node_fs12.readFileSync)(handle, "utf-8");
28171
28253
  } catch {
28172
28254
  unreadable.push(relativePath);
28173
28255
  return;
28174
28256
  } finally {
28175
28257
  try {
28176
- (0, import_node_fs11.closeSync)(handle);
28258
+ (0, import_node_fs12.closeSync)(handle);
28177
28259
  } catch {
28178
28260
  }
28179
28261
  }
@@ -28191,13 +28273,13 @@ function scanPath(targetPath, options = {}) {
28191
28273
  const walk = (currentPath) => {
28192
28274
  let entries;
28193
28275
  try {
28194
- entries = (0, import_node_fs11.readdirSync)(currentPath, { withFileTypes: true });
28276
+ entries = (0, import_node_fs12.readdirSync)(currentPath, { withFileTypes: true });
28195
28277
  } catch {
28196
28278
  unreadable.push(toRelative(walkRoot, currentPath));
28197
28279
  return;
28198
28280
  }
28199
28281
  for (const entry of entries) {
28200
- const fullPath = (0, import_node_path8.join)(currentPath, entry.name);
28282
+ const fullPath = (0, import_node_path9.join)(currentPath, entry.name);
28201
28283
  const relativePath = toRelative(walkRoot, fullPath);
28202
28284
  if (entry.isDirectory()) {
28203
28285
  if (SKIP_DIRS.has(entry.name)) continue;
@@ -28221,7 +28303,7 @@ function scanPath(targetPath, options = {}) {
28221
28303
  } else if (isExcluded(toRelative(walkRoot, targetPath))) {
28222
28304
  excluded += 1;
28223
28305
  } else {
28224
- scanFile(targetPath, (0, import_node_path8.basename)(targetPath));
28306
+ scanFile(targetPath, (0, import_node_path9.basename)(targetPath));
28225
28307
  }
28226
28308
  if (options.missingControls) findings.push(...controls.findings());
28227
28309
  const filtered = allowed ? findings.filter((f) => allowed.has(f.category)) : findings;
@@ -28253,22 +28335,22 @@ function recordSensitiveFile(filename, relativePath, sink, fileFindings) {
28253
28335
  }
28254
28336
  }
28255
28337
  function toRelative(base, target) {
28256
- const rel = (0, import_node_path8.relative)(base, target);
28257
- return (rel === "" ? target : rel).split(import_node_path8.sep).join("/");
28338
+ const rel = (0, import_node_path9.relative)(base, target);
28339
+ return (rel === "" ? target : rel).split(import_node_path9.sep).join("/");
28258
28340
  }
28259
28341
 
28260
28342
  // ../../packages/scan/src/node/dependencies.ts
28261
- var import_node_fs12 = require("fs");
28262
- var import_node_path9 = require("path");
28343
+ var import_node_fs13 = require("fs");
28344
+ var import_node_path10 = require("path");
28263
28345
  var MAX_DEPS_PER_LOCKFILE = 50;
28264
28346
  async function scanDependencies(targetPath) {
28265
28347
  const findings = [];
28266
28348
  for (const { file, ecosystem, parse: parse2 } of LOCKFILES) {
28267
- const lockPath = (0, import_node_path9.join)(targetPath, file);
28268
- if (!(0, import_node_fs12.existsSync)(lockPath)) continue;
28349
+ const lockPath = (0, import_node_path10.join)(targetPath, file);
28350
+ if (!(0, import_node_fs13.existsSync)(lockPath)) continue;
28269
28351
  let deps;
28270
28352
  try {
28271
- deps = dedupe(parse2((0, import_node_fs12.readFileSync)(lockPath, "utf-8")));
28353
+ deps = dedupe(parse2((0, import_node_fs13.readFileSync)(lockPath, "utf-8")));
28272
28354
  } catch {
28273
28355
  continue;
28274
28356
  }
@@ -28483,7 +28565,7 @@ async function queryOsv(name, version, ecosystem) {
28483
28565
 
28484
28566
  // ../../packages/scan/src/node/sarif.ts
28485
28567
  var import_node_crypto3 = require("crypto");
28486
- var import_node_path10 = require("path");
28568
+ var import_node_path11 = require("path");
28487
28569
  var FINGERPRINT_KEY = "threatcrush/contentHash/v1";
28488
28570
  function fingerprintOf(finding) {
28489
28571
  const content = finding.excerpt.replace(/\s+/g, " ").trim();
@@ -28521,11 +28603,11 @@ function securitySeverity(severity) {
28521
28603
  }
28522
28604
  }
28523
28605
  function toArtifactUri(filePath, base, prefix = "", root = base) {
28524
- const absolute = (0, import_node_path10.isAbsolute)(filePath) ? filePath : (0, import_node_path10.resolve)(root, filePath);
28525
- const relativePath = (0, import_node_path10.relative)(base, absolute);
28606
+ const absolute = (0, import_node_path11.isAbsolute)(filePath) ? filePath : (0, import_node_path11.resolve)(root, filePath);
28607
+ const relativePath = (0, import_node_path11.relative)(base, absolute);
28526
28608
  const escapedOut = relativePath.startsWith("..") || relativePath === "";
28527
28609
  const chosen = escapedOut ? absolute : relativePath;
28528
- const posix = chosen.split(import_node_path10.sep).join("/").replace(/^\.\//, "");
28610
+ const posix = chosen.split(import_node_path11.sep).join("/").replace(/^\.\//, "");
28529
28611
  if (!prefix || escapedOut) return posix;
28530
28612
  const trimmed = prefix.replace(/^\/+|\/+$/g, "");
28531
28613
  return trimmed ? `${trimmed}/${posix}` : posix;
@@ -28615,11 +28697,11 @@ ${finding.consequence}` : `**${finding.title}**`
28615
28697
  // src/commands/scan.ts
28616
28698
  function readVersion() {
28617
28699
  for (const candidate of [
28618
- (0, import_node_path11.join)(__dirname, "..", "package.json"),
28619
- (0, import_node_path11.join)(__dirname, "..", "..", "package.json")
28700
+ (0, import_node_path12.join)(__dirname, "..", "package.json"),
28701
+ (0, import_node_path12.join)(__dirname, "..", "..", "package.json")
28620
28702
  ]) {
28621
28703
  try {
28622
- return JSON.parse((0, import_node_fs13.readFileSync)(candidate, "utf-8")).version ?? "0.0.0";
28704
+ return JSON.parse((0, import_node_fs14.readFileSync)(candidate, "utf-8")).version ?? "0.0.0";
28623
28705
  } catch {
28624
28706
  }
28625
28707
  }
@@ -28686,7 +28768,7 @@ async function scanCommand(targetPath, options = {}) {
28686
28768
  const say = machineReadable ? (line) => process.stderr.write(`${line}
28687
28769
  `) : (line) => process.stdout.write(`${line}
28688
28770
  `);
28689
- if (!(0, import_node_fs13.existsSync)(targetPath)) {
28771
+ if (!(0, import_node_fs14.existsSync)(targetPath)) {
28690
28772
  say(source_default.red(`Scan target does not exist: ${targetPath}`));
28691
28773
  process.exitCode = 2;
28692
28774
  return failedResult(targetPath, `no such path: ${targetPath}`);
@@ -28782,7 +28864,7 @@ function emitMachineReadable(format, outcome, targetPath, options, say) {
28782
28864
  // and it fails silently. `--path-prefix` covers the remaining case:
28783
28865
  // a scan run from inside the subdirectory it is scanning.
28784
28866
  base: process.cwd(),
28785
- root: (0, import_node_path11.resolve)(outcome.root)
28867
+ root: (0, import_node_path12.resolve)(outcome.root)
28786
28868
  }) : {
28787
28869
  tool: "threatcrush",
28788
28870
  version: PKG_VERSION2,
@@ -28796,8 +28878,8 @@ function emitMachineReadable(format, outcome, targetPath, options, say) {
28796
28878
  const serialized = `${JSON.stringify(payload, null, 2)}
28797
28879
  `;
28798
28880
  if (options.output) {
28799
- (0, import_node_fs13.mkdirSync)((0, import_node_path11.dirname)((0, import_node_path11.resolve)(options.output)), { recursive: true });
28800
- (0, import_node_fs13.writeFileSync)(options.output, serialized, "utf-8");
28881
+ (0, import_node_fs14.mkdirSync)((0, import_node_path12.dirname)((0, import_node_path12.resolve)(options.output)), { recursive: true });
28882
+ (0, import_node_fs14.writeFileSync)(options.output, serialized, "utf-8");
28801
28883
  say(
28802
28884
  source_default.gray(
28803
28885
  ` ${format.toUpperCase()} written to ${options.output} (${outcome.findings.length} finding(s))`
@@ -28849,30 +28931,30 @@ function printHuman(outcome) {
28849
28931
  }
28850
28932
 
28851
28933
  // src/commands/init.ts
28852
- var import_node_fs15 = require("fs");
28853
- var import_node_child_process = require("child_process");
28934
+ var import_node_fs16 = require("fs");
28935
+ var import_node_child_process2 = require("child_process");
28854
28936
 
28855
28937
  // src/core/cli-config.ts
28856
- var import_node_fs14 = require("fs");
28857
- var import_node_path12 = require("path");
28858
- var import_node_os4 = require("os");
28859
- var CLI_CONFIG_DIR = (0, import_node_path12.join)((0, import_node_os4.homedir)(), ".threatcrush");
28860
- var CLI_CONFIG_PATH = (0, import_node_path12.join)(CLI_CONFIG_DIR, "config.json");
28938
+ var import_node_fs15 = require("fs");
28939
+ var import_node_path13 = require("path");
28940
+ var import_node_os5 = require("os");
28941
+ var CLI_CONFIG_DIR = (0, import_node_path13.join)((0, import_node_os5.homedir)(), ".threatcrush");
28942
+ var CLI_CONFIG_PATH = (0, import_node_path13.join)(CLI_CONFIG_DIR, "config.json");
28861
28943
  function apiUrl() {
28862
28944
  return process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
28863
28945
  }
28864
28946
  function readCliConfig() {
28865
28947
  try {
28866
- return JSON.parse((0, import_node_fs14.readFileSync)(CLI_CONFIG_PATH, "utf-8"));
28948
+ return JSON.parse((0, import_node_fs15.readFileSync)(CLI_CONFIG_PATH, "utf-8"));
28867
28949
  } catch {
28868
28950
  return {};
28869
28951
  }
28870
28952
  }
28871
28953
  function writeCliConfig(config) {
28872
- if (!(0, import_node_fs14.existsSync)(CLI_CONFIG_DIR)) (0, import_node_fs14.mkdirSync)(CLI_CONFIG_DIR, { recursive: true });
28873
- (0, import_node_fs14.writeFileSync)(CLI_CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
28954
+ if (!(0, import_node_fs15.existsSync)(CLI_CONFIG_DIR)) (0, import_node_fs15.mkdirSync)(CLI_CONFIG_DIR, { recursive: true });
28955
+ (0, import_node_fs15.writeFileSync)(CLI_CONFIG_PATH, JSON.stringify(config, null, 2), "utf-8");
28874
28956
  try {
28875
- (0, import_node_fs14.chmodSync)(CLI_CONFIG_PATH, 384);
28957
+ (0, import_node_fs15.chmodSync)(CLI_CONFIG_PATH, 384);
28876
28958
  } catch {
28877
28959
  }
28878
28960
  }
@@ -29035,13 +29117,13 @@ function ask(question, opts = {}) {
29035
29117
 
29036
29118
  // src/core/link-login.ts
29037
29119
  var import_node_crypto4 = require("crypto");
29038
- var import_node_os5 = require("os");
29120
+ var import_node_os6 = require("os");
29039
29121
  function createPkce() {
29040
29122
  const verifier = (0, import_node_crypto4.randomBytes)(32).toString("base64url");
29041
29123
  const challenge = (0, import_node_crypto4.createHash)("sha256").update(verifier).digest("base64url");
29042
29124
  return { verifier, challenge };
29043
29125
  }
29044
- async function startLinkLogin(pkce, deviceName = (0, import_node_os5.hostname)()) {
29126
+ async function startLinkLogin(pkce, deviceName = (0, import_node_os6.hostname)()) {
29045
29127
  const res = await fetch(`${apiUrl()}/api/auth/cli/start`, {
29046
29128
  method: "POST",
29047
29129
  headers: { "Content-Type": "application/json" },
@@ -29327,7 +29409,7 @@ var SERVICES_TO_DETECT = [
29327
29409
  ];
29328
29410
  function isProcessRunning(name) {
29329
29411
  try {
29330
- (0, import_node_child_process.execSync)(`pgrep -x ${name}`, { stdio: "pipe" });
29412
+ (0, import_node_child_process2.execSync)(`pgrep -x ${name}`, { stdio: "pipe" });
29331
29413
  return true;
29332
29414
  } catch {
29333
29415
  return false;
@@ -29335,14 +29417,14 @@ function isProcessRunning(name) {
29335
29417
  }
29336
29418
  function binaryExists(name) {
29337
29419
  try {
29338
- (0, import_node_child_process.execSync)(`which ${name}`, { stdio: "pipe" });
29420
+ (0, import_node_child_process2.execSync)(`which ${name}`, { stdio: "pipe" });
29339
29421
  return true;
29340
29422
  } catch {
29341
29423
  return false;
29342
29424
  }
29343
29425
  }
29344
29426
  function findLogPath(paths) {
29345
- return paths.find((p) => (0, import_node_fs15.existsSync)(p));
29427
+ return paths.find((p) => (0, import_node_fs16.existsSync)(p));
29346
29428
  }
29347
29429
  async function promptYesNo(question, fallback2) {
29348
29430
  const hint = fallback2 ? "(Y/n)" : "(y/N)";
@@ -29486,11 +29568,11 @@ async function initCommand(opts = {}) {
29486
29568
  }
29487
29569
  } else {
29488
29570
  const spinner2 = ora({ text: "Writing configuration files...", color: "green" }).start();
29489
- (0, import_node_fs15.mkdirSync)(confDDir, { recursive: true });
29490
- (0, import_node_fs15.mkdirSync)("/var/log/threatcrush", { recursive: true });
29491
- (0, import_node_fs15.mkdirSync)("/var/lib/threatcrush", { recursive: true });
29571
+ (0, import_node_fs16.mkdirSync)(confDDir, { recursive: true });
29572
+ (0, import_node_fs16.mkdirSync)("/var/log/threatcrush", { recursive: true });
29573
+ (0, import_node_fs16.mkdirSync)("/var/lib/threatcrush", { recursive: true });
29492
29574
  const mainConfig = generateDefaultConfig(detected.map((d) => d.name));
29493
- (0, import_node_fs15.writeFileSync)(`${configDir}/threatcrushd.conf`, mainConfig);
29575
+ (0, import_node_fs16.writeFileSync)(`${configDir}/threatcrushd.conf`, mainConfig);
29494
29576
  for (const svc of detected) {
29495
29577
  const svcDef = SERVICES_TO_DETECT.find((s) => s.name === svc.name);
29496
29578
  if (!svcDef) continue;
@@ -29499,7 +29581,7 @@ async function initCommand(opts = {}) {
29499
29581
  ...svcDef.moduleConfig,
29500
29582
  log_path: svc.logPath || svcDef.logPaths[0]
29501
29583
  });
29502
- (0, import_node_fs15.writeFileSync)(`${confDDir}/${modName}.conf`, modConfig);
29584
+ (0, import_node_fs16.writeFileSync)(`${confDDir}/${modName}.conf`, modConfig);
29503
29585
  }
29504
29586
  spinner2.succeed("Configuration written successfully");
29505
29587
  console.log();
@@ -29517,8 +29599,8 @@ async function initCommand(opts = {}) {
29517
29599
  }
29518
29600
  function checkWriteAccess(dir) {
29519
29601
  try {
29520
- if (!(0, import_node_fs15.existsSync)(dir)) {
29521
- (0, import_node_fs15.mkdirSync)(dir, { recursive: true });
29602
+ if (!(0, import_node_fs16.existsSync)(dir)) {
29603
+ (0, import_node_fs16.mkdirSync)(dir, { recursive: true });
29522
29604
  }
29523
29605
  return true;
29524
29606
  } catch {
@@ -29536,8 +29618,8 @@ var BUILTIN_MODULES = [
29536
29618
  ];
29537
29619
 
29538
29620
  // src/core/module-loader.ts
29539
- var import_node_fs16 = require("fs");
29540
- var import_node_path13 = require("path");
29621
+ var import_node_fs17 = require("fs");
29622
+ var import_node_path14 = require("path");
29541
29623
  var import_toml2 = __toESM(require_toml());
29542
29624
  init_paths();
29543
29625
  function discoverModules(moduleDir, confDir) {
@@ -29545,22 +29627,22 @@ function discoverModules(moduleDir, confDir) {
29545
29627
  const configs = loadModuleConfigs(confDir || PATHS.confD);
29546
29628
  const searchPaths = [
29547
29629
  moduleDir || PATHS.moduleDir,
29548
- (0, import_node_path13.resolve)(process.cwd(), "modules")
29630
+ (0, import_node_path14.resolve)(process.cwd(), "modules")
29549
29631
  ];
29550
- const builtinDir = (0, import_node_path13.resolve)(__dirname || ".", "..", "modules");
29551
- if ((0, import_node_fs16.existsSync)(builtinDir)) {
29632
+ const builtinDir = (0, import_node_path14.resolve)(__dirname || ".", "..", "modules");
29633
+ if ((0, import_node_fs17.existsSync)(builtinDir)) {
29552
29634
  searchPaths.push(builtinDir);
29553
29635
  }
29554
29636
  for (const basePath of searchPaths) {
29555
- if (!(0, import_node_fs16.existsSync)(basePath)) continue;
29556
- const entries = (0, import_node_fs16.readdirSync)(basePath, { withFileTypes: true });
29637
+ if (!(0, import_node_fs17.existsSync)(basePath)) continue;
29638
+ const entries = (0, import_node_fs17.readdirSync)(basePath, { withFileTypes: true });
29557
29639
  for (const entry of entries) {
29558
29640
  if (!entry.isDirectory()) continue;
29559
- const modPath = (0, import_node_path13.join)(basePath, entry.name);
29560
- const manifestPath = (0, import_node_path13.join)(modPath, "mod.toml");
29561
- if (!(0, import_node_fs16.existsSync)(manifestPath)) continue;
29641
+ const modPath = (0, import_node_path14.join)(basePath, entry.name);
29642
+ const manifestPath = (0, import_node_path14.join)(modPath, "mod.toml");
29643
+ if (!(0, import_node_fs17.existsSync)(manifestPath)) continue;
29562
29644
  try {
29563
- const raw = (0, import_node_fs16.readFileSync)(manifestPath, "utf-8");
29645
+ const raw = (0, import_node_fs17.readFileSync)(manifestPath, "utf-8");
29564
29646
  const manifest = import_toml2.default.parse(raw);
29565
29647
  const config = configs.get(manifest.module.name) || { enabled: true };
29566
29648
  modules.push({
@@ -29586,21 +29668,21 @@ function discoverModules(moduleDir, confDir) {
29586
29668
  init_ipc_client();
29587
29669
 
29588
29670
  // src/daemon/pidfile.ts
29589
- var import_node_fs17 = require("fs");
29671
+ var import_node_fs18 = require("fs");
29590
29672
  init_paths();
29591
29673
  function writePidFile() {
29592
29674
  ensureRuntimeDirs();
29593
- (0, import_node_fs17.writeFileSync)(PATHS.pidFile, String(process.pid), "utf-8");
29675
+ (0, import_node_fs18.writeFileSync)(PATHS.pidFile, String(process.pid), "utf-8");
29594
29676
  }
29595
29677
  function readPidFile() {
29596
- if (!(0, import_node_fs17.existsSync)(PATHS.pidFile)) return null;
29597
- const raw = (0, import_node_fs17.readFileSync)(PATHS.pidFile, "utf-8").trim();
29678
+ if (!(0, import_node_fs18.existsSync)(PATHS.pidFile)) return null;
29679
+ const raw = (0, import_node_fs18.readFileSync)(PATHS.pidFile, "utf-8").trim();
29598
29680
  const pid = parseInt(raw, 10);
29599
29681
  return Number.isFinite(pid) ? pid : null;
29600
29682
  }
29601
29683
  function removePidFile() {
29602
29684
  try {
29603
- if ((0, import_node_fs17.existsSync)(PATHS.pidFile)) (0, import_node_fs17.unlinkSync)(PATHS.pidFile);
29685
+ if ((0, import_node_fs18.existsSync)(PATHS.pidFile)) (0, import_node_fs18.unlinkSync)(PATHS.pidFile);
29604
29686
  } catch {
29605
29687
  }
29606
29688
  }
@@ -29612,7 +29694,7 @@ function procStatState(stat) {
29612
29694
  function isZombie(pid) {
29613
29695
  let stat;
29614
29696
  try {
29615
- stat = (0, import_node_fs17.readFileSync)(`/proc/${pid}/stat`, "utf-8");
29697
+ stat = (0, import_node_fs18.readFileSync)(`/proc/${pid}/stat`, "utf-8");
29616
29698
  } catch {
29617
29699
  return false;
29618
29700
  }
@@ -29737,25 +29819,25 @@ function formatUptime2(seconds) {
29737
29819
  }
29738
29820
 
29739
29821
  // src/commands/modules.ts
29740
- var import_node_child_process2 = require("child_process");
29741
- var import_node_fs19 = require("fs");
29742
- var import_node_path15 = require("path");
29822
+ var import_node_child_process3 = require("child_process");
29823
+ var import_node_fs20 = require("fs");
29824
+ var import_node_path16 = require("path");
29743
29825
  var import_toml3 = __toESM(require_toml());
29744
29826
  init_paths();
29745
29827
 
29746
29828
  // src/daemon/module-trust.ts
29747
29829
  var import_node_crypto5 = require("crypto");
29748
- var import_node_fs18 = require("fs");
29749
- var import_node_path14 = require("path");
29830
+ var import_node_fs19 = require("fs");
29831
+ var import_node_path15 = require("path");
29750
29832
  init_paths();
29751
- var TRUST_FILE = (0, import_node_path14.join)(PATHS.configDir, "trusted-modules.json");
29752
- var PUBLISHER_KEYS_FILE = (0, import_node_path14.join)(PATHS.configDir, "publisher-keys.json");
29833
+ var TRUST_FILE = (0, import_node_path15.join)(PATHS.configDir, "trusted-modules.json");
29834
+ var PUBLISHER_KEYS_FILE = (0, import_node_path15.join)(PATHS.configDir, "publisher-keys.json");
29753
29835
  var DIGEST_EXCLUDED_DIRS = /* @__PURE__ */ new Set([".git"]);
29754
29836
  function collectFiles(root, dir = root, out = []) {
29755
- for (const entry of (0, import_node_fs18.readdirSync)(dir, { withFileTypes: true }).sort(
29837
+ for (const entry of (0, import_node_fs19.readdirSync)(dir, { withFileTypes: true }).sort(
29756
29838
  (a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0
29757
29839
  )) {
29758
- const full = (0, import_node_path14.join)(dir, entry.name);
29840
+ const full = (0, import_node_path15.join)(dir, entry.name);
29759
29841
  if (entry.isSymbolicLink()) {
29760
29842
  out.push({ path: full, isSymlink: true });
29761
29843
  } else if (entry.isDirectory()) {
@@ -29770,24 +29852,24 @@ function collectFiles(root, dir = root, out = []) {
29770
29852
  function computeModuleDigest(modulePath) {
29771
29853
  const hash = (0, import_node_crypto5.createHash)("sha256");
29772
29854
  for (const entry of collectFiles(modulePath)) {
29773
- const relPath = (0, import_node_path14.relative)(modulePath, entry.path).split(import_node_path14.sep).join("/");
29855
+ const relPath = (0, import_node_path15.relative)(modulePath, entry.path).split(import_node_path15.sep).join("/");
29774
29856
  hash.update(relPath);
29775
29857
  hash.update("\0");
29776
29858
  if (entry.isSymlink) {
29777
29859
  hash.update("symlink:");
29778
- hash.update((0, import_node_fs18.readlinkSync)(entry.path));
29860
+ hash.update((0, import_node_fs19.readlinkSync)(entry.path));
29779
29861
  } else {
29780
29862
  hash.update("file:");
29781
- hash.update((0, import_node_fs18.readFileSync)(entry.path));
29863
+ hash.update((0, import_node_fs19.readFileSync)(entry.path));
29782
29864
  }
29783
29865
  hash.update("\0");
29784
29866
  }
29785
29867
  return hash.digest("hex");
29786
29868
  }
29787
29869
  function readTrustFile() {
29788
- if (!(0, import_node_fs18.existsSync)(TRUST_FILE)) return { version: 1, modules: {} };
29870
+ if (!(0, import_node_fs19.existsSync)(TRUST_FILE)) return { version: 1, modules: {} };
29789
29871
  try {
29790
- const parsed = JSON.parse((0, import_node_fs18.readFileSync)(TRUST_FILE, "utf-8"));
29872
+ const parsed = JSON.parse((0, import_node_fs19.readFileSync)(TRUST_FILE, "utf-8"));
29791
29873
  if (parsed.version !== 1 || typeof parsed.modules !== "object" || !parsed.modules) {
29792
29874
  return { version: 1, modules: {} };
29793
29875
  }
@@ -29797,9 +29879,9 @@ function readTrustFile() {
29797
29879
  }
29798
29880
  }
29799
29881
  function writeTrustFile(file) {
29800
- (0, import_node_fs18.writeFileSync)(TRUST_FILE, JSON.stringify(file, null, 2) + "\n", { mode: 384 });
29882
+ (0, import_node_fs19.writeFileSync)(TRUST_FILE, JSON.stringify(file, null, 2) + "\n", { mode: 384 });
29801
29883
  try {
29802
- (0, import_node_fs18.chmodSync)(TRUST_FILE, 384);
29884
+ (0, import_node_fs19.chmodSync)(TRUST_FILE, 384);
29803
29885
  } catch {
29804
29886
  }
29805
29887
  }
@@ -29825,9 +29907,9 @@ function listTrustedModules() {
29825
29907
  return readTrustFile().modules;
29826
29908
  }
29827
29909
  function readPublisherKeys() {
29828
- if (!(0, import_node_fs18.existsSync)(PUBLISHER_KEYS_FILE)) return {};
29910
+ if (!(0, import_node_fs19.existsSync)(PUBLISHER_KEYS_FILE)) return {};
29829
29911
  try {
29830
- const parsed = JSON.parse((0, import_node_fs18.readFileSync)(PUBLISHER_KEYS_FILE, "utf-8"));
29912
+ const parsed = JSON.parse((0, import_node_fs19.readFileSync)(PUBLISHER_KEYS_FILE, "utf-8"));
29831
29913
  return parsed && typeof parsed === "object" ? parsed : {};
29832
29914
  } catch {
29833
29915
  return {};
@@ -29836,16 +29918,16 @@ function readPublisherKeys() {
29836
29918
  function verifyModuleSignature(modulePath, digest) {
29837
29919
  const keys = readPublisherKeys();
29838
29920
  const pinnedKeyIds = Object.keys(keys);
29839
- const sigPath = (0, import_node_path14.join)(modulePath, "mod.sig");
29921
+ const sigPath = (0, import_node_path15.join)(modulePath, "mod.sig");
29840
29922
  if (pinnedKeyIds.length === 0) {
29841
29923
  return { ok: true };
29842
29924
  }
29843
- if (!(0, import_node_fs18.existsSync)(sigPath)) {
29925
+ if (!(0, import_node_fs19.existsSync)(sigPath)) {
29844
29926
  return { ok: false, reason: "publisher keys are pinned but the module ships no mod.sig" };
29845
29927
  }
29846
29928
  let parsed;
29847
29929
  try {
29848
- parsed = JSON.parse((0, import_node_fs18.readFileSync)(sigPath, "utf-8"));
29930
+ parsed = JSON.parse((0, import_node_fs19.readFileSync)(sigPath, "utf-8"));
29849
29931
  } catch {
29850
29932
  return { ok: false, reason: "mod.sig is not valid JSON" };
29851
29933
  }
@@ -29906,10 +29988,10 @@ function safeModuleDirName(name, label = "module name") {
29906
29988
  return name;
29907
29989
  }
29908
29990
  function moduleDestination(dir, name, label) {
29909
- return (0, import_node_path15.join)(dir, safeModuleDirName(name, label));
29991
+ return (0, import_node_path16.join)(dir, safeModuleDirName(name, label));
29910
29992
  }
29911
29993
  function assertSafeTarballEntries(tarPath) {
29912
- const listing = (0, import_node_child_process2.execFileSync)("tar", ["-tzf", tarPath], { encoding: "utf-8" });
29994
+ const listing = (0, import_node_child_process3.execFileSync)("tar", ["-tzf", tarPath], { encoding: "utf-8" });
29913
29995
  for (const entry of listing.split("\n").map((line) => line.trim()).filter(Boolean)) {
29914
29996
  const normalized = entry.replace(/\\/g, "/");
29915
29997
  const segments = normalized.split("/");
@@ -29919,12 +30001,12 @@ function assertSafeTarballEntries(tarPath) {
29919
30001
  }
29920
30002
  }
29921
30003
  function validateManifest(modPath) {
29922
- const manifestPath = (0, import_node_path15.join)(modPath, "mod.toml");
29923
- if (!(0, import_node_fs19.existsSync)(manifestPath)) {
30004
+ const manifestPath = (0, import_node_path16.join)(modPath, "mod.toml");
30005
+ if (!(0, import_node_fs20.existsSync)(manifestPath)) {
29924
30006
  return { ok: false, error: `mod.toml not found at ${manifestPath}` };
29925
30007
  }
29926
30008
  try {
29927
- const raw = (0, import_node_fs19.readFileSync)(manifestPath, "utf-8");
30009
+ const raw = (0, import_node_fs20.readFileSync)(manifestPath, "utf-8");
29928
30010
  const parsed = import_toml3.default.parse(raw);
29929
30011
  const name = parsed.module?.name;
29930
30012
  const version = parsed.module?.version;
@@ -29986,8 +30068,8 @@ async function modulesInstallCommand(source) {
29986
30068
  console.log();
29987
30069
  const dir = modulesDir();
29988
30070
  if (source.startsWith("./") || source.startsWith("/") || source.startsWith("~")) {
29989
- const absPath = (0, import_node_path15.resolve)(source.startsWith("~") ? source.replace("~", process.env.HOME || "") : source);
29990
- if (!(0, import_node_fs19.existsSync)(absPath)) {
30071
+ const absPath = (0, import_node_path16.resolve)(source.startsWith("~") ? source.replace("~", process.env.HOME || "") : source);
30072
+ if (!(0, import_node_fs20.existsSync)(absPath)) {
29991
30073
  console.log(source_default.red(` \u2717 Path not found: ${absPath}
29992
30074
  `));
29993
30075
  return;
@@ -30006,7 +30088,7 @@ async function modulesInstallCommand(source) {
30006
30088
  `));
30007
30089
  return;
30008
30090
  }
30009
- if ((0, import_node_fs19.existsSync)(dest2)) {
30091
+ if ((0, import_node_fs20.existsSync)(dest2)) {
30010
30092
  console.log(source_default.yellow(` ! ${check.name} is already installed at ${dest2}`));
30011
30093
  console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${check.name}`)} first.
30012
30094
  `));
@@ -30014,7 +30096,7 @@ async function modulesInstallCommand(source) {
30014
30096
  }
30015
30097
  const spinner2 = ora({ text: `Copying module files...`, color: "green" }).start();
30016
30098
  try {
30017
- (0, import_node_fs19.cpSync)(absPath, dest2, { recursive: true, dereference: true });
30099
+ (0, import_node_fs20.cpSync)(absPath, dest2, { recursive: true, dereference: true });
30018
30100
  spinner2.succeed(`Installed ${source_default.white(check.name)} v${check.version} \u2192 ${dest2}`);
30019
30101
  } catch (err) {
30020
30102
  spinner2.fail(`Copy failed: ${err.message}`);
@@ -30030,14 +30112,14 @@ async function modulesInstallCommand(source) {
30030
30112
  let name;
30031
30113
  let dest2;
30032
30114
  try {
30033
- name = safeModuleDirName((0, import_node_path15.basename)(gitUrl.replace(/\.git$/, "")), "repository name");
30115
+ name = safeModuleDirName((0, import_node_path16.basename)(gitUrl.replace(/\.git$/, "")), "repository name");
30034
30116
  dest2 = moduleDestination(dir, name);
30035
30117
  } catch (err) {
30036
30118
  console.log(source_default.red(` x ${err.message}
30037
30119
  `));
30038
30120
  return;
30039
30121
  }
30040
- if ((0, import_node_fs19.existsSync)(dest2)) {
30122
+ if ((0, import_node_fs20.existsSync)(dest2)) {
30041
30123
  console.log(source_default.yellow(` ! ${name} is already installed at ${dest2}`));
30042
30124
  console.log(source_default.dim(` Run ${source_default.white(`threatcrush modules remove ${name}`)} first.
30043
30125
  `));
@@ -30045,7 +30127,7 @@ async function modulesInstallCommand(source) {
30045
30127
  }
30046
30128
  const spinner2 = ora({ text: `Cloning ${gitUrl}...`, color: "green" }).start();
30047
30129
  try {
30048
- (0, import_node_child_process2.execFileSync)("git", ["clone", "--depth", "1", "--", gitUrl, dest2], { stdio: "pipe" });
30130
+ (0, import_node_child_process3.execFileSync)("git", ["clone", "--depth", "1", "--", gitUrl, dest2], { stdio: "pipe" });
30049
30131
  } catch (err) {
30050
30132
  spinner2.fail(`Clone failed: ${err.message}`);
30051
30133
  return;
@@ -30054,7 +30136,7 @@ async function modulesInstallCommand(source) {
30054
30136
  if (!check.ok) {
30055
30137
  spinner2.fail(check.error);
30056
30138
  try {
30057
- (0, import_node_fs19.rmSync)(dest2, { recursive: true, force: true });
30139
+ (0, import_node_fs20.rmSync)(dest2, { recursive: true, force: true });
30058
30140
  } catch {
30059
30141
  }
30060
30142
  return;
@@ -30101,7 +30183,7 @@ async function modulesInstallCommand(source) {
30101
30183
  `));
30102
30184
  return;
30103
30185
  }
30104
- if ((0, import_node_fs19.existsSync)(dest)) {
30186
+ if ((0, import_node_fs20.existsSync)(dest)) {
30105
30187
  console.log(source_default.yellow(` ! ${mod.slug} is already installed at ${dest}
30106
30188
  `));
30107
30189
  return;
@@ -30109,7 +30191,7 @@ async function modulesInstallCommand(source) {
30109
30191
  if (install.npm_package) {
30110
30192
  const npmSpinner = ora({ text: `Installing ${install.npm_package}...`, color: "green" }).start();
30111
30193
  try {
30112
- (0, import_node_child_process2.execFileSync)("npm", ["install", "-g", "--", install.npm_package], { stdio: "pipe" });
30194
+ (0, import_node_child_process3.execFileSync)("npm", ["install", "-g", "--", install.npm_package], { stdio: "pipe" });
30113
30195
  npmSpinner.succeed(`Package ${install.npm_package} installed globally`);
30114
30196
  } catch (err) {
30115
30197
  npmSpinner.fail(`npm install failed: ${err.message}`);
@@ -30118,7 +30200,7 @@ async function modulesInstallCommand(source) {
30118
30200
  } else if (install.git_url) {
30119
30201
  const cloneSpinner = ora({ text: "Cloning module repository...", color: "green" }).start();
30120
30202
  try {
30121
- (0, import_node_child_process2.execFileSync)("git", ["clone", "--depth", "1", "--", install.git_url, dest], { stdio: "pipe" });
30203
+ (0, import_node_child_process3.execFileSync)("git", ["clone", "--depth", "1", "--", install.git_url, dest], { stdio: "pipe" });
30122
30204
  } catch (err) {
30123
30205
  cloneSpinner.fail(`Clone failed: ${err.message}`);
30124
30206
  return;
@@ -30127,7 +30209,7 @@ async function modulesInstallCommand(source) {
30127
30209
  if (!check.ok) {
30128
30210
  cloneSpinner.fail(check.error);
30129
30211
  try {
30130
- (0, import_node_fs19.rmSync)(dest, { recursive: true, force: true });
30212
+ (0, import_node_fs20.rmSync)(dest, { recursive: true, force: true });
30131
30213
  } catch {
30132
30214
  }
30133
30215
  return;
@@ -30141,11 +30223,11 @@ async function modulesInstallCommand(source) {
30141
30223
  dlSpinner.fail(`HTTP ${res.status}`);
30142
30224
  return;
30143
30225
  }
30144
- const tar = (0, import_node_path15.join)(dir, `${mod.slug}.tar.gz`);
30145
- (0, import_node_fs19.writeFileSync)(tar, Buffer.from(await res.arrayBuffer()));
30226
+ const tar = (0, import_node_path16.join)(dir, `${mod.slug}.tar.gz`);
30227
+ (0, import_node_fs20.writeFileSync)(tar, Buffer.from(await res.arrayBuffer()));
30146
30228
  assertSafeTarballEntries(tar);
30147
- (0, import_node_child_process2.execFileSync)("tar", ["-xzf", tar, "-C", dir], { stdio: "pipe" });
30148
- (0, import_node_fs19.rmSync)(tar, { force: true });
30229
+ (0, import_node_child_process3.execFileSync)("tar", ["-xzf", tar, "-C", dir], { stdio: "pipe" });
30230
+ (0, import_node_fs20.rmSync)(tar, { force: true });
30149
30231
  const check = validateManifest(dest);
30150
30232
  if (!check.ok) {
30151
30233
  dlSpinner.fail(check.error);
@@ -30177,7 +30259,7 @@ async function modulesRemoveCommand(name) {
30177
30259
  `));
30178
30260
  return;
30179
30261
  }
30180
- if (!(0, import_node_fs19.existsSync)(target)) {
30262
+ if (!(0, import_node_fs20.existsSync)(target)) {
30181
30263
  console.log(source_default.yellow(` ! No module named "${name}" in ${dir}
30182
30264
  `));
30183
30265
  return;
@@ -30187,7 +30269,7 @@ async function modulesRemoveCommand(name) {
30187
30269
  console.log(source_default.yellow(` ! Directory name "${name}" does not match manifest name "${check.name}"`));
30188
30270
  }
30189
30271
  try {
30190
- (0, import_node_fs19.rmSync)(target, { recursive: true, force: true });
30272
+ (0, import_node_fs20.rmSync)(target, { recursive: true, force: true });
30191
30273
  untrustModule(name);
30192
30274
  console.log(source_default.green(` \u2713 Removed ${name} from ${dir}
30193
30275
  `));
@@ -30212,7 +30294,7 @@ async function modulesTrustCommand(name) {
30212
30294
  `));
30213
30295
  return;
30214
30296
  }
30215
- if (!(0, import_node_fs19.existsSync)(target)) {
30297
+ if (!(0, import_node_fs20.existsSync)(target)) {
30216
30298
  console.log(source_default.yellow(` ! No module named "${name}" in ${dir}
30217
30299
  `));
30218
30300
  return;
@@ -30647,7 +30729,7 @@ async function pentestCommand(targetUrl) {
30647
30729
  }
30648
30730
 
30649
30731
  // src/commands/ai-scan.ts
30650
- var import_node_fs20 = require("fs");
30732
+ var import_node_fs21 = require("fs");
30651
30733
 
30652
30734
  // src/aiscan/probes.ts
30653
30735
  function makeCanary() {
@@ -30924,7 +31006,7 @@ async function aiScanMoshCommand(file, args) {
30924
31006
  console.log();
30925
31007
  let source;
30926
31008
  try {
30927
- source = (0, import_node_fs20.readFileSync)(file, "utf-8");
31009
+ source = (0, import_node_fs21.readFileSync)(file, "utf-8");
30928
31010
  } catch (err) {
30929
31011
  logger.error(`Cannot read ${file}: ${err.message}`);
30930
31012
  process.exitCode = 1;
@@ -30944,22 +31026,22 @@ async function aiScanMoshCommand(file, args) {
30944
31026
  }
30945
31027
 
30946
31028
  // src/commands/orgs.ts
30947
- var import_node_os6 = require("os");
30948
- var import_node_fs21 = require("fs");
30949
- var import_node_path16 = require("path");
31029
+ var import_node_os7 = require("os");
31030
+ var import_node_fs22 = require("fs");
31031
+ var import_node_path17 = require("path");
30950
31032
  var API_URL3 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
30951
- var CONFIG_PATH = (0, import_node_path16.join)((0, import_node_os6.homedir)(), ".threatcrush", "config.json");
31033
+ var CONFIG_PATH = (0, import_node_path17.join)((0, import_node_os7.homedir)(), ".threatcrush", "config.json");
30952
31034
  function readConfig() {
30953
31035
  try {
30954
- return JSON.parse((0, import_node_fs21.readFileSync)(CONFIG_PATH, "utf-8"));
31036
+ return JSON.parse((0, import_node_fs22.readFileSync)(CONFIG_PATH, "utf-8"));
30955
31037
  } catch {
30956
31038
  return {};
30957
31039
  }
30958
31040
  }
30959
31041
  function writeConfig(config) {
30960
- const dir = (0, import_node_path16.join)((0, import_node_os6.homedir)(), ".threatcrush");
30961
- if (!(0, import_node_fs21.existsSync)(dir)) (0, import_node_fs21.mkdirSync)(dir, { recursive: true });
30962
- (0, import_node_fs21.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2));
31042
+ const dir = (0, import_node_path17.join)((0, import_node_os7.homedir)(), ".threatcrush");
31043
+ if (!(0, import_node_fs22.existsSync)(dir)) (0, import_node_fs22.mkdirSync)(dir, { recursive: true });
31044
+ (0, import_node_fs22.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2));
30963
31045
  }
30964
31046
  function getAuthHeaders() {
30965
31047
  const config = readConfig();
@@ -31095,7 +31177,7 @@ async function useOrganization(slug) {
31095
31177
 
31096
31178
  // src/commands/servers.ts
31097
31179
  var import_node_readline2 = __toESM(require("readline"));
31098
- var import_node_os7 = require("os");
31180
+ var import_node_os8 = require("os");
31099
31181
  async function serversCommand(options) {
31100
31182
  const { action, name, org } = options;
31101
31183
  if (action === "list" || !action) {
@@ -31187,7 +31269,7 @@ async function chooseOrg(orgs, flag, ask2) {
31187
31269
  async function linkServer(opts = {}, ask2 = askChoice) {
31188
31270
  if (!hasSession()) throw new Error("Not logged in. Run: threatcrush login");
31189
31271
  const org = await chooseOrg(await fetchOrgs(), opts.org, ask2);
31190
- const host = opts.hostname ?? (0, import_node_os7.hostname)();
31272
+ const host = opts.hostname ?? (0, import_node_os8.hostname)();
31191
31273
  const listRes = await cloudFetch(`/api/orgs/${org.id}/servers`);
31192
31274
  if (!listRes.ok) throw new Error(`Failed to list servers in /${org.slug} (${listRes.status})`);
31193
31275
  const { servers = [] } = await listRes.json();
@@ -31303,15 +31385,15 @@ function timeAgo(dateStr) {
31303
31385
  }
31304
31386
 
31305
31387
  // src/commands/connect.ts
31306
- var import_node_os8 = require("os");
31307
- var import_node_fs22 = require("fs");
31308
- var import_node_path17 = require("path");
31309
- var import_node_child_process3 = require("child_process");
31388
+ var import_node_os9 = require("os");
31389
+ var import_node_fs23 = require("fs");
31390
+ var import_node_path18 = require("path");
31391
+ var import_node_child_process4 = require("child_process");
31310
31392
  var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
31311
- var CONFIG_PATH2 = (0, import_node_path17.join)((0, import_node_os8.homedir)(), ".threatcrush", "config.json");
31393
+ var CONFIG_PATH2 = (0, import_node_path18.join)((0, import_node_os9.homedir)(), ".threatcrush", "config.json");
31312
31394
  function readConfig2() {
31313
31395
  try {
31314
- return JSON.parse((0, import_node_fs22.readFileSync)(CONFIG_PATH2, "utf-8"));
31396
+ return JSON.parse((0, import_node_fs23.readFileSync)(CONFIG_PATH2, "utf-8"));
31315
31397
  } catch {
31316
31398
  return {};
31317
31399
  }
@@ -31447,7 +31529,7 @@ async function sshConnect(options) {
31447
31529
  sshArgs.push("-i", identity);
31448
31530
  }
31449
31531
  sshArgs.push(`${user}@${hostname3}`);
31450
- const ssh = (0, import_node_child_process3.spawn)("ssh", sshArgs, { stdio: "inherit" });
31532
+ const ssh = (0, import_node_child_process4.spawn)("ssh", sshArgs, { stdio: "inherit" });
31451
31533
  ssh.on("error", (err) => {
31452
31534
  console.log(source_default.red(`
31453
31535
  SSH error: ${err.message}
@@ -31465,22 +31547,22 @@ async function sshConnect(options) {
31465
31547
  }
31466
31548
 
31467
31549
  // src/commands/daemon.ts
31468
- var import_node_child_process11 = require("child_process");
31469
- var import_node_fs34 = require("fs");
31470
- var import_node_path24 = require("path");
31550
+ var import_node_child_process12 = require("child_process");
31471
31551
  var import_node_fs35 = require("fs");
31552
+ var import_node_path25 = require("path");
31553
+ var import_node_fs36 = require("fs");
31472
31554
 
31473
31555
  // src/daemon/index.ts
31474
- var import_node_fs33 = require("fs");
31475
- var import_node_child_process10 = require("child_process");
31476
- var import_node_os9 = require("os");
31477
- var import_node_path23 = require("path");
31556
+ var import_node_fs34 = require("fs");
31557
+ var import_node_child_process11 = require("child_process");
31558
+ var import_node_os10 = require("os");
31559
+ var import_node_path24 = require("path");
31478
31560
  var import_node_util = require("util");
31479
31561
  init_paths();
31480
31562
 
31481
31563
  // src/daemon/ipc-server.ts
31482
31564
  var import_node_net2 = require("net");
31483
- var import_node_fs23 = require("fs");
31565
+ var import_node_fs24 = require("fs");
31484
31566
  init_paths();
31485
31567
  init_control_token();
31486
31568
 
@@ -31534,9 +31616,9 @@ var IpcServer = class {
31534
31616
  controlToken = "";
31535
31617
  async start() {
31536
31618
  this.controlToken = issueControlToken();
31537
- if ((0, import_node_fs23.existsSync)(PATHS.socket)) {
31619
+ if ((0, import_node_fs24.existsSync)(PATHS.socket)) {
31538
31620
  try {
31539
- (0, import_node_fs23.unlinkSync)(PATHS.socket);
31621
+ (0, import_node_fs24.unlinkSync)(PATHS.socket);
31540
31622
  } catch {
31541
31623
  }
31542
31624
  }
@@ -31572,14 +31654,14 @@ var IpcServer = class {
31572
31654
  return new Promise((resolve6) => {
31573
31655
  if (!this.server) {
31574
31656
  try {
31575
- if ((0, import_node_fs23.existsSync)(PATHS.socket)) (0, import_node_fs23.unlinkSync)(PATHS.socket);
31657
+ if ((0, import_node_fs24.existsSync)(PATHS.socket)) (0, import_node_fs24.unlinkSync)(PATHS.socket);
31576
31658
  } catch {
31577
31659
  }
31578
31660
  return resolve6();
31579
31661
  }
31580
31662
  this.server.close(() => {
31581
31663
  try {
31582
- if ((0, import_node_fs23.existsSync)(PATHS.socket)) (0, import_node_fs23.unlinkSync)(PATHS.socket);
31664
+ if ((0, import_node_fs24.existsSync)(PATHS.socket)) (0, import_node_fs24.unlinkSync)(PATHS.socket);
31583
31665
  } catch {
31584
31666
  }
31585
31667
  resolve6();
@@ -31761,14 +31843,14 @@ var IpcServer = class {
31761
31843
  };
31762
31844
 
31763
31845
  // src/daemon/module-host.ts
31764
- var import_node_fs27 = require("fs");
31765
- var import_node_path18 = require("path");
31846
+ var import_node_fs28 = require("fs");
31847
+ var import_node_path19 = require("path");
31766
31848
  var import_node_url = require("url");
31767
31849
  var import_toml4 = __toESM(require_toml());
31768
31850
  init_paths();
31769
31851
 
31770
31852
  // src/daemon/watchers/log-watcher.ts
31771
- var import_node_fs24 = require("fs");
31853
+ var import_node_fs25 = require("fs");
31772
31854
  var DEFAULT_SOURCES = [
31773
31855
  { path: "/var/log/auth.log", module: "ssh-guard", category: "auth" },
31774
31856
  { path: "/var/log/secure", module: "ssh-guard", category: "auth" },
@@ -31788,9 +31870,9 @@ var LogWatcher = class {
31788
31870
  start() {
31789
31871
  const started = [];
31790
31872
  for (const src of this.sources) {
31791
- if (!(0, import_node_fs24.existsSync)(src.path)) continue;
31873
+ if (!(0, import_node_fs25.existsSync)(src.path)) continue;
31792
31874
  try {
31793
- (0, import_node_fs24.accessSync)(src.path, import_node_fs24.constants.R_OK);
31875
+ (0, import_node_fs25.accessSync)(src.path, import_node_fs25.constants.R_OK);
31794
31876
  } catch {
31795
31877
  continue;
31796
31878
  }
@@ -31906,7 +31988,7 @@ var LogWatcher = class {
31906
31988
  };
31907
31989
 
31908
31990
  // src/daemon/watchers/journal-watcher.ts
31909
- var import_node_child_process4 = require("child_process");
31991
+ var import_node_child_process5 = require("child_process");
31910
31992
  var SSHD_COMMS = ["sshd", "sshd-session"];
31911
31993
  function isSshdRecord(entry) {
31912
31994
  return entry._UID === "0" && SSHD_COMMS.includes(entry._COMM);
@@ -31945,14 +32027,14 @@ var JournalWatcher = class _JournalWatcher {
31945
32027
  return isRoot4 ? [] : ["--user"];
31946
32028
  }
31947
32029
  static isAvailable() {
31948
- const probe = (0, import_node_child_process4.spawnSync)("journalctl", [...this.scopeArgs(), "-n", "0", "--no-pager"], {
32030
+ const probe = (0, import_node_child_process5.spawnSync)("journalctl", [...this.scopeArgs(), "-n", "0", "--no-pager"], {
31949
32031
  stdio: ["ignore", "ignore", "ignore"]
31950
32032
  });
31951
32033
  return probe.status === 0;
31952
32034
  }
31953
32035
  start() {
31954
32036
  if (!_JournalWatcher.isAvailable()) return false;
31955
- const child = (0, import_node_child_process4.spawn)(
32037
+ const child = (0, import_node_child_process5.spawn)(
31956
32038
  "journalctl",
31957
32039
  [..._JournalWatcher.scopeArgs(), "-o", "json", "-f", "--since", "now"],
31958
32040
  { stdio: ["ignore", "pipe", "pipe"] }
@@ -31977,14 +32059,14 @@ var JournalWatcher = class _JournalWatcher {
31977
32059
  * nothing and looking like protection.
31978
32060
  */
31979
32061
  startSshd() {
31980
- const probe = (0, import_node_child_process4.spawnSync)("journalctl", ["-q", "-n", "1", "-o", "cat", "--no-pager", "_UID=0"], {
32062
+ const probe = (0, import_node_child_process5.spawnSync)("journalctl", ["-q", "-n", "1", "-o", "cat", "--no-pager", "_UID=0"], {
31981
32063
  stdio: ["ignore", "pipe", "ignore"],
31982
32064
  encoding: "utf-8"
31983
32065
  });
31984
32066
  if (probe.error || probe.status !== 0) return "unavailable";
31985
32067
  if (!probe.stdout.trim()) return "unreadable";
31986
32068
  const matches2 = ["_UID=0", ...SSHD_COMMS.map((comm) => `_COMM=${comm}`)];
31987
- const child = (0, import_node_child_process4.spawn)("journalctl", ["-o", "json", "-f", "--since", "now", ...matches2], {
32069
+ const child = (0, import_node_child_process5.spawn)("journalctl", ["-o", "json", "-f", "--since", "now", ...matches2], {
31988
32070
  stdio: ["ignore", "pipe", "ignore"]
31989
32071
  });
31990
32072
  if (!child.stdout) return "unavailable";
@@ -32086,8 +32168,8 @@ function realtimeToDate(rt) {
32086
32168
  }
32087
32169
 
32088
32170
  // src/modules/network-monitor/index.ts
32089
- var import_node_child_process5 = require("child_process");
32090
- var import_node_fs25 = require("fs");
32171
+ var import_node_child_process6 = require("child_process");
32172
+ var import_node_fs26 = require("fs");
32091
32173
  var NetworkMonitor = class {
32092
32174
  constructor(bus2) {
32093
32175
  this.bus = bus2;
@@ -32149,9 +32231,9 @@ var NetworkMonitor = class {
32149
32231
  return this.active;
32150
32232
  }
32151
32233
  hasConntrackOrSs() {
32152
- const ss = (0, import_node_child_process5.spawnSync)("ss", ["--version"], { stdio: "pipe" });
32234
+ const ss = (0, import_node_child_process6.spawnSync)("ss", ["--version"], { stdio: "pipe" });
32153
32235
  if (ss.status === 0) return true;
32154
- return (0, import_node_fs25.existsSync)("/proc/net/tcp");
32236
+ return (0, import_node_fs26.existsSync)("/proc/net/tcp");
32155
32237
  }
32156
32238
  /**
32157
32239
  * The TCP ports this host actually listens on.
@@ -32166,7 +32248,7 @@ var NetworkMonitor = class {
32166
32248
  listeningPorts() {
32167
32249
  const ports = /* @__PURE__ */ new Set();
32168
32250
  try {
32169
- const out = (0, import_node_child_process5.spawnSync)("ss", ["-ltnH"], { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"], timeout: 3e3 });
32251
+ const out = (0, import_node_child_process6.spawnSync)("ss", ["-ltnH"], { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"], timeout: 3e3 });
32170
32252
  if (out.status === 0 && out.stdout) {
32171
32253
  for (const line of out.stdout.split("\n")) {
32172
32254
  const parts = line.trim().split(/\s+/);
@@ -32197,7 +32279,7 @@ var NetworkMonitor = class {
32197
32279
  const listening = this.listeningPorts();
32198
32280
  if (listening.size === 0) return records;
32199
32281
  try {
32200
- const ct = (0, import_node_child_process5.spawnSync)("conntrack", ["-L", "-p", "tcp", "-o", "extended"], {
32282
+ const ct = (0, import_node_child_process6.spawnSync)("conntrack", ["-L", "-p", "tcp", "-o", "extended"], {
32201
32283
  encoding: "utf-8",
32202
32284
  stdio: ["pipe", "pipe", "pipe"],
32203
32285
  timeout: 3e3
@@ -32217,7 +32299,7 @@ var NetworkMonitor = class {
32217
32299
  } catch {
32218
32300
  }
32219
32301
  try {
32220
- const ss = (0, import_node_child_process5.spawnSync)("ss", ["-tnp", "-H"], {
32302
+ const ss = (0, import_node_child_process6.spawnSync)("ss", ["-tnp", "-H"], {
32221
32303
  encoding: "utf-8",
32222
32304
  stdio: ["pipe", "pipe", "pipe"],
32223
32305
  timeout: 3e3
@@ -32281,7 +32363,7 @@ var NetworkMonitor = class {
32281
32363
  }
32282
32364
  analyzeSynFlood(connections) {
32283
32365
  try {
32284
- const ss = (0, import_node_child_process5.spawnSync)("ss", ["-tn", "state", "syn-recv", "-H"], {
32366
+ const ss = (0, import_node_child_process6.spawnSync)("ss", ["-tn", "state", "syn-recv", "-H"], {
32285
32367
  encoding: "utf-8",
32286
32368
  stdio: ["pipe", "pipe", "pipe"],
32287
32369
  timeout: 3e3
@@ -32338,8 +32420,8 @@ var NetworkMonitor = class {
32338
32420
  };
32339
32421
 
32340
32422
  // src/modules/dns-monitor/index.ts
32341
- var import_node_fs26 = require("fs");
32342
- var import_node_child_process6 = require("child_process");
32423
+ var import_node_fs27 = require("fs");
32424
+ var import_node_child_process7 = require("child_process");
32343
32425
  var import_node_readline3 = require("readline");
32344
32426
  var DNS_LOG_SOURCES = [
32345
32427
  "/var/log/syslog",
@@ -32408,7 +32490,7 @@ var DnsMonitor = class {
32408
32490
  /** True if a systemd unit is loaded on this host (so we do not tail nothing). */
32409
32491
  unitExists(unit) {
32410
32492
  try {
32411
- const r = (0, import_node_child_process6.spawnSync)("systemctl", ["show", unit, "--property=LoadState", "--value"], {
32493
+ const r = (0, import_node_child_process7.spawnSync)("systemctl", ["show", unit, "--property=LoadState", "--value"], {
32412
32494
  encoding: "utf-8",
32413
32495
  stdio: ["ignore", "pipe", "ignore"],
32414
32496
  timeout: 3e3
@@ -32420,9 +32502,9 @@ var DnsMonitor = class {
32420
32502
  }
32421
32503
  start() {
32422
32504
  const sources = [...DNS_LOG_SOURCES, ...this.extraPaths].filter((p) => {
32423
- if (!(0, import_node_fs26.existsSync)(p)) return false;
32505
+ if (!(0, import_node_fs27.existsSync)(p)) return false;
32424
32506
  try {
32425
- (0, import_node_fs26.accessSync)(p, import_node_fs26.constants.R_OK);
32507
+ (0, import_node_fs27.accessSync)(p, import_node_fs27.constants.R_OK);
32426
32508
  return true;
32427
32509
  } catch {
32428
32510
  return false;
@@ -32481,7 +32563,7 @@ var DnsMonitor = class {
32481
32563
  /** Follow one systemd unit's journal, feeding its lines to the same parser. */
32482
32564
  tailJournalUnit(unit) {
32483
32565
  try {
32484
- const child = (0, import_node_child_process6.spawn)("journalctl", ["-u", unit, "-f", "-n", "0", "--output=cat"], {
32566
+ const child = (0, import_node_child_process7.spawn)("journalctl", ["-u", unit, "-f", "-n", "0", "--output=cat"], {
32485
32567
  stdio: ["ignore", "pipe", "ignore"]
32486
32568
  });
32487
32569
  if (!child.stdout) return;
@@ -32755,15 +32837,15 @@ var ModuleHost = class {
32755
32837
  }
32756
32838
  }
32757
32839
  async discoverAndStartInstalled() {
32758
- if (!(0, import_node_fs27.existsSync)(PATHS.moduleDir)) return;
32840
+ if (!(0, import_node_fs28.existsSync)(PATHS.moduleDir)) return;
32759
32841
  const configs = loadModuleConfigs(PATHS.confD);
32760
- const entries = (0, import_node_fs27.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
32842
+ const entries = (0, import_node_fs28.readdirSync)(PATHS.moduleDir, { withFileTypes: true });
32761
32843
  for (const entry of entries) {
32762
32844
  if (!entry.isDirectory()) continue;
32763
- const manifestPath = (0, import_node_path18.join)(PATHS.moduleDir, entry.name, "mod.toml");
32764
- if (!(0, import_node_fs27.existsSync)(manifestPath)) continue;
32845
+ const manifestPath = (0, import_node_path19.join)(PATHS.moduleDir, entry.name, "mod.toml");
32846
+ if (!(0, import_node_fs28.existsSync)(manifestPath)) continue;
32765
32847
  try {
32766
- const manifest = import_toml4.default.parse((0, import_node_fs27.readFileSync)(manifestPath, "utf-8"));
32848
+ const manifest = import_toml4.default.parse((0, import_node_fs28.readFileSync)(manifestPath, "utf-8"));
32767
32849
  const name = manifest.module?.name || entry.name;
32768
32850
  const defaults = manifest.module?.config?.defaults || {};
32769
32851
  const config = {
@@ -32777,7 +32859,7 @@ var ModuleHost = class {
32777
32859
  source: "installed",
32778
32860
  status: config.enabled === false ? "disabled" : "loaded",
32779
32861
  events: 0,
32780
- path: (0, import_node_path18.join)(PATHS.moduleDir, entry.name),
32862
+ path: (0, import_node_path19.join)(PATHS.moduleDir, entry.name),
32781
32863
  config
32782
32864
  };
32783
32865
  this.modules.set(name, hosted);
@@ -32792,7 +32874,7 @@ var ModuleHost = class {
32792
32874
  status: "error",
32793
32875
  events: 0,
32794
32876
  detail: `manifest load failed: ${String(err.message || err)}`,
32795
- path: (0, import_node_path18.join)(PATHS.moduleDir, entry.name)
32877
+ path: (0, import_node_path19.join)(PATHS.moduleDir, entry.name)
32796
32878
  });
32797
32879
  }
32798
32880
  }
@@ -32831,17 +32913,17 @@ var ModuleHost = class {
32831
32913
  }
32832
32914
  }
32833
32915
  installedEntrypoint(modulePath) {
32834
- const packageJson = (0, import_node_path18.join)(modulePath, "package.json");
32916
+ const packageJson = (0, import_node_path19.join)(modulePath, "package.json");
32835
32917
  const candidates = [];
32836
- if ((0, import_node_fs27.existsSync)(packageJson)) {
32918
+ if ((0, import_node_fs28.existsSync)(packageJson)) {
32837
32919
  try {
32838
- const pkg = JSON.parse((0, import_node_fs27.readFileSync)(packageJson, "utf-8"));
32839
- if (pkg.main) candidates.push((0, import_node_path18.join)(modulePath, pkg.main));
32920
+ const pkg = JSON.parse((0, import_node_fs28.readFileSync)(packageJson, "utf-8"));
32921
+ if (pkg.main) candidates.push((0, import_node_path19.join)(modulePath, pkg.main));
32840
32922
  } catch {
32841
32923
  }
32842
32924
  }
32843
- candidates.push((0, import_node_path18.join)(modulePath, "dist", "index.js"), (0, import_node_path18.join)(modulePath, "index.js"));
32844
- return candidates.find((candidate) => (0, import_node_fs27.existsSync)(candidate)) || null;
32925
+ candidates.push((0, import_node_path19.join)(modulePath, "dist", "index.js"), (0, import_node_path19.join)(modulePath, "index.js"));
32926
+ return candidates.find((candidate) => (0, import_node_fs28.existsSync)(candidate)) || null;
32845
32927
  }
32846
32928
  isThreatCrushModule(value) {
32847
32929
  return Boolean(
@@ -33344,16 +33426,16 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
33344
33426
  }
33345
33427
 
33346
33428
  // src/daemon/workers/cloud-spool.ts
33347
- var import_node_fs28 = require("fs");
33429
+ var import_node_fs29 = require("fs");
33348
33430
  var import_promises = require("fs/promises");
33349
- var import_node_path19 = require("path");
33431
+ var import_node_path20 = require("path");
33350
33432
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
33351
33433
  var CloudSpool = class {
33352
33434
  constructor(path, limits = DEFAULT_SPOOL_LIMITS) {
33353
33435
  this.path = path;
33354
33436
  this.limits = limits;
33355
33437
  try {
33356
- (0, import_node_fs28.mkdirSync)((0, import_node_path19.dirname)(path), { recursive: true });
33438
+ (0, import_node_fs29.mkdirSync)((0, import_node_path20.dirname)(path), { recursive: true });
33357
33439
  } catch {
33358
33440
  }
33359
33441
  this.load();
@@ -33422,7 +33504,7 @@ var CloudSpool = class {
33422
33504
  load() {
33423
33505
  let raw;
33424
33506
  try {
33425
- raw = (0, import_node_fs28.readFileSync)(this.path, "utf-8");
33507
+ raw = (0, import_node_fs29.readFileSync)(this.path, "utf-8");
33426
33508
  } catch {
33427
33509
  return;
33428
33510
  }
@@ -33663,7 +33745,7 @@ var CloudSync = class {
33663
33745
  var import_node_net6 = require("net");
33664
33746
 
33665
33747
  // src/daemon/firewall/protected.ts
33666
- var import_node_child_process7 = require("child_process");
33748
+ var import_node_child_process8 = require("child_process");
33667
33749
  var import_node_net4 = require("net");
33668
33750
  var DEFAULT_PROTECTED = [
33669
33751
  "127.0.0.0/8",
@@ -33759,7 +33841,7 @@ function currentSshClient(env2 = process.env) {
33759
33841
  function establishedSshPeers() {
33760
33842
  const peers = /* @__PURE__ */ new Set();
33761
33843
  try {
33762
- const out = (0, import_node_child_process7.execFileSync)("ss", ["-tnpH"], {
33844
+ const out = (0, import_node_child_process8.execFileSync)("ss", ["-tnpH"], {
33763
33845
  encoding: "utf-8",
33764
33846
  stdio: ["ignore", "pipe", "ignore"],
33765
33847
  timeout: 3e3
@@ -33780,7 +33862,7 @@ function defaultGateways() {
33780
33862
  const found = /* @__PURE__ */ new Set();
33781
33863
  for (const args of [["-4", "route", "show", "default"], ["-6", "route", "show", "default"]]) {
33782
33864
  try {
33783
- const out = (0, import_node_child_process7.execFileSync)("ip", args, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
33865
+ const out = (0, import_node_child_process8.execFileSync)("ip", args, { encoding: "utf-8", stdio: ["ignore", "pipe", "ignore"] });
33784
33866
  for (const line of out.split("\n")) {
33785
33867
  const match = line.match(/\bvia\s+(\S+)/);
33786
33868
  if (match && (0, import_node_net4.isIP)(match[1])) found.add(match[1]);
@@ -34167,8 +34249,8 @@ var RuleEngine = class {
34167
34249
  };
34168
34250
 
34169
34251
  // src/daemon/rules/loader.ts
34170
- var import_node_fs29 = require("fs");
34171
- var import_node_path20 = require("path");
34252
+ var import_node_fs30 = require("fs");
34253
+ var import_node_path21 = require("path");
34172
34254
 
34173
34255
  // src/daemon/rules/default-rules.ts
34174
34256
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
@@ -34569,11 +34651,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
34569
34651
  function loadAllRules(customDir) {
34570
34652
  const rules = [...DEFAULT_RULES];
34571
34653
  const dir = customDir || RULES_DIR;
34572
- if ((0, import_node_fs29.existsSync)(dir)) {
34573
- const files = (0, import_node_fs29.readdirSync)(dir).filter((f) => f.endsWith(".json"));
34654
+ if ((0, import_node_fs30.existsSync)(dir)) {
34655
+ const files = (0, import_node_fs30.readdirSync)(dir).filter((f) => f.endsWith(".json"));
34574
34656
  for (const file of files) {
34575
34657
  try {
34576
- const raw = (0, import_node_fs29.readFileSync)((0, import_node_path20.join)(dir, file), "utf-8");
34658
+ const raw = (0, import_node_fs30.readFileSync)((0, import_node_path21.join)(dir, file), "utf-8");
34577
34659
  const parsed = JSON.parse(raw);
34578
34660
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
34579
34661
  for (const rule of customRules) {
@@ -34604,9 +34686,9 @@ function loadAllRules(customDir) {
34604
34686
  }
34605
34687
 
34606
34688
  // src/daemon/firewall/adapters.ts
34607
- var import_node_child_process8 = require("child_process");
34608
- var import_node_fs30 = require("fs");
34609
- var import_node_path21 = require("path");
34689
+ var import_node_child_process9 = require("child_process");
34690
+ var import_node_fs31 = require("fs");
34691
+ var import_node_path22 = require("path");
34610
34692
  var import_node_net7 = require("net");
34611
34693
  function assertValidFirewallIp(ip) {
34612
34694
  if ((0, import_node_net7.isIP)(ip) !== 4) {
@@ -34619,9 +34701,9 @@ function assertBannableIp(ip) {
34619
34701
  }
34620
34702
  }
34621
34703
  function writeIfAbsent(path, contents) {
34622
- (0, import_node_fs30.mkdirSync)((0, import_node_path21.dirname)(path), { recursive: true });
34704
+ (0, import_node_fs31.mkdirSync)((0, import_node_path22.dirname)(path), { recursive: true });
34623
34705
  try {
34624
- (0, import_node_fs30.writeFileSync)(path, contents, { flag: "wx" });
34706
+ (0, import_node_fs31.writeFileSync)(path, contents, { flag: "wx" });
34625
34707
  } catch (err) {
34626
34708
  if (err.code !== "EEXIST") throw err;
34627
34709
  }
@@ -34640,11 +34722,11 @@ var Fail2banAdapter = class {
34640
34722
  enforces = true;
34641
34723
  jailReady = false;
34642
34724
  isAvailable() {
34643
- const result = (0, import_node_child_process8.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
34725
+ const result = (0, import_node_child_process9.spawnSync)("fail2ban-client", ["ping"], { stdio: "pipe" });
34644
34726
  return result.status === 0;
34645
34727
  }
34646
34728
  client(args) {
34647
- return (0, import_node_child_process8.execFileSync)("fail2ban-client", args, {
34729
+ return (0, import_node_child_process9.execFileSync)("fail2ban-client", args, {
34648
34730
  encoding: "utf-8",
34649
34731
  stdio: ["ignore", "pipe", "pipe"]
34650
34732
  });
@@ -34689,7 +34771,11 @@ var Fail2banAdapter = class {
34689
34771
  ""
34690
34772
  ].join("\n")
34691
34773
  );
34692
- this.client(["reload", this.jail]);
34774
+ try {
34775
+ this.client(["reload", this.jail]);
34776
+ } catch {
34777
+ this.client(["reload"]);
34778
+ }
34693
34779
  this.jailReady = true;
34694
34780
  }
34695
34781
  async block(ip) {
@@ -34736,35 +34822,35 @@ var NftablesAdapter = class {
34736
34822
  table = "threatcrush";
34737
34823
  set = "blocklist";
34738
34824
  isAvailable() {
34739
- const result = (0, import_node_child_process8.spawnSync)("nft", ["--version"], { stdio: "pipe" });
34825
+ const result = (0, import_node_child_process9.spawnSync)("nft", ["--version"], { stdio: "pipe" });
34740
34826
  return result.status === 0;
34741
34827
  }
34742
34828
  ensureSetup() {
34743
34829
  try {
34744
- (0, import_node_child_process8.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
34830
+ (0, import_node_child_process9.execSync)(`nft list table inet ${this.table} 2>/dev/null`, { stdio: "pipe" });
34745
34831
  } catch {
34746
- (0, import_node_child_process8.execSync)(`nft add table inet ${this.table}`);
34747
- (0, import_node_child_process8.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
34748
- (0, import_node_child_process8.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
34749
- (0, import_node_child_process8.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
34832
+ (0, import_node_child_process9.execSync)(`nft add table inet ${this.table}`);
34833
+ (0, import_node_child_process9.execSync)(`nft add set inet ${this.table} ${this.set} '{ type ipv4_addr; flags timeout; }'`);
34834
+ (0, import_node_child_process9.execSync)(`nft add chain inet ${this.table} input '{ type filter hook input priority -1; policy accept; }'`);
34835
+ (0, import_node_child_process9.execSync)(`nft add rule inet ${this.table} input ip saddr @${this.set} drop`);
34750
34836
  }
34751
34837
  }
34752
34838
  async block(ip) {
34753
34839
  assertValidFirewallIp(ip);
34754
34840
  this.ensureSetup();
34755
- (0, import_node_child_process8.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
34841
+ (0, import_node_child_process9.execSync)(`nft add element inet ${this.table} ${this.set} '{ ${ip} }'`);
34756
34842
  }
34757
34843
  async unblock(ip) {
34758
34844
  assertValidFirewallIp(ip);
34759
34845
  try {
34760
- (0, import_node_child_process8.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
34846
+ (0, import_node_child_process9.execSync)(`nft delete element inet ${this.table} ${this.set} '{ ${ip} }'`);
34761
34847
  } catch {
34762
34848
  }
34763
34849
  }
34764
34850
  async isBlocked(ip) {
34765
34851
  assertValidFirewallIp(ip);
34766
34852
  try {
34767
- const output = (0, import_node_child_process8.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
34853
+ const output = (0, import_node_child_process9.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
34768
34854
  return output.includes(ip);
34769
34855
  } catch {
34770
34856
  return false;
@@ -34772,7 +34858,7 @@ var NftablesAdapter = class {
34772
34858
  }
34773
34859
  async listBlocked() {
34774
34860
  try {
34775
- const output = (0, import_node_child_process8.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
34861
+ const output = (0, import_node_child_process9.execSync)(`nft list set inet ${this.table} ${this.set}`, { encoding: "utf-8" });
34776
34862
  const match = output.match(/elements\s*=\s*\{([^}]*)\}/);
34777
34863
  if (!match) return [];
34778
34864
  return match[1].split(",").map((s) => s.trim().split(/\s/)[0]).filter(Boolean);
@@ -34785,34 +34871,34 @@ var IptablesAdapter = class {
34785
34871
  name = "iptables";
34786
34872
  chain = "THREATCRUSH";
34787
34873
  isAvailable() {
34788
- const result = (0, import_node_child_process8.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
34874
+ const result = (0, import_node_child_process9.spawnSync)("iptables", ["--version"], { stdio: "pipe" });
34789
34875
  return result.status === 0;
34790
34876
  }
34791
34877
  ensureChain() {
34792
34878
  try {
34793
- (0, import_node_child_process8.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
34879
+ (0, import_node_child_process9.execSync)(`iptables -n -L ${this.chain} 2>/dev/null`, { stdio: "pipe" });
34794
34880
  } catch {
34795
- (0, import_node_child_process8.execSync)(`iptables -N ${this.chain}`);
34796
- (0, import_node_child_process8.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
34881
+ (0, import_node_child_process9.execSync)(`iptables -N ${this.chain}`);
34882
+ (0, import_node_child_process9.execSync)(`iptables -I INPUT 1 -j ${this.chain}`);
34797
34883
  }
34798
34884
  }
34799
34885
  async block(ip) {
34800
34886
  assertValidFirewallIp(ip);
34801
34887
  this.ensureChain();
34802
34888
  if (await this.isBlocked(ip)) return;
34803
- (0, import_node_child_process8.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
34889
+ (0, import_node_child_process9.execSync)(`iptables -A ${this.chain} -s ${ip} -j DROP`);
34804
34890
  }
34805
34891
  async unblock(ip) {
34806
34892
  assertValidFirewallIp(ip);
34807
34893
  try {
34808
- (0, import_node_child_process8.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
34894
+ (0, import_node_child_process9.execSync)(`iptables -D ${this.chain} -s ${ip} -j DROP`);
34809
34895
  } catch {
34810
34896
  }
34811
34897
  }
34812
34898
  async isBlocked(ip) {
34813
34899
  assertValidFirewallIp(ip);
34814
34900
  try {
34815
- const output = (0, import_node_child_process8.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
34901
+ const output = (0, import_node_child_process9.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
34816
34902
  return output.includes(ip);
34817
34903
  } catch {
34818
34904
  return false;
@@ -34820,7 +34906,7 @@ var IptablesAdapter = class {
34820
34906
  }
34821
34907
  async listBlocked() {
34822
34908
  try {
34823
- const output = (0, import_node_child_process8.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
34909
+ const output = (0, import_node_child_process9.execSync)(`iptables -n -L ${this.chain}`, { encoding: "utf-8" });
34824
34910
  const ips = [];
34825
34911
  for (const line of output.split("\n")) {
34826
34912
  const match = line.match(/DROP\s+all\s+--\s+(\d+\.\d+\.\d+\.\d+)/);
@@ -34876,7 +34962,7 @@ function detectFirewallAdapter(backend = "auto") {
34876
34962
  }
34877
34963
 
34878
34964
  // src/daemon/firewall/remediation.ts
34879
- var import_node_fs31 = require("fs");
34965
+ var import_node_fs32 = require("fs");
34880
34966
  var import_node_net8 = require("net");
34881
34967
  init_paths();
34882
34968
  init_backoff();
@@ -34949,6 +35035,10 @@ function isSuccessfulAuth(message) {
34949
35035
  }
34950
35036
  function explainBlockFailure(err, backend) {
34951
35037
  const raw = err.message || String(err);
35038
+ if (/EROFS|read-only file system/i.test(raw)) {
35039
+ const path = /open '([^']+)'/.exec(raw)?.[1];
35040
+ return `threatcrushd cannot write ${path ?? "its firewall config"} for ${backend}: the systemd unit mounts it read-only. Reinstall the unit and restart: sudo $(which threatcrush) install-service && sudo systemctl restart threatcrushd`;
35041
+ }
34952
35042
  const denied = /not permitted|EACCES|EPERM|permission denied|must be root/i.test(raw);
34953
35043
  if (!denied) return `${raw} (backend: ${backend})`;
34954
35044
  const who = typeof process.getuid === "function" && process.getuid() === 0 ? "as root" : `as uid ${typeof process.getuid === "function" ? process.getuid() : "?"}`;
@@ -35286,7 +35376,7 @@ var RemediationManager = class {
35286
35376
  }
35287
35377
  logLine(line) {
35288
35378
  try {
35289
- (0, import_node_fs31.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
35379
+ (0, import_node_fs32.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
35290
35380
  `);
35291
35381
  } catch {
35292
35382
  }
@@ -35324,19 +35414,19 @@ function remediationSettings(section) {
35324
35414
  init_backoff();
35325
35415
 
35326
35416
  // src/daemon/watchdog-service.ts
35327
- var import_node_fs32 = require("fs");
35328
- var import_node_path22 = require("path");
35417
+ var import_node_fs33 = require("fs");
35418
+ var import_node_path23 = require("path");
35329
35419
  function defaultShareGid() {
35330
35420
  const isRoot4 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
35331
35421
  if (!isRoot4) return void 0;
35332
35422
  try {
35333
- return (0, import_node_fs32.statSync)("/var/log/auth.log").gid;
35423
+ return (0, import_node_fs33.statSync)("/var/log/auth.log").gid;
35334
35424
  } catch {
35335
35425
  return void 0;
35336
35426
  }
35337
35427
  }
35338
35428
  function startWatchdog(opts) {
35339
- const dir = opts.config?.dir ?? (0, import_node_path22.join)(opts.stateDir, WATCHDOG_DIRNAME);
35429
+ const dir = opts.config?.dir ?? (0, import_node_path23.join)(opts.stateDir, WATCHDOG_DIRNAME);
35340
35430
  const base = { dir, logged: 0, answered: 0, errored: 0 };
35341
35431
  if (opts.config?.enabled === false) {
35342
35432
  opts.log("[watchdog] off ([watchdog] enabled = false)");
@@ -35430,7 +35520,7 @@ async function flushTelemetry(timeoutMs = 2e3) {
35430
35520
  }
35431
35521
 
35432
35522
  // src/core/node-runtime.ts
35433
- var import_node_child_process9 = require("child_process");
35523
+ var import_node_child_process10 = require("child_process");
35434
35524
  var MIN_DAEMON_NODE_MAJOR = 22;
35435
35525
  function nodeMajor(version) {
35436
35526
  const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
@@ -35444,23 +35534,23 @@ function daemonNodeProblem(version) {
35444
35534
  }
35445
35535
  function versionOfNode(path) {
35446
35536
  if (path === process.execPath) return process.versions.node;
35447
- const res = (0, import_node_child_process9.spawnSync)(path, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
35537
+ const res = (0, import_node_child_process10.spawnSync)(path, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
35448
35538
  return res.status === 0 ? res.stdout.trim() : null;
35449
35539
  }
35450
35540
 
35451
35541
  // src/daemon/index.ts
35452
35542
  function readVersion2() {
35453
35543
  try {
35454
- const pkg = JSON.parse((0, import_node_fs33.readFileSync)((0, import_node_path23.join)(__dirname, "..", "package.json"), "utf-8"));
35544
+ const pkg = JSON.parse((0, import_node_fs34.readFileSync)((0, import_node_path24.join)(__dirname, "..", "package.json"), "utf-8"));
35455
35545
  return pkg.version || "0.0.0";
35456
35546
  } catch {
35457
35547
  return "0.0.0";
35458
35548
  }
35459
35549
  }
35460
35550
  async function runHardeningChecks() {
35461
- const { stdout } = await (0, import_node_util.promisify)(import_node_child_process10.execFile)(
35551
+ const { stdout } = await (0, import_node_util.promisify)(import_node_child_process11.execFile)(
35462
35552
  process.execPath,
35463
- [(0, import_node_path23.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
35553
+ [(0, import_node_path24.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
35464
35554
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
35465
35555
  );
35466
35556
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -35468,7 +35558,7 @@ async function runHardeningChecks() {
35468
35558
  }
35469
35559
  function logLine(line) {
35470
35560
  try {
35471
- (0, import_node_fs33.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
35561
+ (0, import_node_fs34.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
35472
35562
  `);
35473
35563
  } catch {
35474
35564
  }
@@ -35493,9 +35583,9 @@ async function runDaemon() {
35493
35583
  logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
35494
35584
  const restartDaemon = () => {
35495
35585
  if (PATHS.mode === "system") {
35496
- (0, import_node_child_process10.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
35586
+ (0, import_node_child_process11.spawn)("systemctl", ["restart", "threatcrushd"], { detached: true, stdio: "ignore" }).unref();
35497
35587
  } else {
35498
- (0, import_node_child_process10.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
35588
+ (0, import_node_child_process11.spawn)(process.execPath, process.argv.slice(1), { detached: true, stdio: "ignore" }).unref();
35499
35589
  setTimeout(() => process.exit(0), 500).unref();
35500
35590
  }
35501
35591
  };
@@ -35510,7 +35600,7 @@ async function runDaemon() {
35510
35600
  } catch (err) {
35511
35601
  logLine(`[daemon] state db unavailable: ${err.message}`);
35512
35602
  }
35513
- const config = loadConfig((0, import_node_fs33.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
35603
+ const config = loadConfig((0, import_node_fs34.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
35514
35604
  configureAttackDetection(config.detection);
35515
35605
  const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
35516
35606
  const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
@@ -35587,9 +35677,9 @@ async function runDaemon() {
35587
35677
  cloudSync = new CloudSync({
35588
35678
  bus,
35589
35679
  version,
35590
- hostname: (0, import_node_os9.hostname)(),
35680
+ hostname: (0, import_node_os10.hostname)(),
35591
35681
  minSeverity,
35592
- spoolPath: (0, import_node_path23.join)(PATHS.stateDir, "cloud-spool.jsonl"),
35682
+ spoolPath: (0, import_node_path24.join)(PATHS.stateDir, "cloud-spool.jsonl"),
35593
35683
  log: logLine,
35594
35684
  ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
35595
35685
  runHardening: runHardeningChecks
@@ -35671,7 +35761,7 @@ var SYSTEM_SOCKET = "/var/run/threatcrush/threatcrushd.sock";
35671
35761
  function isRoot2() {
35672
35762
  return typeof process.getuid === "function" && process.getuid() === 0;
35673
35763
  }
35674
- var DAEMON_ENTRY = (0, import_node_path24.join)(__dirname, "daemon.js");
35764
+ var DAEMON_ENTRY = (0, import_node_path25.join)(__dirname, "daemon.js");
35675
35765
  async function daemonForeground() {
35676
35766
  await runDaemon();
35677
35767
  }
@@ -35692,7 +35782,7 @@ async function daemonStart() {
35692
35782
  return;
35693
35783
  }
35694
35784
  ensureRuntimeDirs();
35695
- if (!(0, import_node_fs34.existsSync)(DAEMON_ENTRY)) {
35785
+ if (!(0, import_node_fs35.existsSync)(DAEMON_ENTRY)) {
35696
35786
  console.log(source_default.red(` Daemon entry not found at ${DAEMON_ENTRY}.`));
35697
35787
  console.log(source_default.dim(" Reinstall with `threatcrush update` or `pnpm run build` in the cli package."));
35698
35788
  return;
@@ -35700,8 +35790,8 @@ async function daemonStart() {
35700
35790
  let out;
35701
35791
  let err;
35702
35792
  try {
35703
- out = (0, import_node_fs35.openSync)(PATHS.logFile, "a");
35704
- err = (0, import_node_fs35.openSync)(PATHS.logFile, "a");
35793
+ out = (0, import_node_fs36.openSync)(PATHS.logFile, "a");
35794
+ err = (0, import_node_fs36.openSync)(PATHS.logFile, "a");
35705
35795
  } catch (e) {
35706
35796
  const code = e.code;
35707
35797
  console.log(source_default.red(` \u2717 Cannot write daemon log at ${PATHS.logFile} (${code ?? "error"}).`));
@@ -35714,7 +35804,7 @@ async function daemonStart() {
35714
35804
  }
35715
35805
  return;
35716
35806
  }
35717
- const child = (0, import_node_child_process11.spawn)(process.execPath, [DAEMON_ENTRY], {
35807
+ const child = (0, import_node_child_process12.spawn)(process.execPath, [DAEMON_ENTRY], {
35718
35808
  detached: true,
35719
35809
  stdio: ["ignore", out, err],
35720
35810
  env: { ...process.env, THREATCRUSH_DAEMON: "1" }
@@ -35789,41 +35879,41 @@ async function waitForExit(pid, timeoutMs) {
35789
35879
  }
35790
35880
  async function releaseStaleSocket() {
35791
35881
  const deadline = Date.now() + 2e3;
35792
- while ((0, import_node_fs34.existsSync)(PATHS.socket) && Date.now() < deadline) {
35882
+ while ((0, import_node_fs35.existsSync)(PATHS.socket) && Date.now() < deadline) {
35793
35883
  await new Promise((r) => setTimeout(r, 50));
35794
35884
  }
35795
- if ((0, import_node_fs34.existsSync)(PATHS.socket)) {
35885
+ if ((0, import_node_fs35.existsSync)(PATHS.socket)) {
35796
35886
  try {
35797
- (0, import_node_fs34.unlinkSync)(PATHS.socket);
35887
+ (0, import_node_fs35.unlinkSync)(PATHS.socket);
35798
35888
  } catch {
35799
35889
  }
35800
35890
  }
35801
35891
  }
35802
35892
 
35803
35893
  // src/commands/service.ts
35804
- var import_node_child_process12 = require("child_process");
35805
- var import_node_fs36 = require("fs");
35806
- var import_node_path25 = require("path");
35807
- var import_node_os10 = require("os");
35894
+ var import_node_child_process13 = require("child_process");
35895
+ var import_node_fs37 = require("fs");
35896
+ var import_node_path26 = require("path");
35897
+ var import_node_os11 = require("os");
35808
35898
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
35809
35899
  var DAEMON_UNIT_NAME = "threatcrushd.service";
35810
35900
  function resolveTemplate() {
35811
- const templatePath = (0, import_node_path25.join)(__dirname, "systemd", "threatcrushd.service");
35812
- if (!(0, import_node_fs36.existsSync)(templatePath)) {
35901
+ const templatePath = (0, import_node_path26.join)(__dirname, "systemd", "threatcrushd.service");
35902
+ if (!(0, import_node_fs37.existsSync)(templatePath)) {
35813
35903
  throw new Error(`systemd unit template not found at ${templatePath}`);
35814
35904
  }
35815
- return (0, import_node_fs36.readFileSync)(templatePath, "utf-8");
35905
+ return (0, import_node_fs37.readFileSync)(templatePath, "utf-8");
35816
35906
  }
35817
35907
  function stableBinPath(binPath) {
35818
35908
  const stable = binPath.replace(/\/\.pnpm\/[^/]+\/node_modules\//, "/node_modules/");
35819
35909
  if (stable === binPath) return binPath;
35820
- return (0, import_node_fs36.existsSync)(stable) ? stable : binPath;
35910
+ return (0, import_node_fs37.existsSync)(stable) ? stable : binPath;
35821
35911
  }
35822
35912
  function resolveBinPath() {
35823
35913
  const arg = process.argv[1];
35824
- if (arg && (0, import_node_fs36.existsSync)(arg)) return stableBinPath(arg);
35914
+ if (arg && (0, import_node_fs37.existsSync)(arg)) return stableBinPath(arg);
35825
35915
  try {
35826
- return (0, import_node_child_process12.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
35916
+ return (0, import_node_child_process13.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
35827
35917
  } catch {
35828
35918
  return "threatcrush";
35829
35919
  }
@@ -35831,11 +35921,11 @@ function resolveBinPath() {
35831
35921
  function stableNodePath(execPath) {
35832
35922
  const stable = execPath.replace(/(\/installs\/node\/)[^/]+\//, "$1latest/");
35833
35923
  if (stable === execPath) return execPath;
35834
- return (0, import_node_fs36.existsSync)(stable) ? stable : execPath;
35924
+ return (0, import_node_fs37.existsSync)(stable) ? stable : execPath;
35835
35925
  }
35836
35926
  function looksLikeNodeScript(path) {
35837
35927
  try {
35838
- const head = (0, import_node_fs36.readFileSync)(path, "utf-8").slice(0, 120);
35928
+ const head = (0, import_node_fs37.readFileSync)(path, "utf-8").slice(0, 120);
35839
35929
  return /^#!.*\bnode\b/.test(head);
35840
35930
  } catch {
35841
35931
  return false;
@@ -35862,20 +35952,20 @@ function isRoot3() {
35862
35952
  return typeof process.getuid === "function" && process.getuid() === 0;
35863
35953
  }
35864
35954
  function reexecWithSudo(args) {
35865
- if ((0, import_node_child_process12.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
35955
+ if ((0, import_node_child_process13.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
35866
35956
  console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
35867
35957
  const bin = resolveBinPath();
35868
35958
  const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
35869
- const result = (0, import_node_child_process12.spawnSync)("sudo", argv, { stdio: "inherit" });
35959
+ const result = (0, import_node_child_process13.spawnSync)("sudo", argv, { stdio: "inherit" });
35870
35960
  return result.status === 0;
35871
35961
  }
35872
35962
  function callerHome() {
35873
35963
  const user = process.env.SUDO_USER;
35874
35964
  if (!user) return null;
35875
35965
  try {
35876
- const line = (0, import_node_child_process12.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
35966
+ const line = (0, import_node_child_process13.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
35877
35967
  const home = line.split(":")[5];
35878
- return home && (0, import_node_fs36.existsSync)(home) ? home : null;
35968
+ return home && (0, import_node_fs37.existsSync)(home) ? home : null;
35879
35969
  } catch {
35880
35970
  return null;
35881
35971
  }
@@ -35883,13 +35973,13 @@ function callerHome() {
35883
35973
  function stopUserModeDaemon() {
35884
35974
  const home = callerHome();
35885
35975
  if (!home) return;
35886
- const runDir = (0, import_node_path25.join)(home, ".threatcrush", "run");
35887
- const pidFile = (0, import_node_path25.join)(runDir, "threatcrushd.pid");
35888
- const socket = (0, import_node_path25.join)(runDir, "threatcrushd.sock");
35889
- if (!(0, import_node_fs36.existsSync)(pidFile) && !(0, import_node_fs36.existsSync)(socket)) return;
35976
+ const runDir = (0, import_node_path26.join)(home, ".threatcrush", "run");
35977
+ const pidFile = (0, import_node_path26.join)(runDir, "threatcrushd.pid");
35978
+ const socket = (0, import_node_path26.join)(runDir, "threatcrushd.sock");
35979
+ if (!(0, import_node_fs37.existsSync)(pidFile) && !(0, import_node_fs37.existsSync)(socket)) return;
35890
35980
  let pid = null;
35891
35981
  try {
35892
- pid = Number.parseInt((0, import_node_fs36.readFileSync)(pidFile, "utf-8").trim(), 10);
35982
+ pid = Number.parseInt((0, import_node_fs37.readFileSync)(pidFile, "utf-8").trim(), 10);
35893
35983
  } catch {
35894
35984
  pid = null;
35895
35985
  }
@@ -35902,13 +35992,13 @@ function stopUserModeDaemon() {
35902
35992
  }
35903
35993
  for (const path of [socket, pidFile]) {
35904
35994
  try {
35905
- if ((0, import_node_fs36.existsSync)(path)) (0, import_node_fs36.rmSync)(path);
35995
+ if ((0, import_node_fs37.existsSync)(path)) (0, import_node_fs37.rmSync)(path);
35906
35996
  } catch {
35907
35997
  }
35908
35998
  }
35909
35999
  }
35910
36000
  function unitIsActive() {
35911
- const result = (0, import_node_child_process12.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
36001
+ const result = (0, import_node_child_process13.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
35912
36002
  return result.status === 0;
35913
36003
  }
35914
36004
  async function installServiceCommand() {
@@ -35919,8 +36009,8 @@ async function installServiceCommand() {
35919
36009
  return;
35920
36010
  }
35921
36011
  const noSystemd = systemdUnavailableReason({
35922
- hasSystemctl: (0, import_node_child_process12.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
35923
- booted: (0, import_node_fs36.existsSync)("/run/systemd/system")
36012
+ hasSystemctl: (0, import_node_child_process13.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
36013
+ booted: (0, import_node_fs37.existsSync)("/run/systemd/system")
35924
36014
  });
35925
36015
  if (noSystemd) {
35926
36016
  console.log(source_default.red(` \u2717 systemd isn't available here: ${noSystemd}.`));
@@ -35942,7 +36032,7 @@ async function installServiceCommand() {
35942
36032
  const isNodeScript = looksLikeNodeScript(binPath);
35943
36033
  let nodePath = stableNodePath(process.execPath);
35944
36034
  if (isNodeScript && nodeVersionDir(binPath)) {
35945
- binPath = (0, import_node_fs36.realpathSync)(binPath);
36035
+ binPath = (0, import_node_fs37.realpathSync)(binPath);
35946
36036
  nodePath = process.execPath;
35947
36037
  }
35948
36038
  if (isNodeScript) {
@@ -35955,9 +36045,9 @@ async function installServiceCommand() {
35955
36045
  }
35956
36046
  }
35957
36047
  const exec = execStartCommand(binPath, nodePath, isNodeScript);
35958
- const configDir = (0, import_node_path25.join)((0, import_node_os10.homedir)(), ".threatcrush");
36048
+ const configDir = (0, import_node_path26.join)((0, import_node_os11.homedir)(), ".threatcrush");
35959
36049
  const unit = renderUnit(resolveTemplate(), { exec, binPath, configDir });
35960
- (0, import_node_fs36.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
36050
+ (0, import_node_fs37.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
35961
36051
  console.log(source_default.green(` \u2713 Installed unit file: ${UNIT_PATH}`));
35962
36052
  console.log(source_default.dim(` ExecStart=${exec}`));
35963
36053
  const nodeDir = nodeVersionDir(nodePath);
@@ -35971,8 +36061,8 @@ async function installServiceCommand() {
35971
36061
  ensureSystemDirs(configDir);
35972
36062
  stopUserModeDaemon();
35973
36063
  try {
35974
- (0, import_node_child_process12.execSync)("systemctl daemon-reload", { stdio: "inherit" });
35975
- (0, import_node_child_process12.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
36064
+ (0, import_node_child_process13.execSync)("systemctl daemon-reload", { stdio: "inherit" });
36065
+ (0, import_node_child_process13.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
35976
36066
  } catch (err) {
35977
36067
  console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
35978
36068
  console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
@@ -36006,20 +36096,20 @@ function ensureSystemDirs(configDir) {
36006
36096
  ];
36007
36097
  let admGid = null;
36008
36098
  try {
36009
- admGid = (0, import_node_fs36.statSync)("/var/log/auth.log").gid;
36099
+ admGid = (0, import_node_fs37.statSync)("/var/log/auth.log").gid;
36010
36100
  } catch {
36011
36101
  }
36012
36102
  for (const { path, groupWritable, sticky } of dirs) {
36013
36103
  try {
36014
- (0, import_node_fs36.mkdirSync)(path, { recursive: true });
36104
+ (0, import_node_fs37.mkdirSync)(path, { recursive: true });
36015
36105
  } catch {
36016
36106
  }
36017
36107
  try {
36018
36108
  if (groupWritable && admGid !== null) {
36019
- (0, import_node_fs36.chmodSync)(path, sticky ? 1533 : 509);
36020
- (0, import_node_child_process12.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
36109
+ (0, import_node_fs37.chmodSync)(path, sticky ? 1533 : 509);
36110
+ (0, import_node_child_process13.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
36021
36111
  } else {
36022
- (0, import_node_fs36.chmodSync)(path, 493);
36112
+ (0, import_node_fs37.chmodSync)(path, 493);
36023
36113
  }
36024
36114
  } catch {
36025
36115
  }
@@ -36039,29 +36129,29 @@ async function uninstallServiceCommand() {
36039
36129
  return;
36040
36130
  }
36041
36131
  try {
36042
- (0, import_node_child_process12.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
36132
+ (0, import_node_child_process13.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
36043
36133
  } catch {
36044
36134
  }
36045
36135
  try {
36046
- (0, import_node_child_process12.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
36136
+ (0, import_node_child_process13.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
36047
36137
  } catch {
36048
36138
  }
36049
36139
  try {
36050
- if ((0, import_node_fs36.existsSync)(UNIT_PATH)) {
36051
- (0, import_node_child_process12.execSync)(`rm -f ${UNIT_PATH}`);
36140
+ if ((0, import_node_fs37.existsSync)(UNIT_PATH)) {
36141
+ (0, import_node_child_process13.execSync)(`rm -f ${UNIT_PATH}`);
36052
36142
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
36053
36143
  }
36054
36144
  } catch {
36055
36145
  }
36056
36146
  try {
36057
- (0, import_node_child_process12.execSync)("systemctl daemon-reload", { stdio: "inherit" });
36147
+ (0, import_node_child_process13.execSync)("systemctl daemon-reload", { stdio: "inherit" });
36058
36148
  } catch {
36059
36149
  }
36060
36150
  console.log(source_default.green(" \u2713 threatcrushd service removed."));
36061
36151
  }
36062
36152
 
36063
36153
  // src/commands/save.ts
36064
- var import_node_fs37 = require("fs");
36154
+ var import_node_fs38 = require("fs");
36065
36155
  var import_toml5 = __toESM(require_toml());
36066
36156
  init_paths();
36067
36157
  var SECRET_KEY = /pass(word)?|secret|token|api_?key|private|webhook|dsn|url|routing_key|auth/i;
@@ -36099,9 +36189,9 @@ async function saveCommand(opts = {}) {
36099
36189
  }
36100
36190
  const path = opts.config ?? PATHS.configFile;
36101
36191
  let config = {};
36102
- if ((0, import_node_fs37.existsSync)(path)) {
36192
+ if ((0, import_node_fs38.existsSync)(path)) {
36103
36193
  try {
36104
- config = import_toml5.default.parse((0, import_node_fs37.readFileSync)(path, "utf-8"));
36194
+ config = import_toml5.default.parse((0, import_node_fs38.readFileSync)(path, "utf-8"));
36105
36195
  } catch (err) {
36106
36196
  console.log(source_default.red(` \u2717 ${path} is not valid TOML: ${err.message}
36107
36197
  `));
@@ -36213,8 +36303,8 @@ function welcomeCommand() {
36213
36303
  }
36214
36304
 
36215
36305
  // src/commands/properties.ts
36216
- var import_node_fs38 = require("fs");
36217
- var import_node_path26 = require("path");
36306
+ var import_node_fs39 = require("fs");
36307
+ var import_node_path27 = require("path");
36218
36308
  var import_node_readline4 = __toESM(require("readline"));
36219
36309
  var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
36220
36310
  var KINDS = ["url", "api", "domain", "ip", "repo"];
@@ -36543,8 +36633,8 @@ async function propertiesRunsCommand(opts) {
36543
36633
  }
36544
36634
  }
36545
36635
  function parseImportFile(path) {
36546
- const ext = (0, import_node_path26.extname)(path).toLowerCase();
36547
- const raw = (0, import_node_fs38.readFileSync)(path, "utf-8");
36636
+ const ext = (0, import_node_path27.extname)(path).toLowerCase();
36637
+ const raw = (0, import_node_fs39.readFileSync)(path, "utf-8");
36548
36638
  if (ext === ".json") {
36549
36639
  const parsed = JSON.parse(raw);
36550
36640
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -36739,18 +36829,18 @@ async function rulesCommand(opts) {
36739
36829
  }
36740
36830
 
36741
36831
  // src/commands/harden.ts
36742
- var import_node_fs39 = require("fs");
36743
- var import_node_child_process13 = require("child_process");
36832
+ var import_node_fs40 = require("fs");
36833
+ var import_node_child_process14 = require("child_process");
36744
36834
  function tryExec(cmd) {
36745
36835
  try {
36746
- return (0, import_node_child_process13.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
36836
+ return (0, import_node_child_process14.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
36747
36837
  } catch {
36748
36838
  return null;
36749
36839
  }
36750
36840
  }
36751
36841
  function tryRead(path) {
36752
36842
  try {
36753
- return (0, import_node_fs39.readFileSync)(path, "utf-8");
36843
+ return (0, import_node_fs40.readFileSync)(path, "utf-8");
36754
36844
  } catch {
36755
36845
  return null;
36756
36846
  }
@@ -36854,8 +36944,8 @@ function checkSshWeakConfig() {
36854
36944
  };
36855
36945
  }
36856
36946
  function checkAutoUpdates() {
36857
- const unattended = (0, import_node_fs39.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs39.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
36858
- const dnfAuto = (0, import_node_fs39.existsSync)("/etc/dnf/automatic.conf");
36947
+ const unattended = (0, import_node_fs40.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs40.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
36948
+ const dnfAuto = (0, import_node_fs40.existsSync)("/etc/dnf/automatic.conf");
36859
36949
  if (unattended || dnfAuto) {
36860
36950
  return {
36861
36951
  key: "auto-updates",
@@ -36981,7 +37071,7 @@ function checkFail2ban() {
36981
37071
  explanation: "fail2ban is installed and running."
36982
37072
  };
36983
37073
  }
36984
- if ((0, import_node_fs39.existsSync)("/etc/fail2ban/fail2ban.conf")) {
37074
+ if ((0, import_node_fs40.existsSync)("/etc/fail2ban/fail2ban.conf")) {
36985
37075
  return {
36986
37076
  key: checkKey,
36987
37077
  status: "warn",
@@ -37310,11 +37400,11 @@ async function allowlistCommand(opts) {
37310
37400
  init_paths();
37311
37401
 
37312
37402
  // src/upgrade.ts
37313
- var import_node_child_process14 = require("child_process");
37403
+ var import_node_child_process15 = require("child_process");
37314
37404
  var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
37315
37405
  var defaultRunner = (cmd) => {
37316
37406
  try {
37317
- return (0, import_node_child_process14.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
37407
+ return (0, import_node_child_process15.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
37318
37408
  } catch {
37319
37409
  return null;
37320
37410
  }
@@ -37429,25 +37519,25 @@ ${source_default.dim(" C R U S H")}
37429
37519
  var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
37430
37520
  var PKG_NAME = "@profullstack/threatcrush";
37431
37521
  var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
37432
- var INSTALL_CONFIG_PATH = (0, import_node_path27.join)((0, import_node_os11.homedir)(), ".threatcrush", "install.json");
37522
+ var INSTALL_CONFIG_PATH = (0, import_node_path28.join)((0, import_node_os12.homedir)(), ".threatcrush", "install.json");
37433
37523
  function detectPackageManager() {
37434
37524
  try {
37435
- const npmGlobal = (0, import_node_child_process15.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
37525
+ const npmGlobal = (0, import_node_child_process16.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
37436
37526
  if (npmGlobal.includes(PKG_NAME)) return "npm";
37437
37527
  } catch {
37438
37528
  }
37439
37529
  try {
37440
- (0, import_node_child_process15.execSync)("pnpm --version", { stdio: "pipe" });
37530
+ (0, import_node_child_process16.execSync)("pnpm --version", { stdio: "pipe" });
37441
37531
  return "pnpm";
37442
37532
  } catch {
37443
37533
  }
37444
37534
  try {
37445
- (0, import_node_child_process15.execSync)("yarn --version", { stdio: "pipe" });
37535
+ (0, import_node_child_process16.execSync)("yarn --version", { stdio: "pipe" });
37446
37536
  return "yarn";
37447
37537
  } catch {
37448
37538
  }
37449
37539
  try {
37450
- (0, import_node_child_process15.execSync)("bun --version", { stdio: "pipe" });
37540
+ (0, import_node_child_process16.execSync)("bun --version", { stdio: "pipe" });
37451
37541
  return "bun";
37452
37542
  } catch {
37453
37543
  }
@@ -37455,14 +37545,14 @@ function detectPackageManager() {
37455
37545
  }
37456
37546
  function readInstallConfig() {
37457
37547
  try {
37458
- return JSON.parse((0, import_node_fs40.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
37548
+ return JSON.parse((0, import_node_fs41.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
37459
37549
  } catch {
37460
37550
  return {};
37461
37551
  }
37462
37552
  }
37463
37553
  function packageLooksInstalled(pm, pkgName) {
37464
37554
  try {
37465
- const output = (0, import_node_child_process15.execSync)(globalListCommand(pm, pkgName), {
37555
+ const output = (0, import_node_child_process16.execSync)(globalListCommand(pm, pkgName), {
37466
37556
  encoding: "utf-8",
37467
37557
  stdio: ["pipe", "pipe", "pipe"]
37468
37558
  });
@@ -37565,14 +37655,14 @@ async function promoteUnprivilegedDaemon() {
37565
37655
  function restartSystemdDaemon() {
37566
37656
  const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
37567
37657
  const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
37568
- if (!asRoot && (0, import_node_child_process15.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
37658
+ if (!asRoot && (0, import_node_child_process16.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
37569
37659
  const [cmd, ...args] = argv;
37570
- if ((0, import_node_child_process15.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
37571
- return (0, import_node_child_process15.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
37660
+ if ((0, import_node_child_process16.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
37661
+ return (0, import_node_child_process16.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
37572
37662
  }
37573
37663
  function execQuiet(cmd) {
37574
37664
  try {
37575
- return (0, import_node_child_process15.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
37665
+ return (0, import_node_child_process16.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
37576
37666
  } catch {
37577
37667
  return null;
37578
37668
  }
@@ -37748,7 +37838,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
37748
37838
  program2.command("logs").description("Tail daemon logs").action(async () => {
37749
37839
  console.log(LOGO2);
37750
37840
  const logPath = PATHS.logFile;
37751
- if (!(0, import_node_fs40.existsSync)(logPath)) {
37841
+ if (!(0, import_node_fs41.existsSync)(logPath)) {
37752
37842
  console.log(source_default.yellow(` No log file found at ${logPath}`));
37753
37843
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
37754
37844
  return;
@@ -37756,7 +37846,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
37756
37846
  console.log(source_default.green(` Tailing ${logPath}...
37757
37847
  `));
37758
37848
  console.log(source_default.gray(" Press Ctrl+C to stop\n"));
37759
- (0, import_node_child_process15.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
37849
+ (0, import_node_child_process16.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
37760
37850
  });
37761
37851
  program2.command("update").description("Update ThreatCrush CLI and installed bundle").option("--cli", "Update CLI only").option("--modules", "Update modules only").option("--desktop", "Update desktop app too").action(async (opts) => {
37762
37852
  console.log(LOGO2);
@@ -37768,7 +37858,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
37768
37858
  for (const cmd of commands2) {
37769
37859
  console.log(source_default.green(` \u2192 ${cmd}
37770
37860
  `));
37771
- (0, import_node_child_process15.execSync)(cmd, { stdio: "inherit" });
37861
+ (0, import_node_child_process16.execSync)(cmd, { stdio: "inherit" });
37772
37862
  }
37773
37863
  console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
37774
37864
  await reportIfStillStale();
@@ -37793,7 +37883,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
37793
37883
  for (const cmd of commands) {
37794
37884
  console.log(source_default.green(` \u2192 ${cmd}
37795
37885
  `));
37796
- (0, import_node_child_process15.execSync)(cmd, { stdio: "inherit" });
37886
+ (0, import_node_child_process16.execSync)(cmd, { stdio: "inherit" });
37797
37887
  }
37798
37888
  console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
37799
37889
  if (installMode === "desktop") {
@@ -37844,7 +37934,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
37844
37934
  for (const cmd of commands) {
37845
37935
  console.log(source_default.green(` \u2192 ${cmd}
37846
37936
  `));
37847
- (0, import_node_child_process15.execSync)(cmd, { stdio: "inherit" });
37937
+ (0, import_node_child_process16.execSync)(cmd, { stdio: "inherit" });
37848
37938
  }
37849
37939
  console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
37850
37940
  console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
@@ -37921,10 +38011,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
37921
38011
  });
37922
38012
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
37923
38013
  console.log(LOGO2);
37924
- const configPath = (0, import_node_path27.join)((0, import_node_os11.homedir)(), ".threatcrush", "config.json");
38014
+ const configPath = (0, import_node_path28.join)((0, import_node_os12.homedir)(), ".threatcrush", "config.json");
37925
38015
  let email = "";
37926
38016
  try {
37927
- const config = JSON.parse((0, import_node_fs40.readFileSync)(configPath, "utf-8"));
38017
+ const config = JSON.parse((0, import_node_fs41.readFileSync)(configPath, "utf-8"));
37928
38018
  email = config.email || "";
37929
38019
  } catch {
37930
38020
  }
@@ -37941,9 +38031,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
37941
38031
  return;
37942
38032
  }
37943
38033
  try {
37944
- const dir = (0, import_node_path27.join)((0, import_node_os11.homedir)(), ".threatcrush");
37945
- if (!(0, import_node_fs40.existsSync)(dir)) (0, import_node_fs40.mkdirSync)(dir, { recursive: true });
37946
- (0, import_node_fs40.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
38034
+ const dir = (0, import_node_path28.join)((0, import_node_os12.homedir)(), ".threatcrush");
38035
+ if (!(0, import_node_fs41.existsSync)(dir)) (0, import_node_fs41.mkdirSync)(dir, { recursive: true });
38036
+ (0, import_node_fs41.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
37947
38037
  console.log(source_default.dim(` Saved email to ${configPath}`));
37948
38038
  } catch {
37949
38039
  }