@profullstack/threatcrush 0.18.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/daemon.js CHANGED
@@ -9356,10 +9356,10 @@ var require_dist = __commonJS({
9356
9356
  });
9357
9357
 
9358
9358
  // src/daemon/index.ts
9359
- var import_node_fs44 = require("fs");
9359
+ var import_node_fs45 = require("fs");
9360
9360
  var import_node_child_process18 = require("child_process");
9361
9361
  var import_node_os8 = require("os");
9362
- var import_node_path33 = require("path");
9362
+ var import_node_path34 = require("path");
9363
9363
  var import_node_util = require("util");
9364
9364
 
9365
9365
  // src/daemon/paths.ts
@@ -19318,9 +19318,9 @@ function slackChannel(webhookUrl) {
19318
19318
 
19319
19319
  // src/daemon/workers/runs-worker.ts
19320
19320
  var import_promises = require("dns/promises");
19321
- var import_node_fs20 = require("fs");
19321
+ var import_node_fs21 = require("fs");
19322
19322
  var import_node_net6 = require("net");
19323
- var import_node_path15 = require("path");
19323
+ var import_node_path16 = require("path");
19324
19324
 
19325
19325
  // src/core/cli-config.ts
19326
19326
  var import_node_fs15 = require("fs");
@@ -19528,8 +19528,8 @@ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date(
19528
19528
  }
19529
19529
 
19530
19530
  // src/commands/scan.ts
19531
- var import_node_fs19 = require("fs");
19532
- var import_node_path14 = require("path");
19531
+ var import_node_fs20 = require("fs");
19532
+ var import_node_path15 = require("path");
19533
19533
 
19534
19534
  // ../../node_modules/.pnpm/chalk@6.0.1/node_modules/chalk/source/utilities.js
19535
19535
  function stringReplaceAll(string, substring, postfix) {
@@ -25158,14 +25158,18 @@ async function queryOsv(name, version, ecosystem) {
25158
25158
  var import_node_crypto4 = require("crypto");
25159
25159
  var import_node_path13 = require("path");
25160
25160
 
25161
+ // src/scanverify/index.ts
25162
+ var import_node_fs19 = require("fs");
25163
+ var import_node_path14 = require("path");
25164
+
25161
25165
  // src/commands/scan.ts
25162
25166
  function readVersion() {
25163
25167
  for (const candidate of [
25164
- (0, import_node_path14.join)(__dirname, "..", "package.json"),
25165
- (0, import_node_path14.join)(__dirname, "..", "..", "package.json")
25168
+ (0, import_node_path15.join)(__dirname, "..", "package.json"),
25169
+ (0, import_node_path15.join)(__dirname, "..", "..", "package.json")
25166
25170
  ]) {
25167
25171
  try {
25168
- return JSON.parse((0, import_node_fs19.readFileSync)(candidate, "utf-8")).version ?? "0.0.0";
25172
+ return JSON.parse((0, import_node_fs20.readFileSync)(candidate, "utf-8")).version ?? "0.0.0";
25169
25173
  } catch {
25170
25174
  }
25171
25175
  }
@@ -25413,24 +25417,24 @@ async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0,
25413
25417
  const inside = addresses.find((a) => !isPublicTarget(a));
25414
25418
  return inside ? `${host} resolves to ${inside}, which is not a public address; dashboard runs never reach inside this network` : null;
25415
25419
  }
25416
- function scanTargetError(target, roots, real = import_node_fs20.realpathSync) {
25420
+ function scanTargetError(target, roots, real = import_node_fs21.realpathSync) {
25417
25421
  if (roots.length === 0) {
25418
25422
  return "dashboard scans of this machine are off; list the directories they may read in [cloud] run_scan_paths";
25419
25423
  }
25420
25424
  let path;
25421
25425
  try {
25422
- path = real((0, import_node_path15.resolve)(target));
25426
+ path = real((0, import_node_path16.resolve)(target));
25423
25427
  } catch {
25424
25428
  return `no such path: ${target}`;
25425
25429
  }
25426
25430
  for (const root of roots) {
25427
25431
  let base;
25428
25432
  try {
25429
- base = real((0, import_node_path15.resolve)(root));
25433
+ base = real((0, import_node_path16.resolve)(root));
25430
25434
  } catch {
25431
25435
  continue;
25432
25436
  }
25433
- if (path === base || path.startsWith(base.endsWith(import_node_path15.sep) ? base : base + import_node_path15.sep)) return null;
25437
+ if (path === base || path.startsWith(base.endsWith(import_node_path16.sep) ? base : base + import_node_path16.sep)) return null;
25434
25438
  }
25435
25439
  return `${target} is outside [cloud] run_scan_paths`;
25436
25440
  }
@@ -25581,16 +25585,16 @@ var RunsWorker = class {
25581
25585
  };
25582
25586
 
25583
25587
  // src/daemon/workers/cloud-spool.ts
25584
- var import_node_fs21 = require("fs");
25588
+ var import_node_fs22 = require("fs");
25585
25589
  var import_promises2 = require("fs/promises");
25586
- var import_node_path16 = require("path");
25590
+ var import_node_path17 = require("path");
25587
25591
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
25588
25592
  var CloudSpool = class {
25589
25593
  constructor(path, limits = DEFAULT_SPOOL_LIMITS) {
25590
25594
  this.path = path;
25591
25595
  this.limits = limits;
25592
25596
  try {
25593
- (0, import_node_fs21.mkdirSync)((0, import_node_path16.dirname)(path), { recursive: true });
25597
+ (0, import_node_fs22.mkdirSync)((0, import_node_path17.dirname)(path), { recursive: true });
25594
25598
  } catch {
25595
25599
  }
25596
25600
  this.load();
@@ -25659,7 +25663,7 @@ var CloudSpool = class {
25659
25663
  load() {
25660
25664
  let raw;
25661
25665
  try {
25662
- raw = (0, import_node_fs21.readFileSync)(this.path, "utf-8");
25666
+ raw = (0, import_node_fs22.readFileSync)(this.path, "utf-8");
25663
25667
  } catch {
25664
25668
  return;
25665
25669
  }
@@ -26136,31 +26140,31 @@ function resolveConfig(section) {
26136
26140
  }
26137
26141
 
26138
26142
  // src/core/abuse-report-log.ts
26139
- var import_node_fs22 = require("fs");
26140
- var import_node_path17 = require("path");
26143
+ var import_node_fs23 = require("fs");
26144
+ var import_node_path18 = require("path");
26141
26145
  var ABUSE_DIRNAME = "abuse-reports";
26142
26146
  var LOG_FILE = "reports.jsonl";
26143
26147
  function resolveAbuseDir(dir) {
26144
26148
  if (dir) return dir;
26145
26149
  if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
26146
- const system = (0, import_node_path17.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
26147
- if ((0, import_node_fs22.existsSync)(system)) return system;
26148
- return (0, import_node_path17.join)(PATHS.stateDir, ABUSE_DIRNAME);
26150
+ const system = (0, import_node_path18.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
26151
+ if ((0, import_node_fs23.existsSync)(system)) return system;
26152
+ return (0, import_node_path18.join)(PATHS.stateDir, ABUSE_DIRNAME);
26149
26153
  }
26150
26154
  function logPath(dir) {
26151
- return (0, import_node_path17.join)(resolveAbuseDir(dir), LOG_FILE);
26155
+ return (0, import_node_path18.join)(resolveAbuseDir(dir), LOG_FILE);
26152
26156
  }
26153
26157
  function appendReport(record, dir) {
26154
26158
  const path = logPath(dir);
26155
- (0, import_node_fs22.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
26156
- (0, import_node_fs22.appendFileSync)(path, `${JSON.stringify(record)}
26159
+ (0, import_node_fs23.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
26160
+ (0, import_node_fs23.appendFileSync)(path, `${JSON.stringify(record)}
26157
26161
  `, { mode: 420 });
26158
26162
  }
26159
26163
  function readReports(dir) {
26160
26164
  const path = logPath(dir);
26161
26165
  let raw;
26162
26166
  try {
26163
- raw = (0, import_node_fs22.readFileSync)(path, "utf-8");
26167
+ raw = (0, import_node_fs23.readFileSync)(path, "utf-8");
26164
26168
  } catch {
26165
26169
  return [];
26166
26170
  }
@@ -26566,8 +26570,8 @@ var RemediationConsumer = class {
26566
26570
 
26567
26571
  // src/daemon/workers/auto-update.ts
26568
26572
  var import_node_child_process5 = require("child_process");
26569
- var import_node_fs23 = require("fs");
26570
- var import_node_path18 = require("path");
26573
+ var import_node_fs24 = require("fs");
26574
+ var import_node_path19 = require("path");
26571
26575
  var PKG_NAME = "@profullstack/threatcrush";
26572
26576
  var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
26573
26577
  var DEFAULT_INTERVAL_MS = 6 * 36e5;
@@ -26610,12 +26614,12 @@ function pickUpdate(doc, current, opts) {
26610
26614
  return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
26611
26615
  }
26612
26616
  function installPlan(opts) {
26613
- const expected = `${import_node_path18.sep}lib${import_node_path18.sep}node_modules${import_node_path18.sep}@profullstack${import_node_path18.sep}threatcrush`;
26617
+ const expected = `${import_node_path19.sep}lib${import_node_path19.sep}node_modules${import_node_path19.sep}@profullstack${import_node_path19.sep}threatcrush`;
26614
26618
  if (!opts.pkgRoot.endsWith(expected)) {
26615
26619
  return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
26616
26620
  }
26617
- const nodeBin = (0, import_node_path18.dirname)(opts.execPath);
26618
- const npm = (0, import_node_path18.join)(nodeBin, "npm");
26621
+ const nodeBin = (0, import_node_path19.dirname)(opts.execPath);
26622
+ const npm = (0, import_node_path19.join)(nodeBin, "npm");
26619
26623
  if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
26620
26624
  if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
26621
26625
  const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
@@ -26647,10 +26651,10 @@ function installPlan(opts) {
26647
26651
  }
26648
26652
  function ownerOf(path, passwd = "/etc/passwd") {
26649
26653
  try {
26650
- const st = (0, import_node_fs23.statSync)(path);
26654
+ const st = (0, import_node_fs24.statSync)(path);
26651
26655
  let home = st.uid === 0 ? "/root" : "";
26652
26656
  try {
26653
- for (const line of (0, import_node_fs23.readFileSync)(passwd, "utf8").split("\n")) {
26657
+ for (const line of (0, import_node_fs24.readFileSync)(passwd, "utf8").split("\n")) {
26654
26658
  const f = line.split(":");
26655
26659
  if (Number(f[2]) === st.uid && f[5]) home = f[5];
26656
26660
  }
@@ -26760,7 +26764,7 @@ var AutoUpdate = class {
26760
26764
  uid: process.getuid?.() ?? -1,
26761
26765
  owner: ownerOf(this.opts.pkgRoot),
26762
26766
  underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
26763
- npmExists: import_node_fs23.existsSync
26767
+ npmExists: import_node_fs24.existsSync
26764
26768
  });
26765
26769
  if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
26766
26770
  this.recordAttempt(target);
@@ -26796,7 +26800,7 @@ var AutoUpdate = class {
26796
26800
  }
26797
26801
  lastAttempt() {
26798
26802
  try {
26799
- const v = JSON.parse((0, import_node_fs23.readFileSync)(this.opts.statePath, "utf8"));
26803
+ const v = JSON.parse((0, import_node_fs24.readFileSync)(this.opts.statePath, "utf8"));
26800
26804
  return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
26801
26805
  } catch {
26802
26806
  return null;
@@ -26804,7 +26808,7 @@ var AutoUpdate = class {
26804
26808
  }
26805
26809
  recordAttempt(version) {
26806
26810
  try {
26807
- (0, import_node_fs23.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
26811
+ (0, import_node_fs24.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
26808
26812
  } catch (err) {
26809
26813
  this.opts.log(`[update] could not record attempt: ${err.message}`);
26810
26814
  }
@@ -26813,8 +26817,8 @@ var AutoUpdate = class {
26813
26817
 
26814
26818
  // src/daemon/workers/threat-feeds.ts
26815
26819
  var import_node_child_process6 = require("child_process");
26816
- var import_node_fs24 = require("fs");
26817
- var import_node_path19 = require("path");
26820
+ var import_node_fs25 = require("fs");
26821
+ var import_node_path20 = require("path");
26818
26822
  var import_node_net10 = require("net");
26819
26823
  var EGRESS_TABLE = "threatcrush_egress";
26820
26824
  var DEFAULT_REFRESH_MS = 36e5;
@@ -26836,7 +26840,7 @@ function threatFeedSettings(section, env2 = process.env) {
26836
26840
  function abusechAuthKey(section, env2 = process.env) {
26837
26841
  if (section?.auth_key_file) {
26838
26842
  try {
26839
- const key2 = (0, import_node_fs24.readFileSync)(section.auth_key_file, "utf-8").trim();
26843
+ const key2 = (0, import_node_fs25.readFileSync)(section.auth_key_file, "utf-8").trim();
26840
26844
  if (key2) return key2;
26841
26845
  } catch {
26842
26846
  }
@@ -26999,14 +27003,14 @@ var ThreatFeeds = class {
26999
27003
  */
27000
27004
  writeResolverFiles(set) {
27001
27005
  const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
27002
- const dir = this.opts.resolverDir ?? (0, import_node_path19.dirname)(this.opts.cachePath);
27006
+ const dir = this.opts.resolverDir ?? (0, import_node_path20.dirname)(this.opts.cachePath);
27003
27007
  const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
27004
27008
  const write = (name, content) => {
27005
- const path = (0, import_node_path19.join)(dir, name);
27009
+ const path = (0, import_node_path20.join)(dir, name);
27006
27010
  if (this.resolverWritten.get(name) === content) return false;
27007
27011
  try {
27008
- (0, import_node_fs24.writeFileSync)(`${path}.tmp`, content);
27009
- (0, import_node_fs24.renameSync)(`${path}.tmp`, path);
27012
+ (0, import_node_fs25.writeFileSync)(`${path}.tmp`, content);
27013
+ (0, import_node_fs25.renameSync)(`${path}.tmp`, path);
27010
27014
  this.resolverWritten.set(name, content);
27011
27015
  return true;
27012
27016
  } catch (err) {
@@ -27017,11 +27021,11 @@ var ThreatFeeds = class {
27017
27021
  const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
27018
27022
  const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
27019
27023
  const via = [];
27020
- if ((0, import_node_fs24.existsSync)(hooks.dnsmasq)) {
27024
+ if ((0, import_node_fs25.existsSync)(hooks.dnsmasq)) {
27021
27025
  via.push("dnsmasq");
27022
27026
  if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
27023
27027
  }
27024
- if ((0, import_node_fs24.existsSync)(hooks.unbound)) {
27028
+ if ((0, import_node_fs25.existsSync)(hooks.unbound)) {
27025
27029
  via.push("unbound");
27026
27030
  if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
27027
27031
  this.run("systemctl", ["reload", "unbound.service"]);
@@ -27157,8 +27161,8 @@ var ThreatFeeds = class {
27157
27161
  };
27158
27162
 
27159
27163
  // src/daemon/workers/privilege-watch.ts
27160
- var import_node_fs25 = require("fs");
27161
- var import_node_path20 = require("path");
27164
+ var import_node_fs26 = require("fs");
27165
+ var import_node_path21 = require("path");
27162
27166
  var import_node_child_process7 = require("child_process");
27163
27167
 
27164
27168
  // src/core/privileges/index.ts
@@ -27384,31 +27388,31 @@ function countryName(code) {
27384
27388
  var fsIO = {
27385
27389
  readFile: (p) => {
27386
27390
  try {
27387
- return (0, import_node_fs25.readFileSync)(p, "utf-8");
27391
+ return (0, import_node_fs26.readFileSync)(p, "utf-8");
27388
27392
  } catch {
27389
27393
  return null;
27390
27394
  }
27391
27395
  },
27392
27396
  readDir: (p) => {
27393
27397
  try {
27394
- return (0, import_node_fs25.readdirSync)(p);
27398
+ return (0, import_node_fs26.readdirSync)(p);
27395
27399
  } catch {
27396
27400
  return null;
27397
27401
  }
27398
27402
  },
27399
- exists: (p) => (0, import_node_fs25.existsSync)(p)
27403
+ exists: (p) => (0, import_node_fs26.existsSync)(p)
27400
27404
  };
27401
27405
  function readJson(path) {
27402
27406
  try {
27403
- return JSON.parse((0, import_node_fs25.readFileSync)(path, "utf-8"));
27407
+ return JSON.parse((0, import_node_fs26.readFileSync)(path, "utf-8"));
27404
27408
  } catch {
27405
27409
  return null;
27406
27410
  }
27407
27411
  }
27408
27412
  function writeJson(path, value) {
27409
- (0, import_node_fs25.mkdirSync)((0, import_node_path20.dirname)(path), { recursive: true });
27410
- (0, import_node_fs25.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
27411
- (0, import_node_fs25.renameSync)(`${path}.tmp`, path);
27413
+ (0, import_node_fs26.mkdirSync)((0, import_node_path21.dirname)(path), { recursive: true });
27414
+ (0, import_node_fs26.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
27415
+ (0, import_node_fs26.renameSync)(`${path}.tmp`, path);
27412
27416
  }
27413
27417
  function defaultRun3(cmd, args) {
27414
27418
  const res = (0, import_node_child_process7.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -27525,7 +27529,7 @@ var PrivilegeWatch = class {
27525
27529
  for (const dir of dirs) {
27526
27530
  if (this.watchers.has(dir) || !this.io.exists(dir)) continue;
27527
27531
  try {
27528
- const w = (0, import_node_fs25.watch)(dir, { persistent: false }, (_type2, name) => {
27532
+ const w = (0, import_node_fs26.watch)(dir, { persistent: false }, (_type2, name) => {
27529
27533
  if (name && !String(name).startsWith("authorized_keys")) return;
27530
27534
  if (this.debounce) clearTimeout(this.debounce);
27531
27535
  this.debounce = setTimeout(() => {
@@ -27624,7 +27628,7 @@ var PrivilegeWatch = class {
27624
27628
  * raised a "new country" alert on its first run; on dev2 it did, at once.
27625
27629
  */
27626
27630
  async backfillLogins() {
27627
- if ((0, import_node_fs25.existsSync)(this.opts.loginsPath)) return;
27631
+ if ((0, import_node_fs26.existsSync)(this.opts.loginsPath)) return;
27628
27632
  const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
27629
27633
  const byUser = parseAcceptedLogins(out ?? "");
27630
27634
  const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
@@ -27637,7 +27641,7 @@ var PrivilegeWatch = class {
27637
27641
  return;
27638
27642
  }
27639
27643
  }
27640
- if ((0, import_node_fs25.existsSync)(this.opts.loginsPath)) return;
27644
+ if ((0, import_node_fs26.existsSync)(this.opts.loginsPath)) return;
27641
27645
  const at = this.now().toISOString();
27642
27646
  const history = {};
27643
27647
  for (const [user, userIps] of byUser) {
@@ -27689,9 +27693,9 @@ var PrivilegeWatch = class {
27689
27693
  };
27690
27694
 
27691
27695
  // src/daemon/workers/command-history.ts
27692
- var import_node_fs26 = require("fs");
27696
+ var import_node_fs27 = require("fs");
27693
27697
  var import_node_child_process8 = require("child_process");
27694
- var import_node_path21 = require("path");
27698
+ var import_node_path22 = require("path");
27695
27699
  var import_node_zlib = require("zlib");
27696
27700
  var import_node_crypto7 = require("crypto");
27697
27701
  var POLL_MS2 = 6e4;
@@ -27714,7 +27718,7 @@ function historyAccounts() {
27714
27718
  passwd = (0, import_node_child_process8.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
27715
27719
  } catch {
27716
27720
  try {
27717
- passwd = (0, import_node_fs26.readFileSync)("/etc/passwd", "utf8");
27721
+ passwd = (0, import_node_fs27.readFileSync)("/etc/passwd", "utf8");
27718
27722
  } catch {
27719
27723
  return [];
27720
27724
  }
@@ -27727,9 +27731,9 @@ function historyAccounts() {
27727
27731
  const name = fields[0] ?? "";
27728
27732
  const home = fields[5] ?? "";
27729
27733
  const shell = fields[6] ?? "";
27730
- if (!Number.isInteger(uid) || !Number.isInteger(gid) || !(0, import_node_path21.isAbsolute)(home) || home === "/" || home.split("/").includes("..")) return [];
27734
+ if (!Number.isInteger(uid) || !Number.isInteger(gid) || !(0, import_node_path22.isAbsolute)(home) || home === "/" || home.split("/").includes("..")) return [];
27731
27735
  if (root ? uid !== 0 && uid < 1e3 : uid !== process.getuid?.()) return [];
27732
- if (!HISTORY_TARGETS[(0, import_node_path21.basename)(shell)]) return [];
27736
+ if (!HISTORY_TARGETS[(0, import_node_path22.basename)(shell)]) return [];
27733
27737
  return [{ uid, gid, name, home, shell }];
27734
27738
  });
27735
27739
  }
@@ -27737,18 +27741,18 @@ function descriptorPath(directoryFd, name) {
27737
27741
  return `/proc/self/fd/${directoryFd}/${name}`;
27738
27742
  }
27739
27743
  function openDirectoryChain(path) {
27740
- if (!(0, import_node_path21.isAbsolute)(path) || path.split(import_node_path21.sep).includes("..")) throw new Error("directory path is not a safe absolute path");
27741
- const flags = import_node_fs26.constants.O_RDONLY | import_node_fs26.constants.O_DIRECTORY | (import_node_fs26.constants.O_NOFOLLOW ?? 0);
27742
- let fd = (0, import_node_fs26.openSync)("/", flags);
27744
+ if (!(0, import_node_path22.isAbsolute)(path) || path.split(import_node_path22.sep).includes("..")) throw new Error("directory path is not a safe absolute path");
27745
+ const flags = import_node_fs27.constants.O_RDONLY | import_node_fs27.constants.O_DIRECTORY | (import_node_fs27.constants.O_NOFOLLOW ?? 0);
27746
+ let fd = (0, import_node_fs27.openSync)("/", flags);
27743
27747
  try {
27744
- for (const part of path.split(import_node_path21.sep).filter((item) => item && item !== ".")) {
27745
- const next = (0, import_node_fs26.openSync)(descriptorPath(fd, part), flags);
27746
- (0, import_node_fs26.closeSync)(fd);
27748
+ for (const part of path.split(import_node_path22.sep).filter((item) => item && item !== ".")) {
27749
+ const next = (0, import_node_fs27.openSync)(descriptorPath(fd, part), flags);
27750
+ (0, import_node_fs27.closeSync)(fd);
27747
27751
  fd = next;
27748
27752
  }
27749
27753
  return fd;
27750
27754
  } catch (error) {
27751
- (0, import_node_fs26.closeSync)(fd);
27755
+ (0, import_node_fs27.closeSync)(fd);
27752
27756
  throw error;
27753
27757
  }
27754
27758
  }
@@ -27756,89 +27760,89 @@ function readExact(fd, size) {
27756
27760
  const data = Buffer.alloc(size);
27757
27761
  let offset = 0;
27758
27762
  while (offset < data.length) {
27759
- const read = (0, import_node_fs26.readSync)(fd, data, offset, data.length - offset, offset);
27763
+ const read = (0, import_node_fs27.readSync)(fd, data, offset, data.length - offset, offset);
27760
27764
  if (read === 0) break;
27761
27765
  offset += read;
27762
27766
  }
27763
27767
  return offset === data.length ? data : null;
27764
27768
  }
27765
27769
  function privateDirectory(path) {
27766
- (0, import_node_fs26.mkdirSync)(path, { recursive: true, mode: 448 });
27767
- const stat = (0, import_node_fs26.lstatSync)(path);
27770
+ (0, import_node_fs27.mkdirSync)(path, { recursive: true, mode: 448 });
27771
+ const stat = (0, import_node_fs27.lstatSync)(path);
27768
27772
  if (!stat.isDirectory() || stat.isSymbolicLink()) throw new Error("history storage path is not a directory");
27769
- (0, import_node_fs26.chmodSync)(path, 448);
27773
+ (0, import_node_fs27.chmodSync)(path, 448);
27770
27774
  }
27771
27775
  function safeReadHistory(directoryFd, name, uid) {
27772
- const noFollow = import_node_fs26.constants.O_NOFOLLOW ?? 0;
27773
- const fd = (0, import_node_fs26.openSync)(descriptorPath(directoryFd, name), import_node_fs26.constants.O_RDONLY | noFollow);
27776
+ const noFollow = import_node_fs27.constants.O_NOFOLLOW ?? 0;
27777
+ const fd = (0, import_node_fs27.openSync)(descriptorPath(directoryFd, name), import_node_fs27.constants.O_RDONLY | noFollow);
27774
27778
  try {
27775
- const opened = (0, import_node_fs26.fstatSync)(fd);
27779
+ const opened = (0, import_node_fs27.fstatSync)(fd);
27776
27780
  if (!opened.isFile() || opened.nlink !== 1 || opened.uid !== uid) return null;
27777
27781
  if (opened.size > MAX_HISTORY_BYTES) throw new Error(`history file exceeds ${MAX_HISTORY_BYTES} bytes`);
27778
27782
  const data = readExact(fd, opened.size);
27779
27783
  if (data === null) return null;
27780
- const after = (0, import_node_fs26.fstatSync)(fd);
27784
+ const after = (0, import_node_fs27.fstatSync)(fd);
27781
27785
  if (after.size !== opened.size || after.mtimeMs !== opened.mtimeMs) return null;
27782
27786
  return data;
27783
27787
  } finally {
27784
- (0, import_node_fs26.closeSync)(fd);
27788
+ (0, import_node_fs27.closeSync)(fd);
27785
27789
  }
27786
27790
  }
27787
27791
  function atomicWrite(path, data, mode = 384, owner, parentFd) {
27788
- const dirFd = parentFd ?? openDirectoryChain((0, import_node_path21.dirname)(path));
27792
+ const dirFd = parentFd ?? openDirectoryChain((0, import_node_path22.dirname)(path));
27789
27793
  const ownsDirFd = parentFd === void 0;
27790
- const name = (0, import_node_path21.basename)(path);
27794
+ const name = (0, import_node_path22.basename)(path);
27791
27795
  const temp = descriptorPath(dirFd, `${name}.${(0, import_node_crypto7.randomUUID)()}.tmp`);
27792
27796
  const destination = descriptorPath(dirFd, name);
27793
- const noFollow = import_node_fs26.constants.O_NOFOLLOW ?? 0;
27797
+ const noFollow = import_node_fs27.constants.O_NOFOLLOW ?? 0;
27794
27798
  let fd;
27795
27799
  try {
27796
- fd = (0, import_node_fs26.openSync)(temp, import_node_fs26.constants.O_WRONLY | import_node_fs26.constants.O_CREAT | import_node_fs26.constants.O_EXCL | noFollow, mode);
27800
+ fd = (0, import_node_fs27.openSync)(temp, import_node_fs27.constants.O_WRONLY | import_node_fs27.constants.O_CREAT | import_node_fs27.constants.O_EXCL | noFollow, mode);
27797
27801
  let offset = 0;
27798
- while (offset < data.length) offset += (0, import_node_fs26.writeSync)(fd, data, offset, data.length - offset);
27799
- (0, import_node_fs26.fchmodSync)(fd, mode);
27802
+ while (offset < data.length) offset += (0, import_node_fs27.writeSync)(fd, data, offset, data.length - offset);
27803
+ (0, import_node_fs27.fchmodSync)(fd, mode);
27800
27804
  if (owner && typeof process.getuid === "function" && process.getuid() === 0) {
27801
- (0, import_node_fs26.fchownSync)(fd, owner.uid, owner.gid);
27805
+ (0, import_node_fs27.fchownSync)(fd, owner.uid, owner.gid);
27802
27806
  }
27803
- (0, import_node_fs26.fsyncSync)(fd);
27804
- (0, import_node_fs26.closeSync)(fd);
27807
+ (0, import_node_fs27.fsyncSync)(fd);
27808
+ (0, import_node_fs27.closeSync)(fd);
27805
27809
  fd = void 0;
27806
- (0, import_node_fs26.renameSync)(temp, destination);
27810
+ (0, import_node_fs27.renameSync)(temp, destination);
27807
27811
  } catch (error) {
27808
27812
  if (fd !== void 0) {
27809
27813
  try {
27810
- (0, import_node_fs26.closeSync)(fd);
27814
+ (0, import_node_fs27.closeSync)(fd);
27811
27815
  } catch {
27812
27816
  }
27813
27817
  }
27814
27818
  try {
27815
- (0, import_node_fs26.unlinkSync)(temp);
27819
+ (0, import_node_fs27.unlinkSync)(temp);
27816
27820
  } catch {
27817
27821
  }
27818
27822
  throw error;
27819
27823
  } finally {
27820
- if (ownsDirFd) (0, import_node_fs26.closeSync)(dirFd);
27824
+ if (ownsDirFd) (0, import_node_fs27.closeSync)(dirFd);
27821
27825
  }
27822
27826
  }
27823
27827
  function readCurrentBackup(path) {
27824
27828
  let fd;
27825
27829
  try {
27826
- const parentFd = openDirectoryChain((0, import_node_path21.dirname)(path));
27830
+ const parentFd = openDirectoryChain((0, import_node_path22.dirname)(path));
27827
27831
  try {
27828
- fd = (0, import_node_fs26.openSync)(descriptorPath(parentFd, (0, import_node_path21.basename)(path)), import_node_fs26.constants.O_RDONLY | (import_node_fs26.constants.O_NOFOLLOW ?? 0));
27832
+ fd = (0, import_node_fs27.openSync)(descriptorPath(parentFd, (0, import_node_path22.basename)(path)), import_node_fs27.constants.O_RDONLY | (import_node_fs27.constants.O_NOFOLLOW ?? 0));
27829
27833
  } finally {
27830
- (0, import_node_fs26.closeSync)(parentFd);
27834
+ (0, import_node_fs27.closeSync)(parentFd);
27831
27835
  }
27832
- const stat = (0, import_node_fs26.fstatSync)(fd);
27836
+ const stat = (0, import_node_fs27.fstatSync)(fd);
27833
27837
  if (!stat.isFile() || stat.nlink !== 1 || stat.size > MAX_COMPRESSED_HISTORY_BYTES) return null;
27834
27838
  const compressed = readExact(fd, stat.size);
27835
- const after = (0, import_node_fs26.fstatSync)(fd);
27839
+ const after = (0, import_node_fs27.fstatSync)(fd);
27836
27840
  if (!compressed || after.size !== stat.size || after.mtimeMs !== stat.mtimeMs) return null;
27837
27841
  return (0, import_node_zlib.gunzipSync)(compressed, { maxOutputLength: MAX_HISTORY_BYTES });
27838
27842
  } catch {
27839
27843
  return null;
27840
27844
  } finally {
27841
- if (fd !== void 0) (0, import_node_fs26.closeSync)(fd);
27845
+ if (fd !== void 0) (0, import_node_fs27.closeSync)(fd);
27842
27846
  }
27843
27847
  }
27844
27848
  function compactTime(date) {
@@ -27850,7 +27854,7 @@ var CommandHistoryWatcher = class {
27850
27854
  this.pollMs = Math.max(1e4, opts.pollMs ?? POLL_MS2);
27851
27855
  this.now = opts.now ?? (() => /* @__PURE__ */ new Date());
27852
27856
  this.listAccounts = opts.listAccounts ?? historyAccounts;
27853
- this.root = (0, import_node_path21.join)(opts.stateDir, "command-history");
27857
+ this.root = (0, import_node_path22.join)(opts.stateDir, "command-history");
27854
27858
  }
27855
27859
  opts;
27856
27860
  timer = null;
@@ -27891,7 +27895,7 @@ var CommandHistoryWatcher = class {
27891
27895
  try {
27892
27896
  privateDirectory(this.root);
27893
27897
  for (const account of this.listAccounts()) {
27894
- if (!Number.isInteger(account.uid) || account.uid < 0 || !(0, import_node_path21.isAbsolute)(account.home)) continue;
27898
+ if (!Number.isInteger(account.uid) || account.uid < 0 || !(0, import_node_path22.isAbsolute)(account.home)) continue;
27895
27899
  const targets = this.targetsFor(account);
27896
27900
  for (const relative4 of targets) this.scanFile(account, relative4);
27897
27901
  }
@@ -27902,39 +27906,39 @@ var CommandHistoryWatcher = class {
27902
27906
  }
27903
27907
  }
27904
27908
  targetsFor(account) {
27905
- const targets = new Set(HISTORY_TARGETS[(0, import_node_path21.basename)(account.shell)] ?? []);
27909
+ const targets = new Set(HISTORY_TARGETS[(0, import_node_path22.basename)(account.shell)] ?? []);
27906
27910
  for (const relative4 of Object.values(HISTORY_TARGETS).flat()) {
27907
27911
  if (targets.has(relative4)) continue;
27908
- const path = (0, import_node_path21.join)(account.home, relative4);
27912
+ const path = (0, import_node_path22.join)(account.home, relative4);
27909
27913
  try {
27910
- (0, import_node_fs26.lstatSync)(path);
27914
+ (0, import_node_fs27.lstatSync)(path);
27911
27915
  targets.add(relative4);
27912
27916
  continue;
27913
27917
  } catch (error) {
27914
27918
  if (error.code !== "ENOENT") continue;
27915
27919
  }
27916
- const current = (0, import_node_path21.join)(this.root, String(account.uid), `${(0, import_node_path21.basename)(relative4)}.current.gz`);
27920
+ const current = (0, import_node_path22.join)(this.root, String(account.uid), `${(0, import_node_path22.basename)(relative4)}.current.gz`);
27917
27921
  if (readCurrentBackup(current) !== null) targets.add(relative4);
27918
27922
  }
27919
27923
  return [...targets];
27920
27924
  }
27921
27925
  scanFile(account, relative4) {
27922
- const path = (0, import_node_path21.join)(account.home, relative4);
27923
- const store = (0, import_node_path21.join)(this.root, String(account.uid), (0, import_node_path21.basename)(relative4));
27926
+ const path = (0, import_node_path22.join)(account.home, relative4);
27927
+ const store = (0, import_node_path22.join)(this.root, String(account.uid), (0, import_node_path22.basename)(relative4));
27924
27928
  const current = `${store}.current.gz`;
27925
27929
  let userParentFd;
27926
27930
  try {
27927
- userParentFd = openDirectoryChain((0, import_node_path21.dirname)(path));
27931
+ userParentFd = openDirectoryChain((0, import_node_path22.dirname)(path));
27928
27932
  } catch {
27929
- this.opts.log(`[command-history] skipped uid=${account.uid} ${(0, import_node_path21.basename)(relative4)} because its parent path is missing or not a real directory`);
27933
+ this.opts.log(`[command-history] skipped uid=${account.uid} ${(0, import_node_path22.basename)(relative4)} because its parent path is missing or not a real directory`);
27930
27934
  return;
27931
27935
  }
27932
27936
  try {
27933
- privateDirectory((0, import_node_path21.dirname)(store));
27934
- const userPath = descriptorPath(userParentFd, (0, import_node_path21.basename)(path));
27937
+ privateDirectory((0, import_node_path22.dirname)(store));
27938
+ const userPath = descriptorPath(userParentFd, (0, import_node_path22.basename)(path));
27935
27939
  let status;
27936
27940
  try {
27937
- status = (0, import_node_fs26.lstatSync)(userPath);
27941
+ status = (0, import_node_fs27.lstatSync)(userPath);
27938
27942
  } catch (error) {
27939
27943
  if (error.code !== "ENOENT") throw error;
27940
27944
  }
@@ -27949,7 +27953,7 @@ var CommandHistoryWatcher = class {
27949
27953
  } else if (!status) {
27950
27954
  this.restore(path, Buffer.alloc(0), account, userParentFd);
27951
27955
  }
27952
- const data = safeReadHistory(userParentFd, (0, import_node_path21.basename)(path), account.uid);
27956
+ const data = safeReadHistory(userParentFd, (0, import_node_path22.basename)(path), account.uid);
27953
27957
  if (data === null) return;
27954
27958
  const previous = backup;
27955
27959
  if (previous?.equals(data)) {
@@ -27962,9 +27966,9 @@ var CommandHistoryWatcher = class {
27962
27966
  atomicWrite(current, compressed);
27963
27967
  this.pruneSnapshots(store);
27964
27968
  } catch (error) {
27965
- this.opts.log(`[command-history] could not snapshot uid=${account.uid} ${(0, import_node_path21.basename)(relative4)}: ${error.message}`);
27969
+ this.opts.log(`[command-history] could not snapshot uid=${account.uid} ${(0, import_node_path22.basename)(relative4)}: ${error.message}`);
27966
27970
  } finally {
27967
- (0, import_node_fs26.closeSync)(userParentFd);
27971
+ (0, import_node_fs27.closeSync)(userParentFd);
27968
27972
  }
27969
27973
  }
27970
27974
  restore(path, content, account, parentFd) {
@@ -27977,22 +27981,22 @@ var CommandHistoryWatcher = class {
27977
27981
  module: "command-history",
27978
27982
  category: "system",
27979
27983
  severity: "medium",
27980
- message: `Shell history for ${name} (${(0, import_node_path21.basename)(relative4)}) was ${reason}; restored${hadBackup ? " from the latest backup" : " as an empty file"}`,
27981
- details: { uid: account.uid, account: name, history_file: (0, import_node_path21.basename)(relative4), action: "restored", reason, had_backup: hadBackup }
27984
+ message: `Shell history for ${name} (${(0, import_node_path22.basename)(relative4)}) was ${reason}; restored${hadBackup ? " from the latest backup" : " as an empty file"}`,
27985
+ details: { uid: account.uid, account: name, history_file: (0, import_node_path22.basename)(relative4), action: "restored", reason, had_backup: hadBackup }
27982
27986
  };
27983
27987
  this.opts.bus.publish(event);
27984
27988
  this.opts.log(`[command-history] ${event.message}`);
27985
27989
  }
27986
27990
  pruneSnapshots(current) {
27987
- const dir = (0, import_node_path21.dirname)(current);
27988
- const prefix = `${(0, import_node_path21.basename)(current).replace(/\.current\.gz$/, "")}.`;
27989
- const snapshots = (0, import_node_fs26.readdirSync)(dir).filter((name) => name !== (0, import_node_path21.basename)(current) && name.startsWith(prefix) && name.endsWith(".gz")).map((name) => ({ path: (0, import_node_path21.join)(dir, name), name, time: (0, import_node_fs26.lstatSync)((0, import_node_path21.join)(dir, name)).mtimeMs })).sort((a, b) => a.time - b.time);
27991
+ const dir = (0, import_node_path22.dirname)(current);
27992
+ const prefix = `${(0, import_node_path22.basename)(current).replace(/\.current\.gz$/, "")}.`;
27993
+ const snapshots = (0, import_node_fs27.readdirSync)(dir).filter((name) => name !== (0, import_node_path22.basename)(current) && name.startsWith(prefix) && name.endsWith(".gz")).map((name) => ({ path: (0, import_node_path22.join)(dir, name), name, time: (0, import_node_fs27.lstatSync)((0, import_node_path22.join)(dir, name)).mtimeMs })).sort((a, b) => a.time - b.time);
27990
27994
  const cutoff = this.now().getTime() - SNAPSHOT_RETENTION_MS;
27991
27995
  const removeCount = Math.max(0, snapshots.length - MAX_SNAPSHOTS);
27992
27996
  snapshots.forEach((snapshot, index) => {
27993
27997
  if (snapshot.time < cutoff || index < removeCount) {
27994
27998
  try {
27995
- (0, import_node_fs26.unlinkSync)(snapshot.path);
27999
+ (0, import_node_fs27.unlinkSync)(snapshot.path);
27996
28000
  } catch {
27997
28001
  }
27998
28002
  }
@@ -28001,14 +28005,14 @@ var CommandHistoryWatcher = class {
28001
28005
  };
28002
28006
 
28003
28007
  // src/daemon/workers/file-integrity.ts
28004
- var import_node_fs27 = require("fs");
28008
+ var import_node_fs28 = require("fs");
28005
28009
  var import_promises4 = require("fs/promises");
28006
28010
  var import_node_crypto8 = require("crypto");
28007
- var import_node_path23 = require("path");
28011
+ var import_node_path24 = require("path");
28008
28012
 
28009
28013
  // src/daemon/workers/writer-containment.ts
28010
28014
  var import_promises3 = require("fs/promises");
28011
- var import_node_path22 = require("path");
28015
+ var import_node_path23 = require("path");
28012
28016
  var realWriterProcFs = {
28013
28017
  async pids() {
28014
28018
  try {
@@ -28106,7 +28110,7 @@ var WriterContainment = class {
28106
28110
  if (info.pid <= 2 || info.ppid === 2) return true;
28107
28111
  if (info.pid === this.selfPid || info.pid === this.parentPid) return true;
28108
28112
  const path = stripDeleted(exe);
28109
- const names = [info.comm, (0, import_node_path22.basename)(path)];
28113
+ const names = [info.comm, (0, import_node_path23.basename)(path)];
28110
28114
  if (names.some((name) => name === "sshd" || name.startsWith("sshd-") || name.startsWith("systemd"))) return true;
28111
28115
  return this.opts.settings.neverContain.some((entry) => entry.endsWith("/") ? path.startsWith(entry) : path === entry);
28112
28116
  }
@@ -28123,7 +28127,7 @@ var WriterContainment = class {
28123
28127
  return report;
28124
28128
  }
28125
28129
  const exact = new Set(files.slice(0, MAX_MATCH_FILES));
28126
- const directories = [.../* @__PURE__ */ new Set([...files.map((file) => (0, import_node_path22.dirname)(file)), ...extraDirectories])].filter((dir) => dir !== "/").slice(0, MAX_MATCH_DIRECTORIES).map((dir) => dir.endsWith("/") ? dir : `${dir}/`);
28130
+ const directories = [.../* @__PURE__ */ new Set([...files.map((file) => (0, import_node_path23.dirname)(file)), ...extraDirectories])].filter((dir) => dir !== "/").slice(0, MAX_MATCH_DIRECTORIES).map((dir) => dir.endsWith("/") ? dir : `${dir}/`);
28127
28131
  if (files.length > MAX_MATCH_FILES) report.incomplete = true;
28128
28132
  const deadline = this.nowMs() + (this.opts.budgetMs ?? DEFAULT_BUDGET_MS);
28129
28133
  const exactHits = /* @__PURE__ */ new Map();
@@ -28227,7 +28231,7 @@ var WriterContainment = class {
28227
28231
  }
28228
28232
  };
28229
28233
  function summarizeContainment(report) {
28230
- const procs = report.processes.map((p) => `pid ${p.pid} (${(0, import_node_path22.basename)(p.exe) || p.comm})`).join(", ");
28234
+ const procs = report.processes.map((p) => `pid ${p.pid} (${(0, import_node_path23.basename)(p.exe) || p.comm})`).join(", ");
28231
28235
  switch (report.action) {
28232
28236
  case "contained":
28233
28237
  return `writer ${procs} ${report.mode === "kill" ? "killed (SIGKILL)" : "stopped (SIGSTOP)"}`;
@@ -28257,8 +28261,8 @@ var READ_CHUNK_BYTES = 64 * 1024;
28257
28261
  var CANARY_CONTENT = "ThreatCrush file integrity canary v1\n";
28258
28262
  function fileIntegritySettings(section) {
28259
28263
  const safePath = (value) => {
28260
- if (typeof value !== "string" || !(0, import_node_path23.isAbsolute)(value) || value.split(import_node_path23.sep).includes("..")) return null;
28261
- const path = (0, import_node_path23.normalize)(value);
28264
+ if (typeof value !== "string" || !(0, import_node_path24.isAbsolute)(value) || value.split(import_node_path24.sep).includes("..")) return null;
28265
+ const path = (0, import_node_path24.normalize)(value);
28262
28266
  return path === "/" ? null : path;
28263
28267
  };
28264
28268
  const strings = (values) => Array.isArray(values) ? [...new Set(values.map(safePath).filter((path) => path !== null))] : [];
@@ -28288,7 +28292,7 @@ async function readState(path) {
28288
28292
  }
28289
28293
  }
28290
28294
  async function writeState(path, state) {
28291
- await (0, import_promises4.mkdir)((0, import_node_path23.dirname)(path), { recursive: true, mode: 448 });
28295
+ await (0, import_promises4.mkdir)((0, import_node_path24.dirname)(path), { recursive: true, mode: 448 });
28292
28296
  const temp = `${path}.${process.pid}.${(0, import_node_crypto8.randomUUID)()}.tmp`;
28293
28297
  await (0, import_promises4.writeFile)(temp, JSON.stringify(state), { mode: 384 });
28294
28298
  await (0, import_promises4.rename)(temp, path);
@@ -28318,10 +28322,10 @@ var OPEN_FILE_FLAGS = import_promises4.constants.O_RDONLY | import_promises4.con
28318
28322
  var OPEN_DIR_FLAGS = OPEN_FILE_FLAGS | import_promises4.constants.O_DIRECTORY;
28319
28323
  var CREATE_FILE_FLAGS = import_promises4.constants.O_WRONLY | import_promises4.constants.O_CREAT | import_promises4.constants.O_EXCL | import_promises4.constants.O_NOFOLLOW;
28320
28324
  function autoCanaryPath(directory) {
28321
- return (0, import_node_path23.join)(directory, ".threatcrush-canary");
28325
+ return (0, import_node_path24.join)(directory, ".threatcrush-canary");
28322
28326
  }
28323
28327
  async function openAbsoluteDirectory(path) {
28324
- const parts = path.split(import_node_path23.sep).filter((part) => part && part !== ".");
28328
+ const parts = path.split(import_node_path24.sep).filter((part) => part && part !== ".");
28325
28329
  if (parts.includes("..")) throw new Error("invalid canary directory");
28326
28330
  let directory = await (0, import_promises4.open)("/", OPEN_DIR_FLAGS);
28327
28331
  try {
@@ -28344,9 +28348,9 @@ async function createAutoCanary(path) {
28344
28348
  } catch (error) {
28345
28349
  if (error.code !== "ENOENT") return false;
28346
28350
  }
28347
- const directory = await openAbsoluteDirectory((0, import_node_path23.dirname)(path));
28351
+ const directory = await openAbsoluteDirectory((0, import_node_path24.dirname)(path));
28348
28352
  try {
28349
- const file = await (0, import_promises4.open)(`/proc/self/fd/${directory.fd}/${(0, import_node_path23.basename)(path)}`, CREATE_FILE_FLAGS, 438);
28353
+ const file = await (0, import_promises4.open)(`/proc/self/fd/${directory.fd}/${(0, import_node_path24.basename)(path)}`, CREATE_FILE_FLAGS, 438);
28350
28354
  try {
28351
28355
  await file.chmod(438);
28352
28356
  await file.writeFile(CANARY_CONTENT);
@@ -28363,7 +28367,7 @@ async function createAutoCanary(path) {
28363
28367
  }
28364
28368
  }
28365
28369
  async function openAbsoluteTarget(path) {
28366
- const parts = path.split(import_node_path23.sep).filter((part) => part && part !== ".");
28370
+ const parts = path.split(import_node_path24.sep).filter((part) => part && part !== ".");
28367
28371
  if (parts.length === 0 || parts.includes("..")) throw new Error("invalid file integrity path");
28368
28372
  let directory = await (0, import_promises4.open)("/", OPEN_DIR_FLAGS);
28369
28373
  try {
@@ -28398,7 +28402,7 @@ async function scanTargets(targets, canaries) {
28398
28402
  }
28399
28403
  let handle;
28400
28404
  try {
28401
- handle = parent ? await (0, import_promises4.open)(`/proc/self/fd/${parent.fd}/${path.slice(path.lastIndexOf(import_node_path23.sep) + 1)}`, OPEN_FILE_FLAGS) : await openAbsoluteTarget(path);
28405
+ handle = parent ? await (0, import_promises4.open)(`/proc/self/fd/${parent.fd}/${path.slice(path.lastIndexOf(import_node_path24.sep) + 1)}`, OPEN_FILE_FLAGS) : await openAbsoluteTarget(path);
28402
28406
  const stat = await handle.stat();
28403
28407
  if (stat.isDirectory()) {
28404
28408
  directories.push(path);
@@ -28416,7 +28420,7 @@ async function scanTargets(targets, canaries) {
28416
28420
  return;
28417
28421
  }
28418
28422
  for (const entry of entries2) {
28419
- await walk((0, import_node_path23.join)(path, entry.name), handle);
28423
+ await walk((0, import_node_path24.join)(path, entry.name), handle);
28420
28424
  if (!complete) return;
28421
28425
  }
28422
28426
  return;
@@ -28564,7 +28568,7 @@ var FileIntegrityWatch = class {
28564
28568
  for (const path of wanted) {
28565
28569
  if (this.watchers.has(path)) continue;
28566
28570
  try {
28567
- const watcher = (0, import_node_fs27.watch)(path, { persistent: false }, () => {
28571
+ const watcher = (0, import_node_fs28.watch)(path, { persistent: false }, () => {
28568
28572
  this.scheduleEventScan();
28569
28573
  });
28570
28574
  watcher.on("error", (error) => {
@@ -28636,7 +28640,7 @@ var FileIntegrityWatch = class {
28636
28640
  if (current.complete) {
28637
28641
  const directories = new Set(current.directories);
28638
28642
  for (const path of Object.keys(current.files)) {
28639
- if (!directories.has(path)) directories.add((0, import_node_path23.dirname)(path));
28643
+ if (!directories.has(path)) directories.add((0, import_node_path24.dirname)(path));
28640
28644
  }
28641
28645
  this.refreshWatchers([...directories]);
28642
28646
  }
@@ -28761,15 +28765,15 @@ var FileIntegrityWatch = class {
28761
28765
  };
28762
28766
 
28763
28767
  // src/daemon/workers/edr.ts
28764
- var import_node_fs29 = require("fs");
28765
- var import_node_path25 = require("path");
28768
+ var import_node_fs30 = require("fs");
28769
+ var import_node_path26 = require("path");
28766
28770
  var import_node_child_process10 = require("child_process");
28767
28771
 
28768
28772
  // src/daemon/workers/edr-ebpf.ts
28769
28773
  var import_node_child_process9 = require("child_process");
28770
- var import_node_fs28 = require("fs");
28774
+ var import_node_fs29 = require("fs");
28771
28775
  var import_node_net11 = require("net");
28772
- var import_node_path24 = require("path");
28776
+ var import_node_path25 = require("path");
28773
28777
  var BPFTRACE_RECORD_TAG = "TC1";
28774
28778
  var BTF_VMLINUX_PATH = "/sys/kernel/btf/vmlinux";
28775
28779
  var TCP_SYN_SENT = 2;
@@ -28910,11 +28914,11 @@ function selectEdrSource(probe) {
28910
28914
  }
28911
28915
  var BPFTRACE_DIRS = ["/usr/sbin", "/usr/bin", "/sbin", "/bin", "/usr/local/sbin", "/usr/local/bin", "/snap/bin"];
28912
28916
  function findBpftrace(env2 = process.env) {
28913
- const dirs = [...BPFTRACE_DIRS, ...(env2.PATH ?? "").split(import_node_path24.delimiter).filter((dir) => dir.startsWith("/"))];
28917
+ const dirs = [...BPFTRACE_DIRS, ...(env2.PATH ?? "").split(import_node_path25.delimiter).filter((dir) => dir.startsWith("/"))];
28914
28918
  for (const dir of new Set(dirs)) {
28915
- const candidate = (0, import_node_path24.join)(dir, "bpftrace");
28919
+ const candidate = (0, import_node_path25.join)(dir, "bpftrace");
28916
28920
  try {
28917
- (0, import_node_fs28.accessSync)(candidate, import_node_fs28.constants.X_OK);
28921
+ (0, import_node_fs29.accessSync)(candidate, import_node_fs29.constants.X_OK);
28918
28922
  return candidate;
28919
28923
  } catch {
28920
28924
  }
@@ -28925,11 +28929,12 @@ function probeHost(configured) {
28925
28929
  return {
28926
28930
  configured,
28927
28931
  bpftracePath: configured === "auditd" ? null : findBpftrace(),
28928
- btfPresent: (0, import_node_fs28.existsSync)(BTF_VMLINUX_PATH),
28932
+ btfPresent: (0, import_node_fs29.existsSync)(BTF_VMLINUX_PATH),
28929
28933
  isRoot: typeof process.getuid === "function" && process.getuid() === 0,
28930
28934
  platform: process.platform
28931
28935
  };
28932
28936
  }
28937
+ var BPFTRACE_ENV = { PATH: "/usr/sbin:/usr/bin:/sbin:/bin", LANG: "C" };
28933
28938
  var STDERR_TAIL = 2048;
28934
28939
  var HEALTHY_AFTER_MS = 3e4;
28935
28940
  var KILL_GRACE_MS = 3e3;
@@ -29040,7 +29045,7 @@ var BpftraceSource = class {
29040
29045
  child = this.spawnFn(this.opts.bpftracePath, bpftraceArgs({ network: this.opts.network, peers: this.opts.peers }), {
29041
29046
  stdio: ["ignore", "pipe", "pipe"],
29042
29047
  shell: false,
29043
- env: { PATH: "/usr/sbin:/usr/bin:/sbin:/bin", LANG: "C" }
29048
+ env: BPFTRACE_ENV
29044
29049
  });
29045
29050
  } catch (error) {
29046
29051
  this.onExit(null, null, error.message);
@@ -29110,8 +29115,8 @@ var SHELLS2 = /* @__PURE__ */ new Set(["sh", "bash", "dash", "zsh", "ksh", "fish
29110
29115
  var DOWNLOADERS = /* @__PURE__ */ new Set(["curl", "wget"]);
29111
29116
  var MINERS = /* @__PURE__ */ new Set(["xmrig", "minerd", "cpuminer", "cpuminer-multi", "kdevtmpfsi", "kinsing", "cryptonight"]);
29112
29117
  function safeAbsolutePath(value) {
29113
- if (typeof value !== "string" || !(0, import_node_path25.isAbsolute)(value) || value.split(import_node_path25.sep).includes("..")) return null;
29114
- const path = (0, import_node_path25.normalize)(value);
29118
+ if (typeof value !== "string" || !(0, import_node_path26.isAbsolute)(value) || value.split(import_node_path26.sep).includes("..")) return null;
29119
+ const path = (0, import_node_path26.normalize)(value);
29115
29120
  return path === "/" ? null : path;
29116
29121
  }
29117
29122
  function edrSettings(section) {
@@ -29160,7 +29165,7 @@ function parseAuditRecord(line) {
29160
29165
  serial: header[2],
29161
29166
  key: fields.key,
29162
29167
  executable,
29163
- comm: fields.comm ?? (0, import_node_path25.basename)(executable),
29168
+ comm: fields.comm ?? (0, import_node_path26.basename)(executable),
29164
29169
  euid,
29165
29170
  ...Number.isInteger(pid) && pid > 0 ? { pid } : {},
29166
29171
  ...Number.isInteger(ppid) && ppid > 0 ? { ppid } : {}
@@ -29172,7 +29177,7 @@ function accountNames2() {
29172
29177
  raw = (0, import_node_child_process10.execFileSync)("getent", ["passwd"], { encoding: "utf8", timeout: 5e3, stdio: ["ignore", "pipe", "ignore"] });
29173
29178
  } catch {
29174
29179
  try {
29175
- raw = (0, import_node_fs29.readFileSync)("/etc/passwd", "utf8");
29180
+ raw = (0, import_node_fs30.readFileSync)("/etc/passwd", "utf8");
29176
29181
  } catch {
29177
29182
  return /* @__PURE__ */ new Map();
29178
29183
  }
@@ -29190,7 +29195,7 @@ function pathWithin(path, root) {
29190
29195
  }
29191
29196
  function executableInWorldWritableDirectory(executable) {
29192
29197
  try {
29193
- return ((0, import_node_fs29.statSync)((0, import_node_path25.dirname)(executable)).mode & 2) !== 0;
29198
+ return ((0, import_node_fs30.statSync)((0, import_node_path26.dirname)(executable)).mode & 2) !== 0;
29194
29199
  } catch {
29195
29200
  return false;
29196
29201
  }
@@ -29209,7 +29214,7 @@ function ebpfEventToRecords(event, resolveExe, now = /* @__PURE__ */ new Date(),
29209
29214
  source: "ebpf",
29210
29215
  serial,
29211
29216
  executable,
29212
- comm: event.comm || (0, import_node_path25.basename)(executable),
29217
+ comm: event.comm || (0, import_node_path26.basename)(executable),
29213
29218
  euid: event.euid,
29214
29219
  pid: event.pid,
29215
29220
  ...event.ppid > 0 ? { ppid: event.ppid } : {}
@@ -29283,6 +29288,9 @@ var EdrWatch = class {
29283
29288
  onFatal: (failure) => {
29284
29289
  this.bpftrace = null;
29285
29290
  this.opts.log(`[edr] ${failure}; falling back to auditd`);
29291
+ if (/Missing CAP_(BPF|PERFMON)/.test(failure)) {
29292
+ this.opts.log("[edr] the service unit does not grant CAP_BPF and CAP_PERFMON: re-run `threatcrush install-service` with [edr] enabled, then restart the daemon");
29293
+ }
29286
29294
  this.startAuditd(`eBPF failed: ${failure}`);
29287
29295
  },
29288
29296
  log: this.opts.log
@@ -29294,13 +29302,13 @@ var EdrWatch = class {
29294
29302
  this.bpftrace.start();
29295
29303
  }
29296
29304
  startAuditd(reason) {
29297
- if (!(0, import_node_fs29.existsSync)(this.opts.settings.auditLogPath)) {
29305
+ if (!(0, import_node_fs30.existsSync)(this.opts.settings.auditLogPath)) {
29298
29306
  this.opts.log(`[edr] audit log not found at ${this.opts.settings.auditLogPath}; auditd detections are unavailable`);
29299
29307
  this.setSource("none", `${reason}; audit log not found at ${this.opts.settings.auditLogPath}`);
29300
29308
  return;
29301
29309
  }
29302
29310
  try {
29303
- (0, import_node_fs29.accessSync)(this.opts.settings.auditLogPath, import_node_fs29.constants.R_OK);
29311
+ (0, import_node_fs30.accessSync)(this.opts.settings.auditLogPath, import_node_fs30.constants.R_OK);
29304
29312
  this.tail = new LogTail(this.opts.settings.auditLogPath);
29305
29313
  this.timer = setInterval(() => this.poll(), this.opts.settings.pollMs);
29306
29314
  this.timer.unref?.();
@@ -29324,16 +29332,16 @@ var EdrWatch = class {
29324
29332
  };
29325
29333
  try {
29326
29334
  const temp = `${path}.${process.pid}.tmp`;
29327
- (0, import_node_fs29.writeFileSync)(temp, `${JSON.stringify(status)}
29335
+ (0, import_node_fs30.writeFileSync)(temp, `${JSON.stringify(status)}
29328
29336
  `, { mode: 420 });
29329
- (0, import_node_fs29.renameSync)(temp, path);
29337
+ (0, import_node_fs30.renameSync)(temp, path);
29330
29338
  } catch {
29331
29339
  }
29332
29340
  }
29333
29341
  resolveEbpfExe(event) {
29334
29342
  let exe = null;
29335
29343
  try {
29336
- exe = (0, import_node_fs29.readlinkSync)(`/proc/${event.pid}/exe`).replace(/ \(deleted\)$/, "");
29344
+ exe = (0, import_node_fs30.readlinkSync)(`/proc/${event.pid}/exe`).replace(/ \(deleted\)$/, "");
29337
29345
  } catch {
29338
29346
  }
29339
29347
  if (!exe && event.kind !== "exec") exe = this.ebpfExeCache.get(event.pid) ?? null;
@@ -29412,7 +29420,7 @@ var EdrWatch = class {
29412
29420
  this.opts.bus.publish(event);
29413
29421
  }
29414
29422
  classify(execution) {
29415
- const name = (0, import_node_path25.basename)(execution.executable).toLowerCase();
29423
+ const name = (0, import_node_path26.basename)(execution.executable).toLowerCase();
29416
29424
  const account = this.usersById.get(execution.euid) ?? String(execution.euid);
29417
29425
  let severity;
29418
29426
  let ruleId;
@@ -29476,7 +29484,7 @@ var EdrWatch = class {
29476
29484
  const path = this.opts.networkBaselinePath;
29477
29485
  if (!path) return;
29478
29486
  try {
29479
- const parsed = JSON.parse((0, import_node_fs29.readFileSync)(path, "utf8"));
29487
+ const parsed = JSON.parse((0, import_node_fs30.readFileSync)(path, "utf8"));
29480
29488
  if (Array.isArray(parsed)) {
29481
29489
  for (const value of parsed.slice(0, 1e4)) {
29482
29490
  if (typeof value === "string" && value.startsWith("/")) this.outboundExecutables.add(value);
@@ -29493,9 +29501,9 @@ var EdrWatch = class {
29493
29501
  if (!path) return;
29494
29502
  try {
29495
29503
  const temp = `${path}.${process.pid}.tmp`;
29496
- (0, import_node_fs29.writeFileSync)(temp, `${JSON.stringify([...this.outboundExecutables])}
29504
+ (0, import_node_fs30.writeFileSync)(temp, `${JSON.stringify([...this.outboundExecutables])}
29497
29505
  `, { mode: 384 });
29498
- (0, import_node_fs29.renameSync)(temp, path);
29506
+ (0, import_node_fs30.renameSync)(temp, path);
29499
29507
  this.baselineWriteFailed = false;
29500
29508
  } catch (error) {
29501
29509
  if (!this.baselineWriteFailed) this.opts.log(`[edr] could not persist outbound executable baseline: ${error.message.split("\n")[0]}`);
@@ -29516,7 +29524,7 @@ var EdrWatch = class {
29516
29524
  const current = /* @__PURE__ */ new Map();
29517
29525
  let pids;
29518
29526
  try {
29519
- pids = (0, import_node_fs29.readdirSync)("/proc");
29527
+ pids = (0, import_node_fs30.readdirSync)("/proc");
29520
29528
  } catch {
29521
29529
  return;
29522
29530
  }
@@ -29524,7 +29532,7 @@ var EdrWatch = class {
29524
29532
  if (!/^\d+$/.test(pid)) continue;
29525
29533
  const proc = `/proc/${pid}`;
29526
29534
  try {
29527
- const raw = (0, import_node_fs29.readFileSync)(`${proc}/stat`, "utf8");
29535
+ const raw = (0, import_node_fs30.readFileSync)(`${proc}/stat`, "utf8");
29528
29536
  const end = raw.lastIndexOf(")");
29529
29537
  if (end < 0) continue;
29530
29538
  const fields = raw.slice(end + 1).trim().split(/\s+/);
@@ -29532,10 +29540,10 @@ var EdrWatch = class {
29532
29540
  const systemTicks = Number(fields[12]);
29533
29541
  const startTicks = fields[19];
29534
29542
  if (!Number.isFinite(userTicks) || !Number.isFinite(systemTicks) || !startTicks) continue;
29535
- let executable = (0, import_node_fs29.readlinkSync)(`${proc}/exe`);
29543
+ let executable = (0, import_node_fs30.readlinkSync)(`${proc}/exe`);
29536
29544
  executable = executable.replace(/ \(deleted\)$/, "");
29537
29545
  if (!this.opts.settings.tempExecPaths.some((path) => pathWithin(executable, path))) continue;
29538
- const name = (0, import_node_path25.basename)(executable).toLowerCase();
29546
+ const name = (0, import_node_path26.basename)(executable).toLowerCase();
29539
29547
  if (MINERS.has(name)) continue;
29540
29548
  const key = `${pid}:${startTicks}`;
29541
29549
  const ticks = userTicks + systemTicks;
@@ -29571,8 +29579,8 @@ var EdrWatch = class {
29571
29579
  };
29572
29580
 
29573
29581
  // src/daemon/workers/ssh-intrusion.ts
29574
- var import_node_fs30 = require("fs");
29575
- var import_node_path26 = require("path");
29582
+ var import_node_fs31 = require("fs");
29583
+ var import_node_path27 = require("path");
29576
29584
  var import_node_child_process11 = require("child_process");
29577
29585
 
29578
29586
  // src/core/asn.ts
@@ -29766,32 +29774,32 @@ function parseKeyLoginsByFingerprint(text) {
29766
29774
  }
29767
29775
  function readJson2(path) {
29768
29776
  try {
29769
- return JSON.parse((0, import_node_fs30.readFileSync)(path, "utf-8"));
29777
+ return JSON.parse((0, import_node_fs31.readFileSync)(path, "utf-8"));
29770
29778
  } catch {
29771
29779
  return null;
29772
29780
  }
29773
29781
  }
29774
29782
  function writeJson2(path, value) {
29775
- (0, import_node_fs30.mkdirSync)((0, import_node_path26.dirname)(path), { recursive: true });
29776
- (0, import_node_fs30.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
29777
- (0, import_node_fs30.renameSync)(`${path}.tmp`, path);
29783
+ (0, import_node_fs31.mkdirSync)((0, import_node_path27.dirname)(path), { recursive: true });
29784
+ (0, import_node_fs31.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
29785
+ (0, import_node_fs31.renameSync)(`${path}.tmp`, path);
29778
29786
  }
29779
29787
  var fsIO2 = {
29780
29788
  readFile: (p) => {
29781
29789
  try {
29782
- return (0, import_node_fs30.readFileSync)(p, "utf-8");
29790
+ return (0, import_node_fs31.readFileSync)(p, "utf-8");
29783
29791
  } catch {
29784
29792
  return null;
29785
29793
  }
29786
29794
  },
29787
29795
  readDir: (p) => {
29788
29796
  try {
29789
- return (0, import_node_fs30.readdirSync)(p);
29797
+ return (0, import_node_fs31.readdirSync)(p);
29790
29798
  } catch {
29791
29799
  return null;
29792
29800
  }
29793
29801
  },
29794
- exists: (p) => (0, import_node_fs30.existsSync)(p)
29802
+ exists: (p) => (0, import_node_fs31.existsSync)(p)
29795
29803
  };
29796
29804
  function defaultRun4(cmd, args) {
29797
29805
  const res = (0, import_node_child_process11.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 6e4, maxBuffer: 64 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -29992,23 +30000,23 @@ var SshIntrusionWatch = class {
29992
30000
  };
29993
30001
 
29994
30002
  // src/daemon/key-directory.ts
29995
- var import_node_fs31 = require("fs");
30003
+ var import_node_fs32 = require("fs");
29996
30004
  var fsIO3 = {
29997
30005
  readFile: (p) => {
29998
30006
  try {
29999
- return (0, import_node_fs31.readFileSync)(p, "utf-8");
30007
+ return (0, import_node_fs32.readFileSync)(p, "utf-8");
30000
30008
  } catch {
30001
30009
  return null;
30002
30010
  }
30003
30011
  },
30004
30012
  readDir: (p) => {
30005
30013
  try {
30006
- return (0, import_node_fs31.readdirSync)(p);
30014
+ return (0, import_node_fs32.readdirSync)(p);
30007
30015
  } catch {
30008
30016
  return null;
30009
30017
  }
30010
30018
  },
30011
- exists: (p) => (0, import_node_fs31.existsSync)(p)
30019
+ exists: (p) => (0, import_node_fs32.existsSync)(p)
30012
30020
  };
30013
30021
  var KeyDirectory = class {
30014
30022
  constructor(io = fsIO3, now = Date.now, ttlMs = 3e5) {
@@ -30052,7 +30060,7 @@ function enrichLoginEvent(event, keys) {
30052
30060
  }
30053
30061
 
30054
30062
  // src/daemon/workers/lightning-watch.ts
30055
- var import_node_fs32 = require("fs");
30063
+ var import_node_fs33 = require("fs");
30056
30064
  var DEFAULT_CLN_LOGS = [
30057
30065
  "/home/lightning/.lightning/cln.log",
30058
30066
  "/root/.lightning/cln.log",
@@ -30108,9 +30116,9 @@ var LightningWatch = class {
30108
30116
  if (this.opts.enabled === false) return [];
30109
30117
  const found = [];
30110
30118
  for (const path of this.opts.paths?.length ? this.opts.paths : DEFAULT_CLN_LOGS) {
30111
- if (!(0, import_node_fs32.existsSync)(path)) continue;
30119
+ if (!(0, import_node_fs33.existsSync)(path)) continue;
30112
30120
  try {
30113
- (0, import_node_fs32.accessSync)(path, import_node_fs32.constants.R_OK);
30121
+ (0, import_node_fs33.accessSync)(path, import_node_fs33.constants.R_OK);
30114
30122
  } catch {
30115
30123
  continue;
30116
30124
  }
@@ -30145,12 +30153,12 @@ var LightningWatch = class {
30145
30153
  };
30146
30154
 
30147
30155
  // src/daemon/workers/docker-logs.ts
30148
- var import_node_fs34 = require("fs");
30156
+ var import_node_fs35 = require("fs");
30149
30157
  var import_node_http = require("http");
30150
30158
  var import_node_net13 = require("net");
30151
30159
 
30152
30160
  // src/daemon/workers/postgres-shell.ts
30153
- var import_node_fs33 = require("fs");
30161
+ var import_node_fs34 = require("fs");
30154
30162
  var DEFAULT_ALLOW_CMDLINE = [
30155
30163
  // Supabase's pgsodium reads its root key by running this script at startup.
30156
30164
  String.raw`^(?:\S*/)?(?:ba|da)?sh (?:-c )?(?:\S*/)?pgsodium_getkey(?:\.sh)?$`,
@@ -30294,28 +30302,28 @@ function shellLogDetector(cooldownMs = 6e4, now = Date.now) {
30294
30302
  var realProcFs = {
30295
30303
  pids: () => {
30296
30304
  try {
30297
- return (0, import_node_fs33.readdirSync)("/proc").filter((n) => /^\d+$/.test(n)).map(Number);
30305
+ return (0, import_node_fs34.readdirSync)("/proc").filter((n) => /^\d+$/.test(n)).map(Number);
30298
30306
  } catch {
30299
30307
  return [];
30300
30308
  }
30301
30309
  },
30302
30310
  stat: (pid) => {
30303
30311
  try {
30304
- return (0, import_node_fs33.readFileSync)(`/proc/${pid}/stat`, "utf-8");
30312
+ return (0, import_node_fs34.readFileSync)(`/proc/${pid}/stat`, "utf-8");
30305
30313
  } catch {
30306
30314
  return null;
30307
30315
  }
30308
30316
  },
30309
30317
  cmdline: (pid) => {
30310
30318
  try {
30311
- return (0, import_node_fs33.readFileSync)(`/proc/${pid}/cmdline`, "utf-8").replace(/\0+$/, "").replace(/\0/g, " ");
30319
+ return (0, import_node_fs34.readFileSync)(`/proc/${pid}/cmdline`, "utf-8").replace(/\0+$/, "").replace(/\0/g, " ");
30312
30320
  } catch {
30313
30321
  return null;
30314
30322
  }
30315
30323
  },
30316
30324
  cgroup: (pid) => {
30317
30325
  try {
30318
- return (0, import_node_fs33.readFileSync)(`/proc/${pid}/cgroup`, "utf-8");
30326
+ return (0, import_node_fs34.readFileSync)(`/proc/${pid}/cgroup`, "utf-8");
30319
30327
  } catch {
30320
30328
  return null;
30321
30329
  }
@@ -30674,7 +30682,7 @@ var DockerLogsWatch = class {
30674
30682
  start() {
30675
30683
  const { settings } = this.opts;
30676
30684
  if (!settings.enabled) return false;
30677
- if (!this.opts.deps && !(0, import_node_fs34.existsSync)(settings.socket)) return false;
30685
+ if (!this.opts.deps && !(0, import_node_fs35.existsSync)(settings.socket)) return false;
30678
30686
  this.opts.log(`[docker-logs] following containers named /${settings.namePattern.source}/ or with image /${settings.imagePattern.source}/ for Postgres auth failures`);
30679
30687
  void this.poll();
30680
30688
  this.timer = setInterval(() => {
@@ -30780,7 +30788,7 @@ var DockerLogsWatch = class {
30780
30788
  };
30781
30789
 
30782
30790
  // src/daemon/workers/login-watch.ts
30783
- var import_node_fs35 = require("fs");
30791
+ var import_node_fs36 = require("fs");
30784
30792
  var import_node_child_process12 = require("child_process");
30785
30793
  var import_node_net14 = require("net");
30786
30794
  var DEFAULT_SENSITIVE_GROUPS = ["sudo", "admin", "wheel", "docker"];
@@ -30896,7 +30904,7 @@ var realKillDeps = {
30896
30904
  },
30897
30905
  cmdline: (pid) => {
30898
30906
  try {
30899
- return (0, import_node_fs35.readFileSync)(`/proc/${pid}/cmdline`, "utf-8").replace(/\0+$/, "").replace(/\0/g, " ");
30907
+ return (0, import_node_fs36.readFileSync)(`/proc/${pid}/cmdline`, "utf-8").replace(/\0+$/, "").replace(/\0/g, " ");
30900
30908
  } catch {
30901
30909
  return null;
30902
30910
  }
@@ -30954,14 +30962,14 @@ function forcedCommandKeys(text) {
30954
30962
  var realKeyFileIO = {
30955
30963
  mtime: (p) => {
30956
30964
  try {
30957
- return (0, import_node_fs35.statSync)(p).mtimeMs;
30965
+ return (0, import_node_fs36.statSync)(p).mtimeMs;
30958
30966
  } catch {
30959
30967
  return null;
30960
30968
  }
30961
30969
  },
30962
30970
  read: (p) => {
30963
30971
  try {
30964
- return (0, import_node_fs35.readFileSync)(p, "utf-8");
30972
+ return (0, import_node_fs36.readFileSync)(p, "utf-8");
30965
30973
  } catch {
30966
30974
  return null;
30967
30975
  }
@@ -31015,8 +31023,8 @@ var LoginWatch = class {
31015
31023
  const users = new Set(this.opts.settings.sensitiveUsers);
31016
31024
  try {
31017
31025
  const { group, passwd } = this.opts.readAccounts?.() ?? {
31018
- group: (0, import_node_fs35.readFileSync)("/etc/group", "utf-8"),
31019
- passwd: (0, import_node_fs35.readFileSync)("/etc/passwd", "utf-8")
31026
+ group: (0, import_node_fs36.readFileSync)("/etc/group", "utf-8"),
31027
+ passwd: (0, import_node_fs36.readFileSync)("/etc/passwd", "utf-8")
31020
31028
  };
31021
31029
  for (const u of groupMembers(group, passwd, this.opts.settings.sensitiveGroups)) users.add(u);
31022
31030
  } catch {
@@ -31052,7 +31060,7 @@ var LoginWatch = class {
31052
31060
  }
31053
31061
  passwdText() {
31054
31062
  try {
31055
- return this.opts.readAccounts ? this.opts.readAccounts().passwd : (0, import_node_fs35.readFileSync)("/etc/passwd", "utf-8");
31063
+ return this.opts.readAccounts ? this.opts.readAccounts().passwd : (0, import_node_fs36.readFileSync)("/etc/passwd", "utf-8");
31056
31064
  } catch {
31057
31065
  return "";
31058
31066
  }
@@ -31178,8 +31186,8 @@ var LoginWatch = class {
31178
31186
  };
31179
31187
 
31180
31188
  // src/core/tor-exits.ts
31181
- var import_node_fs36 = require("fs");
31182
- var import_node_path27 = require("path");
31189
+ var import_node_fs37 = require("fs");
31190
+ var import_node_path28 = require("path");
31183
31191
  var import_node_net15 = require("net");
31184
31192
  var TOR_BULK_EXIT_LIST_URL = "https://check.torproject.org/torbulkexitlist";
31185
31193
  function parseTorExitList(text) {
@@ -31251,10 +31259,10 @@ var TorExitList = class _TorExitList {
31251
31259
  }
31252
31260
  loadCache() {
31253
31261
  try {
31254
- if (!(0, import_node_fs36.existsSync)(this.opts.cachePath)) return false;
31255
- const parsed = parseTorExitList((0, import_node_fs36.readFileSync)(this.opts.cachePath, "utf-8"));
31262
+ if (!(0, import_node_fs37.existsSync)(this.opts.cachePath)) return false;
31263
+ const parsed = parseTorExitList((0, import_node_fs37.readFileSync)(this.opts.cachePath, "utf-8"));
31256
31264
  if (parsed.size === 0) return false;
31257
- this.load(parsed, (0, import_node_fs36.statSync)(this.opts.cachePath).mtimeMs);
31265
+ this.load(parsed, (0, import_node_fs37.statSync)(this.opts.cachePath).mtimeMs);
31258
31266
  this.log(`[tor] loaded ${parsed.size} Tor exit addresses from cache (${new Date(this.updatedAt).toISOString()})`);
31259
31267
  return true;
31260
31268
  } catch (err) {
@@ -31286,9 +31294,9 @@ var TorExitList = class _TorExitList {
31286
31294
  const before = this.exits.size;
31287
31295
  this.load(parsed);
31288
31296
  try {
31289
- (0, import_node_fs36.mkdirSync)((0, import_node_path27.dirname)(this.opts.cachePath), { recursive: true });
31290
- (0, import_node_fs36.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
31291
- (0, import_node_fs36.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
31297
+ (0, import_node_fs37.mkdirSync)((0, import_node_path28.dirname)(this.opts.cachePath), { recursive: true });
31298
+ (0, import_node_fs37.writeFileSync)(`${this.opts.cachePath}.tmp`, [...parsed].join("\n") + "\n");
31299
+ (0, import_node_fs37.renameSync)(`${this.opts.cachePath}.tmp`, this.opts.cachePath);
31292
31300
  } catch (err) {
31293
31301
  this.log(`[tor] could not save the exit list cache: ${err.message}`);
31294
31302
  }
@@ -31602,7 +31610,7 @@ var RuleEngine = class {
31602
31610
 
31603
31611
  // src/daemon/ssh-context/index.ts
31604
31612
  var import_node_os7 = require("os");
31605
- var import_node_path28 = require("path");
31613
+ var import_node_path29 = require("path");
31606
31614
 
31607
31615
  // ../../packages/event-detail/src/verdict.ts
31608
31616
  var RANK = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
@@ -31798,7 +31806,7 @@ var SshAuthHistory = class {
31798
31806
  };
31799
31807
 
31800
31808
  // src/daemon/ssh-context/authorized-keys.ts
31801
- var import_node_fs37 = require("fs");
31809
+ var import_node_fs38 = require("fs");
31802
31810
 
31803
31811
  // src/core/host-scan/parsers.ts
31804
31812
  var import_node_crypto9 = require("crypto");
@@ -31907,21 +31915,21 @@ function parsePasswd(text) {
31907
31915
  var realKeyFilesIO = {
31908
31916
  passwd: () => {
31909
31917
  try {
31910
- return (0, import_node_fs37.readFileSync)("/etc/passwd", "utf-8");
31918
+ return (0, import_node_fs38.readFileSync)("/etc/passwd", "utf-8");
31911
31919
  } catch {
31912
31920
  return "";
31913
31921
  }
31914
31922
  },
31915
31923
  mtime: (p) => {
31916
31924
  try {
31917
- return (0, import_node_fs37.statSync)(p).mtimeMs;
31925
+ return (0, import_node_fs38.statSync)(p).mtimeMs;
31918
31926
  } catch {
31919
31927
  return null;
31920
31928
  }
31921
31929
  },
31922
31930
  read: (p) => {
31923
31931
  try {
31924
- return (0, import_node_fs37.readFileSync)(p, "utf-8");
31932
+ return (0, import_node_fs38.readFileSync)(p, "utf-8");
31925
31933
  } catch {
31926
31934
  return null;
31927
31935
  }
@@ -31996,7 +32004,7 @@ var AuthorizedKeysIndex = class {
31996
32004
  var import_node_net17 = require("net");
31997
32005
  var import_node_os6 = require("os");
31998
32006
  var import_node_dns2 = require("dns");
31999
- var import_node_fs38 = require("fs");
32007
+ var import_node_fs39 = require("fs");
32000
32008
  function list(entries2) {
32001
32009
  const b = new import_node_net17.BlockList();
32002
32010
  for (const [a, p, f] of entries2) b.addSubnet(a, p, f);
@@ -32054,7 +32062,7 @@ function rangesDeps(cacheFile) {
32054
32062
  },
32055
32063
  load: () => {
32056
32064
  try {
32057
- const v = JSON.parse((0, import_node_fs38.readFileSync)(cacheFile, "utf-8"));
32065
+ const v = JSON.parse((0, import_node_fs39.readFileSync)(cacheFile, "utf-8"));
32058
32066
  return typeof v.at === "number" && Array.isArray(v.cidrs) ? { at: v.at, cidrs: v.cidrs.map(String) } : null;
32059
32067
  } catch {
32060
32068
  return null;
@@ -32062,7 +32070,7 @@ function rangesDeps(cacheFile) {
32062
32070
  },
32063
32071
  save: (v) => {
32064
32072
  try {
32065
- (0, import_node_fs38.writeFileSync)(cacheFile, JSON.stringify(v), { mode: 420 });
32073
+ (0, import_node_fs39.writeFileSync)(cacheFile, JSON.stringify(v), { mode: 420 });
32066
32074
  } catch {
32067
32075
  }
32068
32076
  },
@@ -32268,7 +32276,7 @@ var SshLoginEnricher = class {
32268
32276
  const now = deps.now ?? Date.now;
32269
32277
  this.history = deps.history ?? new SshAuthHistory(now);
32270
32278
  this.keys = deps.keys ?? new AuthorizedKeysIndex();
32271
- this.ranges = deps.ranges ?? new GitHubActionsRanges(rangesDeps((0, import_node_path28.join)(deps.stateDir ?? ".", "github-actions-ranges.json")), settings.githubRanges);
32279
+ this.ranges = deps.ranges ?? new GitHubActionsRanges(rangesDeps((0, import_node_path29.join)(deps.stateDir ?? ".", "github-actions-ranges.json")), settings.githubRanges);
32272
32280
  this.net = deps.net ?? new NetLookup();
32273
32281
  this.sleep = deps.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
32274
32282
  this.host = deps.host ?? (0, import_node_os7.hostname)();
@@ -32351,8 +32359,8 @@ var SshLoginEnricher = class {
32351
32359
  };
32352
32360
 
32353
32361
  // src/daemon/rules/loader.ts
32354
- var import_node_fs39 = require("fs");
32355
- var import_node_path29 = require("path");
32362
+ var import_node_fs40 = require("fs");
32363
+ var import_node_path30 = require("path");
32356
32364
 
32357
32365
  // src/daemon/rules/default-rules.ts
32358
32366
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
@@ -33028,16 +33036,16 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
33028
33036
  function loadAllRules(customDir) {
33029
33037
  const rules = [...DEFAULT_RULES];
33030
33038
  const dir = customDir || RULES_DIR;
33031
- if ((0, import_node_fs39.existsSync)(dir)) {
33039
+ if ((0, import_node_fs40.existsSync)(dir)) {
33032
33040
  let files = [];
33033
33041
  try {
33034
- files = (0, import_node_fs39.readdirSync)(dir).filter((f) => f.endsWith(".json"));
33042
+ files = (0, import_node_fs40.readdirSync)(dir).filter((f) => f.endsWith(".json"));
33035
33043
  } catch (err) {
33036
33044
  console.warn(`[rules] cannot read ${dir}: ${err.message}; custom rules not loaded`);
33037
33045
  }
33038
33046
  for (const file of files) {
33039
33047
  try {
33040
- const raw = (0, import_node_fs39.readFileSync)((0, import_node_path29.join)(dir, file), "utf-8");
33048
+ const raw = (0, import_node_fs40.readFileSync)((0, import_node_path30.join)(dir, file), "utf-8");
33041
33049
  const parsed = JSON.parse(raw);
33042
33050
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
33043
33051
  for (const rule of customRules) {
@@ -33069,8 +33077,8 @@ function loadAllRules(customDir) {
33069
33077
 
33070
33078
  // src/daemon/firewall/adapters.ts
33071
33079
  var import_node_child_process15 = require("child_process");
33072
- var import_node_fs40 = require("fs");
33073
- var import_node_path30 = require("path");
33080
+ var import_node_fs41 = require("fs");
33081
+ var import_node_path31 = require("path");
33074
33082
  var import_node_net18 = require("net");
33075
33083
  function assertValidFirewallIp(ip) {
33076
33084
  if ((0, import_node_net18.isIP)(ip) !== 4) {
@@ -33083,9 +33091,9 @@ function assertBannableIp(ip) {
33083
33091
  }
33084
33092
  }
33085
33093
  function writeIfAbsent(path, contents) {
33086
- (0, import_node_fs40.mkdirSync)((0, import_node_path30.dirname)(path), { recursive: true });
33094
+ (0, import_node_fs41.mkdirSync)((0, import_node_path31.dirname)(path), { recursive: true });
33087
33095
  try {
33088
- (0, import_node_fs40.writeFileSync)(path, contents, { flag: "wx" });
33096
+ (0, import_node_fs41.writeFileSync)(path, contents, { flag: "wx" });
33089
33097
  } catch (err) {
33090
33098
  if (err.code !== "EEXIST") throw err;
33091
33099
  }
@@ -33344,7 +33352,7 @@ function detectFirewallAdapter(backend = "auto") {
33344
33352
  }
33345
33353
 
33346
33354
  // src/daemon/firewall/remediation.ts
33347
- var import_node_fs41 = require("fs");
33355
+ var import_node_fs42 = require("fs");
33348
33356
  var import_node_child_process16 = require("child_process");
33349
33357
  var import_node_net19 = require("net");
33350
33358
 
@@ -33414,19 +33422,19 @@ var defaultDiscovery = {
33414
33422
  const snapshot = takeSnapshot({
33415
33423
  readFile: (p) => {
33416
33424
  try {
33417
- return (0, import_node_fs41.readFileSync)(p, "utf-8");
33425
+ return (0, import_node_fs42.readFileSync)(p, "utf-8");
33418
33426
  } catch {
33419
33427
  return null;
33420
33428
  }
33421
33429
  },
33422
33430
  readDir: (p) => {
33423
33431
  try {
33424
- return (0, import_node_fs41.readdirSync)(p);
33432
+ return (0, import_node_fs42.readdirSync)(p);
33425
33433
  } catch {
33426
33434
  return null;
33427
33435
  }
33428
33436
  },
33429
- exists: (p) => (0, import_node_fs41.existsSync)(p)
33437
+ exists: (p) => (0, import_node_fs42.existsSync)(p)
33430
33438
  });
33431
33439
  const out = /* @__PURE__ */ new Set();
33432
33440
  for (const keys of Object.values(snapshot.keys)) {
@@ -33939,7 +33947,7 @@ var RemediationManager = class {
33939
33947
  }
33940
33948
  logLine(line) {
33941
33949
  try {
33942
- (0, import_node_fs41.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
33950
+ (0, import_node_fs42.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
33943
33951
  `);
33944
33952
  } catch {
33945
33953
  }
@@ -33979,13 +33987,13 @@ function remediationSettings(section) {
33979
33987
  }
33980
33988
 
33981
33989
  // src/daemon/watchdog-service.ts
33982
- var import_node_fs43 = require("fs");
33983
- var import_node_path32 = require("path");
33990
+ var import_node_fs44 = require("fs");
33991
+ var import_node_path33 = require("path");
33984
33992
 
33985
33993
  // src/core/watchdog.ts
33986
- var import_node_fs42 = require("fs");
33994
+ var import_node_fs43 = require("fs");
33987
33995
  var import_node_crypto10 = require("crypto");
33988
- var import_node_path31 = require("path");
33996
+ var import_node_path32 = require("path");
33989
33997
  var WATCHDOG_DIRNAME = "watchdog";
33990
33998
  var LOG_FILE2 = "attacks.jsonl";
33991
33999
  var ROTATED_FILE = "attacks.1.jsonl";
@@ -34074,12 +34082,12 @@ var WatchdogLog = class {
34074
34082
  stats = { logged: 0, answered: 0, errored: 0 };
34075
34083
  constructor(dir, options = {}) {
34076
34084
  this.dir = dir;
34077
- this.file = (0, import_node_path31.join)(dir, LOG_FILE2);
34085
+ this.file = (0, import_node_path32.join)(dir, LOG_FILE2);
34078
34086
  this.shareGid = options.shareGid;
34079
- (0, import_node_fs42.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
34087
+ (0, import_node_fs43.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
34080
34088
  if (this.shareGid !== void 0) {
34081
- (0, import_node_fs42.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
34082
- (0, import_node_fs42.chmodSync)(dir, 1528);
34089
+ (0, import_node_fs43.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
34090
+ (0, import_node_fs43.chmodSync)(dir, 1528);
34083
34091
  }
34084
34092
  for (const r of readTail(this.file, 512 * 1024)) this.remember(dedupeKey(r));
34085
34093
  }
@@ -34108,16 +34116,16 @@ var WatchdogLog = class {
34108
34116
  const chunk = this.buffer.join("\n") + "\n";
34109
34117
  this.buffer = [];
34110
34118
  try {
34111
- if ((0, import_node_fs42.statSync)(this.file).size > ROTATE_BYTES) {
34112
- (0, import_node_fs42.renameSync)(this.file, (0, import_node_path31.join)(this.dir, ROTATED_FILE));
34119
+ if ((0, import_node_fs43.statSync)(this.file).size > ROTATE_BYTES) {
34120
+ (0, import_node_fs43.renameSync)(this.file, (0, import_node_path32.join)(this.dir, ROTATED_FILE));
34113
34121
  }
34114
34122
  } catch {
34115
34123
  }
34116
- (0, import_node_fs42.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
34124
+ (0, import_node_fs43.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
34117
34125
  if (this.shareGid !== void 0) {
34118
34126
  try {
34119
- (0, import_node_fs42.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
34120
- (0, import_node_fs42.chmodSync)(this.file, 432);
34127
+ (0, import_node_fs43.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
34128
+ (0, import_node_fs43.chmodSync)(this.file, 432);
34121
34129
  } catch {
34122
34130
  }
34123
34131
  }
@@ -34138,21 +34146,21 @@ function parseLines(text) {
34138
34146
  function readTail(file, bytes) {
34139
34147
  let fd;
34140
34148
  try {
34141
- fd = (0, import_node_fs42.openSync)(file, "r");
34149
+ fd = (0, import_node_fs43.openSync)(file, "r");
34142
34150
  } catch (err) {
34143
34151
  if (err.code === "ENOENT") return [];
34144
34152
  throw err;
34145
34153
  }
34146
34154
  try {
34147
- const size = (0, import_node_fs42.fstatSync)(fd).size;
34155
+ const size = (0, import_node_fs43.fstatSync)(fd).size;
34148
34156
  const start = Math.max(0, size - bytes);
34149
34157
  const buf = Buffer.alloc(size - start);
34150
- (0, import_node_fs42.readSync)(fd, buf, 0, buf.length, start);
34158
+ (0, import_node_fs43.readSync)(fd, buf, 0, buf.length, start);
34151
34159
  let text = buf.toString("utf8");
34152
34160
  if (start > 0) text = text.slice(text.indexOf("\n") + 1);
34153
34161
  return parseLines(text);
34154
34162
  } finally {
34155
- (0, import_node_fs42.closeSync)(fd);
34163
+ (0, import_node_fs43.closeSync)(fd);
34156
34164
  }
34157
34165
  }
34158
34166
 
@@ -34161,13 +34169,13 @@ function defaultShareGid() {
34161
34169
  const isRoot2 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
34162
34170
  if (!isRoot2) return void 0;
34163
34171
  try {
34164
- return (0, import_node_fs43.statSync)("/var/log/auth.log").gid;
34172
+ return (0, import_node_fs44.statSync)("/var/log/auth.log").gid;
34165
34173
  } catch {
34166
34174
  return void 0;
34167
34175
  }
34168
34176
  }
34169
34177
  function startWatchdog(opts) {
34170
- const dir = opts.config?.dir ?? (0, import_node_path32.join)(opts.stateDir, WATCHDOG_DIRNAME);
34178
+ const dir = opts.config?.dir ?? (0, import_node_path33.join)(opts.stateDir, WATCHDOG_DIRNAME);
34171
34179
  const base = { dir, logged: 0, answered: 0, errored: 0 };
34172
34180
  if (opts.config?.enabled === false) {
34173
34181
  opts.log("[watchdog] off ([watchdog] enabled = false)");
@@ -34274,7 +34282,7 @@ function daemonNodeProblem(version) {
34274
34282
  // src/daemon/index.ts
34275
34283
  function readVersion2() {
34276
34284
  try {
34277
- const pkg = JSON.parse((0, import_node_fs44.readFileSync)((0, import_node_path33.join)(__dirname, "..", "package.json"), "utf-8"));
34285
+ const pkg = JSON.parse((0, import_node_fs45.readFileSync)((0, import_node_path34.join)(__dirname, "..", "package.json"), "utf-8"));
34278
34286
  return pkg.version || "0.0.0";
34279
34287
  } catch {
34280
34288
  return "0.0.0";
@@ -34283,7 +34291,7 @@ function readVersion2() {
34283
34291
  async function runHardeningChecks() {
34284
34292
  const { stdout } = await (0, import_node_util.promisify)(import_node_child_process18.execFile)(
34285
34293
  process.execPath,
34286
- [(0, import_node_path33.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
34294
+ [(0, import_node_path34.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
34287
34295
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
34288
34296
  );
34289
34297
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -34297,7 +34305,7 @@ async function runHardeningChecks() {
34297
34305
  async function runPatchCheck() {
34298
34306
  const { stdout } = await (0, import_node_util.promisify)(import_node_child_process18.execFile)(
34299
34307
  process.execPath,
34300
- [(0, import_node_path33.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
34308
+ [(0, import_node_path34.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
34301
34309
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
34302
34310
  );
34303
34311
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -34305,7 +34313,7 @@ async function runPatchCheck() {
34305
34313
  }
34306
34314
  function logLine(line) {
34307
34315
  try {
34308
- (0, import_node_fs44.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
34316
+ (0, import_node_fs45.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
34309
34317
  `);
34310
34318
  } catch {
34311
34319
  }
@@ -34347,7 +34355,7 @@ async function runDaemon() {
34347
34355
  } catch (err) {
34348
34356
  logLine(`[daemon] state db unavailable: ${err.message}`);
34349
34357
  }
34350
- const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path33.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
34358
+ const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path34.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
34351
34359
  const config = loaded.config;
34352
34360
  if (loaded.error) {
34353
34361
  logLine(`[daemon] CONFIG ERROR: ${loaded.error}; ${loaded.usedLastGood ? "running on the last config that parsed" : "no earlier good copy, running on DEFAULTS (no protected list)"}`);
@@ -34428,7 +34436,7 @@ async function runDaemon() {
34428
34436
  const threatFeeds = new ThreatFeeds({
34429
34437
  settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
34430
34438
  enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
34431
- cachePath: (0, import_node_path33.join)(PATHS.stateDir, "threat-feeds.json"),
34439
+ cachePath: (0, import_node_path34.join)(PATHS.stateDir, "threat-feeds.json"),
34432
34440
  bus,
34433
34441
  log: logLine
34434
34442
  });
@@ -34436,9 +34444,9 @@ async function runDaemon() {
34436
34444
  const privilegeWatch = new PrivilegeWatch({
34437
34445
  settings: privilegeSettings(config.privileged),
34438
34446
  bus,
34439
- snapshotPath: (0, import_node_path33.join)(PATHS.stateDir, "privileges.json"),
34440
- loginsPath: (0, import_node_path33.join)(PATHS.stateDir, "login-countries.json"),
34441
- cursorPath: (0, import_node_path33.join)(PATHS.stateDir, "sudo-cursor.json"),
34447
+ snapshotPath: (0, import_node_path34.join)(PATHS.stateDir, "privileges.json"),
34448
+ loginsPath: (0, import_node_path34.join)(PATHS.stateDir, "login-countries.json"),
34449
+ cursorPath: (0, import_node_path34.join)(PATHS.stateDir, "sudo-cursor.json"),
34442
34450
  log: logLine
34443
34451
  });
34444
34452
  privilegeWatch.start();
@@ -34452,8 +34460,8 @@ async function runDaemon() {
34452
34460
  const fileIntegrity = new FileIntegrityWatch({
34453
34461
  bus,
34454
34462
  settings: fileIntegritySettings(config.file_integrity),
34455
- baselinePath: (0, import_node_path33.join)(PATHS.stateDir, "file-integrity-baseline.json"),
34456
- observedPath: (0, import_node_path33.join)(PATHS.stateDir, "file-integrity-observed.json"),
34463
+ baselinePath: (0, import_node_path34.join)(PATHS.stateDir, "file-integrity-baseline.json"),
34464
+ observedPath: (0, import_node_path34.join)(PATHS.stateDir, "file-integrity-observed.json"),
34457
34465
  // `[remediation] dry_run` also covers the opt-in contain_writer response.
34458
34466
  dryRun: () => remediation.status().dry_run,
34459
34467
  log: logLine
@@ -34462,8 +34470,8 @@ async function runDaemon() {
34462
34470
  const edr = new EdrWatch({
34463
34471
  bus,
34464
34472
  settings: edrSettings(config.edr),
34465
- networkBaselinePath: (0, import_node_path33.join)(PATHS.stateDir, "edr-outbound-executables.json"),
34466
- sourceStatusPath: (0, import_node_path33.join)(PATHS.stateDir, "edr-source.json"),
34473
+ networkBaselinePath: (0, import_node_path34.join)(PATHS.stateDir, "edr-outbound-executables.json"),
34474
+ sourceStatusPath: (0, import_node_path34.join)(PATHS.stateDir, "edr-source.json"),
34467
34475
  // Every traced connect is checked against the abuse.ch lists: this is what
34468
34476
  // sees a one-second download or a container calling out, which the
34469
34477
  // threat-feeds socket snapshot cannot.
@@ -34474,7 +34482,7 @@ async function runDaemon() {
34474
34482
  });
34475
34483
  edr.start();
34476
34484
  const torExits = new TorExitList({
34477
- cachePath: (0, import_node_path33.join)(PATHS.stateDir, "tor-exits.txt"),
34485
+ cachePath: (0, import_node_path34.join)(PATHS.stateDir, "tor-exits.txt"),
34478
34486
  url: config.remediation?.tor_exit_list_url,
34479
34487
  log: logLine
34480
34488
  });
@@ -34482,7 +34490,7 @@ async function runDaemon() {
34482
34490
  bus,
34483
34491
  manager: remediation,
34484
34492
  tor: torExits,
34485
- historyPath: (0, import_node_path33.join)(PATHS.stateDir, "key-logins.json"),
34493
+ historyPath: (0, import_node_path34.join)(PATHS.stateDir, "key-logins.json"),
34486
34494
  keyLoginWatch: config.privileged?.key_login_watch !== false,
34487
34495
  log: logLine
34488
34496
  });
@@ -34557,7 +34565,7 @@ async function runDaemon() {
34557
34565
  version,
34558
34566
  hostname: (0, import_node_os8.hostname)(),
34559
34567
  minSeverity,
34560
- spoolPath: (0, import_node_path33.join)(PATHS.stateDir, "cloud-spool.jsonl"),
34568
+ spoolPath: (0, import_node_path34.join)(PATHS.stateDir, "cloud-spool.jsonl"),
34561
34569
  log: logLine,
34562
34570
  ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
34563
34571
  runHardening: runHardeningChecks
@@ -34591,8 +34599,8 @@ async function runDaemon() {
34591
34599
  const autoUpdate = autoUpdateRef = new AutoUpdate({
34592
34600
  version,
34593
34601
  settings: updateSettings(config.update),
34594
- pkgRoot: (0, import_node_path33.join)(__dirname, ".."),
34595
- statePath: (0, import_node_path33.join)(PATHS.stateDir, "auto-update.json"),
34602
+ pkgRoot: (0, import_node_path34.join)(__dirname, ".."),
34603
+ statePath: (0, import_node_path34.join)(PATHS.stateDir, "auto-update.json"),
34596
34604
  bus,
34597
34605
  log: logLine,
34598
34606
  restartDaemon