@profullstack/threatcrush 0.13.58 → 0.13.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/daemon.js CHANGED
@@ -1643,20 +1643,20 @@ var require_parse_async = __commonJS({
1643
1643
  const index = 0;
1644
1644
  const blocksize = opts.blocksize || 40960;
1645
1645
  const parser = new TOMLParser();
1646
- return new Promise((resolve3, reject) => {
1647
- setImmediate(parseAsyncNext, index, blocksize, resolve3, reject);
1646
+ return new Promise((resolve4, reject) => {
1647
+ setImmediate(parseAsyncNext, index, blocksize, resolve4, reject);
1648
1648
  });
1649
- function parseAsyncNext(index2, blocksize2, resolve3, reject) {
1649
+ function parseAsyncNext(index2, blocksize2, resolve4, reject) {
1650
1650
  if (index2 >= str3.length) {
1651
1651
  try {
1652
- return resolve3(parser.finish());
1652
+ return resolve4(parser.finish());
1653
1653
  } catch (err) {
1654
1654
  return reject(prettyError(err, str3));
1655
1655
  }
1656
1656
  }
1657
1657
  try {
1658
1658
  parser.parse(str3.slice(index2, index2 + blocksize2));
1659
- setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2, resolve3, reject);
1659
+ setImmediate(parseAsyncNext, index2 + blocksize2, blocksize2, resolve4, reject);
1660
1660
  } catch (err) {
1661
1661
  reject(prettyError(err, str3));
1662
1662
  }
@@ -1682,7 +1682,7 @@ var require_parse_stream = __commonJS({
1682
1682
  function parseReadable(stm) {
1683
1683
  const parser = new TOMLParser();
1684
1684
  stm.setEncoding("utf8");
1685
- return new Promise((resolve3, reject) => {
1685
+ return new Promise((resolve4, reject) => {
1686
1686
  let readable;
1687
1687
  let ended = false;
1688
1688
  let errored = false;
@@ -1690,7 +1690,7 @@ var require_parse_stream = __commonJS({
1690
1690
  ended = true;
1691
1691
  if (readable) return;
1692
1692
  try {
1693
- resolve3(parser.finish());
1693
+ resolve4(parser.finish());
1694
1694
  } catch (err) {
1695
1695
  reject(err);
1696
1696
  }
@@ -2026,10 +2026,10 @@ var require_toml = __commonJS({
2026
2026
  });
2027
2027
 
2028
2028
  // src/daemon/index.ts
2029
- var import_node_fs30 = require("fs");
2029
+ var import_node_fs31 = require("fs");
2030
2030
  var import_node_child_process11 = require("child_process");
2031
2031
  var import_node_os5 = require("os");
2032
- var import_node_path23 = require("path");
2032
+ var import_node_path24 = require("path");
2033
2033
  var import_node_util = require("util");
2034
2034
 
2035
2035
  // src/daemon/paths.ts
@@ -2451,7 +2451,7 @@ var IpcServer = class {
2451
2451
  } catch {
2452
2452
  }
2453
2453
  }
2454
- return new Promise((resolve3, reject) => {
2454
+ return new Promise((resolve4, reject) => {
2455
2455
  this.server = (0, import_node_net.createServer)((sock) => this.handleClient(sock));
2456
2456
  this.server.on("error", reject);
2457
2457
  this.server.listen(PATHS.socket, () => {
@@ -2470,7 +2470,7 @@ var IpcServer = class {
2470
2470
  }
2471
2471
  }
2472
2472
  }
2473
- resolve3();
2473
+ resolve4();
2474
2474
  });
2475
2475
  });
2476
2476
  }
@@ -2482,20 +2482,20 @@ var IpcServer = class {
2482
2482
  }
2483
2483
  }
2484
2484
  this.clients.clear();
2485
- return new Promise((resolve3) => {
2485
+ return new Promise((resolve4) => {
2486
2486
  if (!this.server) {
2487
2487
  try {
2488
2488
  if ((0, import_node_fs4.existsSync)(PATHS.socket)) (0, import_node_fs4.unlinkSync)(PATHS.socket);
2489
2489
  } catch {
2490
2490
  }
2491
- return resolve3();
2491
+ return resolve4();
2492
2492
  }
2493
2493
  this.server.close(() => {
2494
2494
  try {
2495
2495
  if ((0, import_node_fs4.existsSync)(PATHS.socket)) (0, import_node_fs4.unlinkSync)(PATHS.socket);
2496
2496
  } catch {
2497
2497
  }
2498
- resolve3();
2498
+ resolve4();
2499
2499
  });
2500
2500
  });
2501
2501
  }
@@ -11553,6 +11553,12 @@ function slackChannel(webhookUrl) {
11553
11553
  };
11554
11554
  }
11555
11555
 
11556
+ // src/daemon/workers/runs-worker.ts
11557
+ var import_promises = require("dns/promises");
11558
+ var import_node_fs20 = require("fs");
11559
+ var import_node_net5 = require("net");
11560
+ var import_node_path14 = require("path");
11561
+
11556
11562
  // src/core/cli-config.ts
11557
11563
  var import_node_fs15 = require("fs");
11558
11564
  var import_node_path8 = require("path");
@@ -11648,6 +11654,106 @@ async function cloudFetch(path, init = {}) {
11648
11654
  return send();
11649
11655
  }
11650
11656
 
11657
+ // src/core/cloud-events.ts
11658
+ var import_node_crypto3 = require("crypto");
11659
+ var import_node_net4 = require("net");
11660
+ function currentLink() {
11661
+ if (!hasSession()) return null;
11662
+ const cfg = readCliConfig();
11663
+ if (!cfg.server_id || !cfg.server_org_id) return null;
11664
+ return { serverId: cfg.server_id, orgId: cfg.server_org_id };
11665
+ }
11666
+ var SEVERITY_RANK4 = {
11667
+ info: 0,
11668
+ low: 1,
11669
+ medium: 2,
11670
+ high: 3,
11671
+ critical: 4
11672
+ };
11673
+ var MAX_TITLE_CHARS = 300;
11674
+ var MAX_METADATA_BYTES = 16 * 1024;
11675
+ var MAX_STRING_CHARS = 1024;
11676
+ function jsonBytes(value) {
11677
+ try {
11678
+ return Buffer.byteLength(JSON.stringify(value) ?? "");
11679
+ } catch {
11680
+ return Infinity;
11681
+ }
11682
+ }
11683
+ function trimMetadata(meta) {
11684
+ const entries = [];
11685
+ for (const [key, value] of Object.entries(meta)) {
11686
+ if (value === void 0 || typeof value === "function") continue;
11687
+ const cut = typeof value === "string" && value.length > MAX_STRING_CHARS ? `${value.slice(0, MAX_STRING_CHARS)}\u2026` : value;
11688
+ if (jsonBytes(cut) === Infinity) continue;
11689
+ entries.push([key, cut]);
11690
+ }
11691
+ let out = Object.fromEntries(entries);
11692
+ let truncated = entries.length !== Object.keys(meta).length;
11693
+ if (jsonBytes(out) > MAX_METADATA_BYTES) {
11694
+ truncated = true;
11695
+ const bySize = [...entries].sort((a, b) => jsonBytes(a[1]) - jsonBytes(b[1]));
11696
+ while (bySize.length > 0 && jsonBytes({ ...Object.fromEntries(bySize), _truncated: true }) > MAX_METADATA_BYTES) {
11697
+ bySize.pop();
11698
+ }
11699
+ out = Object.fromEntries(bySize);
11700
+ }
11701
+ return truncated ? { ...out, _truncated: true } : out;
11702
+ }
11703
+ function str(value) {
11704
+ return typeof value === "string" && value ? value : void 0;
11705
+ }
11706
+ function detectionEvent(serverId, event) {
11707
+ const { rule_id, username, user, description, ...rest } = event.details ?? {};
11708
+ const title = event.module === "rule-engine" ? event.message.replace(/^\[DETECTION\]\s*/, "") : event.message;
11709
+ return {
11710
+ type: "detection",
11711
+ server_id: serverId,
11712
+ severity: event.severity,
11713
+ title: title.slice(0, MAX_TITLE_CHARS) || event.module,
11714
+ rule_id: str(rule_id) ?? event.module,
11715
+ description: str(description),
11716
+ source_ip: event.source_ip && (0, import_node_net4.isIP)(event.source_ip) ? event.source_ip : void 0,
11717
+ username: str(username) ?? str(user),
11718
+ raw_metadata: trimMetadata({ module: event.module, category: event.category, ...rest }),
11719
+ detected_at: event.timestamp.toISOString()
11720
+ };
11721
+ }
11722
+ function remediationEvent(serverId, event) {
11723
+ const d = event.details ?? {};
11724
+ if (d.action !== "block" && d.action !== "unblock") return null;
11725
+ if (d.origin === "cloud" || !event.source_ip) return null;
11726
+ const at = event.timestamp;
11727
+ const ttl = typeof d.ttl_seconds === "number" ? d.ttl_seconds : null;
11728
+ return {
11729
+ type: "remediation",
11730
+ server_id: serverId,
11731
+ event_id: (0, import_node_crypto3.randomUUID)(),
11732
+ action_type: d.action,
11733
+ target_value: event.source_ip,
11734
+ status: d.failed === true ? "failed" : "executed",
11735
+ rule_id: str(d.rule_id),
11736
+ reason: str(d.reason),
11737
+ error: str(d.error),
11738
+ dry_run: d.dry_run === true,
11739
+ executed_at: at.toISOString(),
11740
+ expires_at: d.action === "block" && ttl !== null && d.failed !== true ? new Date(at.getTime() + ttl * 1e3).toISOString() : null
11741
+ };
11742
+ }
11743
+ function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date()) {
11744
+ return results.map((r) => ({
11745
+ type: "hardening_finding",
11746
+ server_id: serverId,
11747
+ finding_key: r.key,
11748
+ status: r.status,
11749
+ severity: r.severity,
11750
+ title: r.title.slice(0, MAX_TITLE_CHARS),
11751
+ recommendation: r.recommendation,
11752
+ observed_at: observedAt.toISOString(),
11753
+ ...r.details ? { details: trimMetadata(r.details) } : {}
11754
+ }));
11755
+ }
11756
+
11651
11757
  // src/commands/scan.ts
11652
11758
  var import_node_fs19 = require("fs");
11653
11759
  var import_node_path13 = require("path");
@@ -15725,7 +15831,7 @@ async function queryOsv(name, version, ecosystem) {
15725
15831
  }
15726
15832
 
15727
15833
  // ../../packages/scan/src/node/sarif.ts
15728
- var import_node_crypto3 = require("crypto");
15834
+ var import_node_crypto4 = require("crypto");
15729
15835
  var import_node_path12 = require("path");
15730
15836
 
15731
15837
  // src/commands/scan.ts
@@ -15949,16 +16055,77 @@ async function collectPentestResults(targetUrl) {
15949
16055
  // src/daemon/workers/runs-worker.ts
15950
16056
  var POLL_INTERVAL_MS = 3e4;
15951
16057
  var SCHEDULE_INTERVAL_MS = 12e4;
16058
+ var NOT_PUBLIC = [
16059
+ ...DEFAULT_PROTECTED,
16060
+ "0.0.0.0/8",
16061
+ "100.64.0.0/10",
16062
+ "192.0.0.0/24",
16063
+ "198.18.0.0/15",
16064
+ "224.0.0.0/3",
16065
+ "::/128",
16066
+ "::ffff:0:0/96",
16067
+ "64:ff9b::/96",
16068
+ "ff00::/8"
16069
+ ];
16070
+ function isPublicTarget(ip) {
16071
+ return (0, import_node_net5.isIP)(ip) !== 0 && !isProtected(ip, NOT_PUBLIC);
16072
+ }
16073
+ async function pentestTargetError(rawUrl, resolveHost = async (h) => (await (0, import_promises.lookup)(h, { all: true })).map((a) => a.address)) {
16074
+ let url;
16075
+ try {
16076
+ url = new URL(rawUrl.startsWith("http") ? rawUrl : `https://${rawUrl}`);
16077
+ } catch {
16078
+ return `not a URL: ${rawUrl}`;
16079
+ }
16080
+ if (url.protocol !== "http:" && url.protocol !== "https:") return `not an http(s) URL: ${rawUrl}`;
16081
+ const host = url.hostname.replace(/^\[|\]$/g, "");
16082
+ let addresses;
16083
+ try {
16084
+ addresses = (0, import_node_net5.isIP)(host) ? [host] : await resolveHost(host);
16085
+ } catch (err) {
16086
+ return `cannot resolve ${host}: ${err.message}`;
16087
+ }
16088
+ if (addresses.length === 0) return `cannot resolve ${host}`;
16089
+ const inside = addresses.find((a) => !isPublicTarget(a));
16090
+ return inside ? `${host} resolves to ${inside}, which is not a public address; dashboard runs never reach inside this network` : null;
16091
+ }
16092
+ function scanTargetError(target, roots, real = import_node_fs20.realpathSync) {
16093
+ if (roots.length === 0) {
16094
+ return "dashboard scans of this machine are off; list the directories they may read in [cloud] run_scan_paths";
16095
+ }
16096
+ let path;
16097
+ try {
16098
+ path = real((0, import_node_path14.resolve)(target));
16099
+ } catch {
16100
+ return `no such path: ${target}`;
16101
+ }
16102
+ for (const root of roots) {
16103
+ let base;
16104
+ try {
16105
+ base = real((0, import_node_path14.resolve)(root));
16106
+ } catch {
16107
+ continue;
16108
+ }
16109
+ if (path === base || path.startsWith(base.endsWith(import_node_path14.sep) ? base : base + import_node_path14.sep)) return null;
16110
+ }
16111
+ return `${target} is outside [cloud] run_scan_paths`;
16112
+ }
15952
16113
  var RunsWorker = class {
15953
- constructor(bus2) {
16114
+ constructor(bus2, opts = { enabled: false, scanRoots: [] }) {
15954
16115
  this.bus = bus2;
16116
+ this.opts = opts;
15955
16117
  }
15956
16118
  bus;
16119
+ opts;
15957
16120
  pollTimer = null;
15958
16121
  scheduleTimer = null;
15959
16122
  running = false;
15960
16123
  orgIds = [];
15961
16124
  async start() {
16125
+ if (!this.opts.enabled) {
16126
+ this.opts.log?.("[runs] dashboard property runs off (set [cloud] runs = true to run them on this machine)");
16127
+ return;
16128
+ }
15962
16129
  if (!hasSession()) return;
15963
16130
  try {
15964
16131
  await this.refreshOrgs();
@@ -15980,7 +16147,7 @@ var RunsWorker = class {
15980
16147
  async scheduleTick() {
15981
16148
  if (!hasSession()) return;
15982
16149
  try {
15983
- if (this.orgIds.length === 0) await this.refreshOrgs();
16150
+ await this.refreshOrgs();
15984
16151
  for (const orgId of this.orgIds) {
15985
16152
  try {
15986
16153
  await cloudFetch(`/api/orgs/${orgId}/schedules/tick`, { method: "POST" });
@@ -15995,7 +16162,7 @@ var RunsWorker = class {
15995
16162
  if (!hasSession()) return;
15996
16163
  this.running = true;
15997
16164
  try {
15998
- if (this.orgIds.length === 0) await this.refreshOrgs();
16165
+ await this.refreshOrgs();
15999
16166
  for (const orgId of this.orgIds) {
16000
16167
  const claimed = await this.claimOne(orgId);
16001
16168
  if (!claimed) continue;
@@ -16007,11 +16174,10 @@ var RunsWorker = class {
16007
16174
  this.running = false;
16008
16175
  }
16009
16176
  }
16177
+ /** Only the org this server is linked to: never every org its user is in. */
16010
16178
  async refreshOrgs() {
16011
- const res = await cloudFetch("/api/orgs");
16012
- if (!res.ok) return;
16013
- const data = await res.json();
16014
- this.orgIds = (data.organizations || []).map((o) => o.id);
16179
+ const link = currentLink();
16180
+ this.orgIds = link ? [link.orgId] : [];
16015
16181
  }
16016
16182
  async claimOne(orgId) {
16017
16183
  try {
@@ -16038,6 +16204,18 @@ var RunsWorker = class {
16038
16204
  error: "property target missing"
16039
16205
  };
16040
16206
  }
16207
+ const refused = run.type === "scan" ? scanTargetError(target, this.opts.scanRoots) : await pentestTargetError(target);
16208
+ if (refused) {
16209
+ this.opts.log?.(`[runs] refused ${run.type} ${target}: ${refused}`);
16210
+ return {
16211
+ type: run.type,
16212
+ target,
16213
+ findings: [],
16214
+ severity_summary: { critical: 0, high: 0, medium: 0, low: 0, info: 0 },
16215
+ summary: `refused: ${refused}`,
16216
+ error: refused
16217
+ };
16218
+ }
16041
16219
  this.bus.announceModule("runs-worker", "running", `${run.type} ${run.property?.name || target}`);
16042
16220
  try {
16043
16221
  if (run.type === "scan") return await runScan(target);
@@ -16078,117 +16256,17 @@ var RunsWorker = class {
16078
16256
  }
16079
16257
  };
16080
16258
 
16081
- // src/core/cloud-events.ts
16082
- var import_node_crypto4 = require("crypto");
16083
- var import_node_net4 = require("net");
16084
- function currentLink() {
16085
- if (!hasSession()) return null;
16086
- const cfg = readCliConfig();
16087
- if (!cfg.server_id || !cfg.server_org_id) return null;
16088
- return { serverId: cfg.server_id, orgId: cfg.server_org_id };
16089
- }
16090
- var SEVERITY_RANK4 = {
16091
- info: 0,
16092
- low: 1,
16093
- medium: 2,
16094
- high: 3,
16095
- critical: 4
16096
- };
16097
- var MAX_TITLE_CHARS = 300;
16098
- var MAX_METADATA_BYTES = 16 * 1024;
16099
- var MAX_STRING_CHARS = 1024;
16100
- function jsonBytes(value) {
16101
- try {
16102
- return Buffer.byteLength(JSON.stringify(value) ?? "");
16103
- } catch {
16104
- return Infinity;
16105
- }
16106
- }
16107
- function trimMetadata(meta) {
16108
- const entries = [];
16109
- for (const [key, value] of Object.entries(meta)) {
16110
- if (value === void 0 || typeof value === "function") continue;
16111
- const cut = typeof value === "string" && value.length > MAX_STRING_CHARS ? `${value.slice(0, MAX_STRING_CHARS)}\u2026` : value;
16112
- if (jsonBytes(cut) === Infinity) continue;
16113
- entries.push([key, cut]);
16114
- }
16115
- let out = Object.fromEntries(entries);
16116
- let truncated = entries.length !== Object.keys(meta).length;
16117
- if (jsonBytes(out) > MAX_METADATA_BYTES) {
16118
- truncated = true;
16119
- const bySize = [...entries].sort((a, b) => jsonBytes(a[1]) - jsonBytes(b[1]));
16120
- while (bySize.length > 0 && jsonBytes({ ...Object.fromEntries(bySize), _truncated: true }) > MAX_METADATA_BYTES) {
16121
- bySize.pop();
16122
- }
16123
- out = Object.fromEntries(bySize);
16124
- }
16125
- return truncated ? { ...out, _truncated: true } : out;
16126
- }
16127
- function str(value) {
16128
- return typeof value === "string" && value ? value : void 0;
16129
- }
16130
- function detectionEvent(serverId, event) {
16131
- const { rule_id, username, user, description, ...rest } = event.details ?? {};
16132
- const title = event.module === "rule-engine" ? event.message.replace(/^\[DETECTION\]\s*/, "") : event.message;
16133
- return {
16134
- type: "detection",
16135
- server_id: serverId,
16136
- severity: event.severity,
16137
- title: title.slice(0, MAX_TITLE_CHARS) || event.module,
16138
- rule_id: str(rule_id) ?? event.module,
16139
- description: str(description),
16140
- source_ip: event.source_ip && (0, import_node_net4.isIP)(event.source_ip) ? event.source_ip : void 0,
16141
- username: str(username) ?? str(user),
16142
- raw_metadata: trimMetadata({ module: event.module, category: event.category, ...rest }),
16143
- detected_at: event.timestamp.toISOString()
16144
- };
16145
- }
16146
- function remediationEvent(serverId, event) {
16147
- const d = event.details ?? {};
16148
- if (d.action !== "block" && d.action !== "unblock") return null;
16149
- if (d.origin === "cloud" || !event.source_ip) return null;
16150
- const at = event.timestamp;
16151
- const ttl = typeof d.ttl_seconds === "number" ? d.ttl_seconds : null;
16152
- return {
16153
- type: "remediation",
16154
- server_id: serverId,
16155
- event_id: (0, import_node_crypto4.randomUUID)(),
16156
- action_type: d.action,
16157
- target_value: event.source_ip,
16158
- status: d.failed === true ? "failed" : "executed",
16159
- rule_id: str(d.rule_id),
16160
- reason: str(d.reason),
16161
- error: str(d.error),
16162
- dry_run: d.dry_run === true,
16163
- executed_at: at.toISOString(),
16164
- expires_at: d.action === "block" && ttl !== null && d.failed !== true ? new Date(at.getTime() + ttl * 1e3).toISOString() : null
16165
- };
16166
- }
16167
- function findingEvents(serverId, results, observedAt = /* @__PURE__ */ new Date()) {
16168
- return results.map((r) => ({
16169
- type: "hardening_finding",
16170
- server_id: serverId,
16171
- finding_key: r.key,
16172
- status: r.status,
16173
- severity: r.severity,
16174
- title: r.title.slice(0, MAX_TITLE_CHARS),
16175
- recommendation: r.recommendation,
16176
- observed_at: observedAt.toISOString(),
16177
- ...r.details ? { details: trimMetadata(r.details) } : {}
16178
- }));
16179
- }
16180
-
16181
16259
  // src/daemon/workers/cloud-spool.ts
16182
- var import_node_fs20 = require("fs");
16183
- var import_promises = require("fs/promises");
16184
- var import_node_path14 = require("path");
16260
+ var import_node_fs21 = require("fs");
16261
+ var import_promises2 = require("fs/promises");
16262
+ var import_node_path15 = require("path");
16185
16263
  var DEFAULT_SPOOL_LIMITS = { maxEvents: 1e4, maxBytes: 20 * 1024 * 1024 };
16186
16264
  var CloudSpool = class {
16187
16265
  constructor(path, limits = DEFAULT_SPOOL_LIMITS) {
16188
16266
  this.path = path;
16189
16267
  this.limits = limits;
16190
16268
  try {
16191
- (0, import_node_fs20.mkdirSync)((0, import_node_path14.dirname)(path), { recursive: true });
16269
+ (0, import_node_fs21.mkdirSync)((0, import_node_path15.dirname)(path), { recursive: true });
16192
16270
  } catch {
16193
16271
  }
16194
16272
  this.load();
@@ -16257,7 +16335,7 @@ var CloudSpool = class {
16257
16335
  load() {
16258
16336
  let raw;
16259
16337
  try {
16260
- raw = (0, import_node_fs20.readFileSync)(this.path, "utf-8");
16338
+ raw = (0, import_node_fs21.readFileSync)(this.path, "utf-8");
16261
16339
  } catch {
16262
16340
  return;
16263
16341
  }
@@ -16288,13 +16366,13 @@ var CloudSpool = class {
16288
16366
  const body = this.lines.length > 0 ? `${this.lines.join("\n")}
16289
16367
  ` : "";
16290
16368
  const tmp = `${this.path}.tmp`;
16291
- await (0, import_promises.writeFile)(tmp, body, { mode: 384 });
16292
- await (0, import_promises.rename)(tmp, this.path);
16369
+ await (0, import_promises2.writeFile)(tmp, body, { mode: 384 });
16370
+ await (0, import_promises2.rename)(tmp, this.path);
16293
16371
  } else if (this.pendingAppend.length > 0) {
16294
16372
  const chunk = `${this.pendingAppend.join("\n")}
16295
16373
  `;
16296
16374
  this.pendingAppend = [];
16297
- await (0, import_promises.appendFile)(this.path, chunk, { mode: 384 });
16375
+ await (0, import_promises2.appendFile)(this.path, chunk, { mode: 384 });
16298
16376
  }
16299
16377
  }).catch(() => {
16300
16378
  this.needsRewrite = true;
@@ -16498,7 +16576,7 @@ var CloudSync = class {
16498
16576
  var import_node_crypto5 = require("crypto");
16499
16577
 
16500
16578
  // src/daemon/workers/abuse-evidence.ts
16501
- var import_node_net5 = require("net");
16579
+ var import_node_net6 = require("net");
16502
16580
  var NEVER_REPORT_RANGES = [
16503
16581
  ...DEFAULT_PROTECTED,
16504
16582
  "100.64.0.0/10",
@@ -16574,7 +16652,7 @@ function summarizeEvidence(events) {
16574
16652
  };
16575
16653
  }
16576
16654
  function isReportable(ip, evidence, config, now = Date.now()) {
16577
- if ((0, import_node_net5.isIP)(ip) === 0) return { reportable: false, reason: "not an IP address" };
16655
+ if ((0, import_node_net6.isIP)(ip) === 0) return { reportable: false, reason: "not an IP address" };
16578
16656
  if (isProtected(ip, config.neverReport)) {
16579
16657
  return { reportable: false, reason: "address is in a never-report range (private/CGNAT/reserved/allowlisted)" };
16580
16658
  }
@@ -16723,31 +16801,31 @@ function resolveConfig(section) {
16723
16801
  }
16724
16802
 
16725
16803
  // src/core/abuse-report-log.ts
16726
- var import_node_fs21 = require("fs");
16727
- var import_node_path15 = require("path");
16804
+ var import_node_fs22 = require("fs");
16805
+ var import_node_path16 = require("path");
16728
16806
  var ABUSE_DIRNAME = "abuse-reports";
16729
16807
  var LOG_FILE = "reports.jsonl";
16730
16808
  function resolveAbuseDir(dir) {
16731
16809
  if (dir) return dir;
16732
16810
  if (process.env.THREATCRUSH_ABUSE_DIR) return process.env.THREATCRUSH_ABUSE_DIR;
16733
- const system = (0, import_node_path15.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
16734
- if ((0, import_node_fs21.existsSync)(system)) return system;
16735
- return (0, import_node_path15.join)(PATHS.stateDir, ABUSE_DIRNAME);
16811
+ const system = (0, import_node_path16.join)("/var/lib/threatcrush", ABUSE_DIRNAME);
16812
+ if ((0, import_node_fs22.existsSync)(system)) return system;
16813
+ return (0, import_node_path16.join)(PATHS.stateDir, ABUSE_DIRNAME);
16736
16814
  }
16737
16815
  function logPath(dir) {
16738
- return (0, import_node_path15.join)(resolveAbuseDir(dir), LOG_FILE);
16816
+ return (0, import_node_path16.join)(resolveAbuseDir(dir), LOG_FILE);
16739
16817
  }
16740
16818
  function appendReport(record, dir) {
16741
16819
  const path = logPath(dir);
16742
- (0, import_node_fs21.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
16743
- (0, import_node_fs21.appendFileSync)(path, `${JSON.stringify(record)}
16820
+ (0, import_node_fs22.mkdirSync)(resolveAbuseDir(dir), { recursive: true, mode: 493 });
16821
+ (0, import_node_fs22.appendFileSync)(path, `${JSON.stringify(record)}
16744
16822
  `, { mode: 420 });
16745
16823
  }
16746
16824
  function readReports(dir) {
16747
16825
  const path = logPath(dir);
16748
16826
  let raw;
16749
16827
  try {
16750
- raw = (0, import_node_fs21.readFileSync)(path, "utf-8");
16828
+ raw = (0, import_node_fs22.readFileSync)(path, "utf-8");
16751
16829
  } catch {
16752
16830
  return [];
16753
16831
  }
@@ -16905,18 +16983,25 @@ var AbuseReporter = class {
16905
16983
  };
16906
16984
 
16907
16985
  // src/daemon/workers/remediation-consumer.ts
16908
- var import_node_net7 = require("net");
16986
+ var import_node_net8 = require("net");
16909
16987
 
16910
16988
  // src/daemon/workers/allowlist-sync.ts
16911
- var import_node_net6 = require("net");
16989
+ var import_node_net7 = require("net");
16912
16990
  function isAddressOrCidr(value) {
16913
16991
  const [network, prefix, extra] = value.split("/");
16914
- const family = (0, import_node_net6.isIP)(network);
16992
+ const family = (0, import_node_net7.isIP)(network);
16915
16993
  if (family === 0 || extra !== void 0) return false;
16916
16994
  if (prefix === void 0) return true;
16917
16995
  if (!/^\d{1,3}$/.test(prefix)) return false;
16918
16996
  return Number(prefix) <= (family === 4 ? 32 : 128);
16919
16997
  }
16998
+ var CLOUD_MIN_PREFIX = { 4: 8, 6: 16 };
16999
+ function isCloudAllowEntry(value) {
17000
+ if (!isAddressOrCidr(value)) return false;
17001
+ const [network, prefix] = value.split("/");
17002
+ if (prefix === void 0) return true;
17003
+ return Number(prefix) >= CLOUD_MIN_PREFIX[(0, import_node_net7.isIP)(network)];
17004
+ }
16920
17005
  var AllowlistSync = class {
16921
17006
  constructor(manager, opts) {
16922
17007
  this.manager = manager;
@@ -16952,7 +17037,8 @@ var AllowlistSync = class {
16952
17037
  for (const entry of entries) {
16953
17038
  if (entry.type !== "ip" && entry.type !== "cidr") continue;
16954
17039
  const value = String(entry.value ?? "").trim();
16955
- if (isAddressOrCidr(value)) wanted.add(value);
17040
+ if (isCloudAllowEntry(value)) wanted.add(value);
17041
+ else if (isAddressOrCidr(value)) this.opts.log(`[cloud] org allowlist: ignoring ${value} (wider than /${CLOUD_MIN_PREFIX[(0, import_node_net7.isIP)(value.split("/")[0])]})`);
16956
17042
  }
16957
17043
  const added2 = [];
16958
17044
  const protectedNow = new Set(this.manager.getProtected());
@@ -17060,7 +17146,7 @@ var RemediationConsumer = class {
17060
17146
  try {
17061
17147
  switch (action.action_type) {
17062
17148
  case "block": {
17063
- if ((0, import_node_net7.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
17149
+ if ((0, import_node_net8.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
17064
17150
  let ttlSeconds = this.manager.status().max_ban_seconds;
17065
17151
  if (action.expires_at) {
17066
17152
  const until = Date.parse(action.expires_at);
@@ -17079,7 +17165,7 @@ var RemediationConsumer = class {
17079
17165
  return { status: "executed", dry_run: result.entry?.dry_run === true, executed_at };
17080
17166
  }
17081
17167
  case "unblock": {
17082
- if ((0, import_node_net7.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
17168
+ if ((0, import_node_net8.isIP)(target) === 0) return failed(`not an IP address: ${target}`);
17083
17169
  const wasBanned = this.manager.getBlocklist().some((b) => b.ip === target);
17084
17170
  const result = await this.manager.unban(target, {
17085
17171
  forget: true,
@@ -17092,13 +17178,16 @@ var RemediationConsumer = class {
17092
17178
  return { status: "executed", dry_run: this.manager.status().dry_run, executed_at };
17093
17179
  }
17094
17180
  case "allowlist_add":
17095
- if (!isAddressOrCidr(target)) return failed(`not an IP address or CIDR: ${target}`);
17181
+ if (!isCloudAllowEntry(target)) return failed(`not an IP address or CIDR the dashboard may protect: ${target}`);
17096
17182
  this.manager.addToAllowlist(target);
17097
17183
  return { status: "executed", executed_at };
17098
17184
  case "allowlist_remove":
17099
17185
  if (DEFAULT_PROTECTED.includes(target)) {
17100
17186
  return failed(`${target} is a built-in protected range and cannot be removed`);
17101
17187
  }
17188
+ if (this.manager.isPinned(target)) {
17189
+ return failed(`${target} is protected by this server's own configuration and cannot be removed from the dashboard`);
17190
+ }
17102
17191
  this.manager.removeFromAllowlist(target);
17103
17192
  return { status: "executed", executed_at };
17104
17193
  case "restart": {
@@ -17113,6 +17202,13 @@ var RemediationConsumer = class {
17113
17202
  }, 3e3).unref?.();
17114
17203
  return { status: "executed", executed_at };
17115
17204
  }
17205
+ case "update": {
17206
+ if (!this.opts.updateNow) return failed("update not supported by this daemon");
17207
+ this.opts.log("[cloud] dashboard requested an update");
17208
+ const outcome = await this.opts.updateNow();
17209
+ if (outcome.startsWith("updated to") || outcome.startsWith("up to date")) return { status: "executed", executed_at };
17210
+ return failed(outcome);
17211
+ }
17116
17212
  default:
17117
17213
  return failed(`unsupported action_type: ${action.action_type}`);
17118
17214
  }
@@ -17124,8 +17220,8 @@ var RemediationConsumer = class {
17124
17220
 
17125
17221
  // src/daemon/workers/auto-update.ts
17126
17222
  var import_node_child_process5 = require("child_process");
17127
- var import_node_fs22 = require("fs");
17128
- var import_node_path16 = require("path");
17223
+ var import_node_fs23 = require("fs");
17224
+ var import_node_path17 = require("path");
17129
17225
  var PKG_NAME = "@profullstack/threatcrush";
17130
17226
  var REGISTRY = `https://registry.npmjs.org/${PKG_NAME}`;
17131
17227
  var DEFAULT_INTERVAL_MS = 6 * 36e5;
@@ -17168,12 +17264,12 @@ function pickUpdate(doc, current, opts) {
17168
17264
  return { version: null, reason: `${latest} is younger than min_age, and nothing older is newer than ${current}; waiting` };
17169
17265
  }
17170
17266
  function installPlan(opts) {
17171
- const expected = `${import_node_path16.sep}lib${import_node_path16.sep}node_modules${import_node_path16.sep}@profullstack${import_node_path16.sep}threatcrush`;
17267
+ const expected = `${import_node_path17.sep}lib${import_node_path17.sep}node_modules${import_node_path17.sep}@profullstack${import_node_path17.sep}threatcrush`;
17172
17268
  if (!opts.pkgRoot.endsWith(expected)) {
17173
17269
  return { kind: "unsupported", reason: `not an npm global install (${opts.pkgRoot}); run \`threatcrush update\`` };
17174
17270
  }
17175
- const nodeBin = (0, import_node_path16.dirname)(opts.execPath);
17176
- const npm = (0, import_node_path16.join)(nodeBin, "npm");
17271
+ const nodeBin = (0, import_node_path17.dirname)(opts.execPath);
17272
+ const npm = (0, import_node_path17.join)(nodeBin, "npm");
17177
17273
  if (!opts.npmExists(npm)) return { kind: "unsupported", reason: `no npm beside ${opts.execPath}` };
17178
17274
  if (!opts.owner) return { kind: "unsupported", reason: `cannot tell who owns ${opts.pkgRoot}` };
17179
17275
  const npmArgs = [npm, "i", "-g", `${PKG_NAME}@${opts.version}`, "--no-fund", "--no-audit"];
@@ -17205,10 +17301,10 @@ function installPlan(opts) {
17205
17301
  }
17206
17302
  function ownerOf(path, passwd = "/etc/passwd") {
17207
17303
  try {
17208
- const st = (0, import_node_fs22.statSync)(path);
17304
+ const st = (0, import_node_fs23.statSync)(path);
17209
17305
  let home = st.uid === 0 ? "/root" : "";
17210
17306
  try {
17211
- for (const line of (0, import_node_fs22.readFileSync)(passwd, "utf8").split("\n")) {
17307
+ for (const line of (0, import_node_fs23.readFileSync)(passwd, "utf8").split("\n")) {
17212
17308
  const f = line.split(":");
17213
17309
  if (Number(f[2]) === st.uid && f[5]) home = f[5];
17214
17310
  }
@@ -17230,7 +17326,7 @@ function updateSettings(section, env2 = process.env) {
17230
17326
  };
17231
17327
  }
17232
17328
  function defaultRun(argv, env2) {
17233
- return new Promise((resolve3) => {
17329
+ return new Promise((resolve4) => {
17234
17330
  const child = (0, import_node_child_process5.spawn)(argv[0], argv.slice(1), {
17235
17331
  env: { ...process.env, ...env2 },
17236
17332
  stdio: ["ignore", "pipe", "pipe"]
@@ -17241,8 +17337,8 @@ function defaultRun(argv, env2) {
17241
17337
  };
17242
17338
  child.stdout?.on("data", keep);
17243
17339
  child.stderr?.on("data", keep);
17244
- child.on("error", (err) => resolve3({ code: -1, output: err.message }));
17245
- child.on("close", (code) => resolve3({ code: code ?? -1, output }));
17340
+ child.on("error", (err) => resolve4({ code: -1, output: err.message }));
17341
+ child.on("close", (code) => resolve4({ code: code ?? -1, output }));
17246
17342
  });
17247
17343
  }
17248
17344
  var AutoUpdate = class {
@@ -17279,8 +17375,13 @@ var AutoUpdate = class {
17279
17375
  }, ms);
17280
17376
  this.timer.unref?.();
17281
17377
  }
17282
- /** One check; returns what it did, for logs and tests. */
17283
- async check() {
17378
+ /**
17379
+ * One check; returns what it did, for logs and tests.
17380
+ * `force` is the dashboard's "Update now": no min_age wait and no
17381
+ * retry-after-a-day for a version that failed before. `restartDelayMs`
17382
+ * restarts that much later, so the action's result is reported first.
17383
+ */
17384
+ async check(opts = {}) {
17284
17385
  if (this.busy) return "busy";
17285
17386
  this.busy = true;
17286
17387
  try {
@@ -17297,13 +17398,13 @@ var AutoUpdate = class {
17297
17398
  }
17298
17399
  const pick = pickUpdate(doc, this.opts.version, {
17299
17400
  allowMajor: this.opts.settings.allowMajor,
17300
- minAgeMs: this.opts.settings.minAgeMs,
17401
+ minAgeMs: opts.force ? 0 : this.opts.settings.minAgeMs,
17301
17402
  now: this.now()
17302
17403
  });
17303
17404
  if (pick.version === null) return this.note(pick.reason, !pick.reason.startsWith("up to date"));
17304
17405
  const target = pick.version;
17305
17406
  const last = this.lastAttempt();
17306
- if (last?.version === target && this.now() - last.at < RETRY_AFTER_MS) {
17407
+ if (!opts.force && last?.version === target && this.now() - last.at < RETRY_AFTER_MS) {
17307
17408
  return this.note(`${target} was tried at ${new Date(last.at).toISOString()} and did not take; retrying after a day`);
17308
17409
  }
17309
17410
  const plan = installPlan({
@@ -17313,7 +17414,7 @@ var AutoUpdate = class {
17313
17414
  uid: process.getuid?.() ?? -1,
17314
17415
  owner: ownerOf(this.opts.pkgRoot),
17315
17416
  underSystemd: this.opts.underSystemd ?? Boolean(process.env.INVOCATION_ID),
17316
- npmExists: import_node_fs22.existsSync
17417
+ npmExists: import_node_fs23.existsSync
17317
17418
  });
17318
17419
  if (plan.kind === "unsupported") return this.note(`${target} is available but cannot self-install: ${plan.reason}`);
17319
17420
  this.recordAttempt(target);
@@ -17326,7 +17427,8 @@ var AutoUpdate = class {
17326
17427
  return this.note(`install of ${target} failed (exit ${code}): ${tail}`);
17327
17428
  }
17328
17429
  this.opts.log(`[update] ${target} installed; restarting onto it`);
17329
- this.opts.restartDaemon();
17430
+ if (opts.restartDelayMs) setTimeout(() => this.opts.restartDaemon(), opts.restartDelayMs).unref?.();
17431
+ else this.opts.restartDaemon();
17330
17432
  return `updated to ${target}`;
17331
17433
  } finally {
17332
17434
  this.busy = false;
@@ -17348,7 +17450,7 @@ var AutoUpdate = class {
17348
17450
  }
17349
17451
  lastAttempt() {
17350
17452
  try {
17351
- const v = JSON.parse((0, import_node_fs22.readFileSync)(this.opts.statePath, "utf8"));
17453
+ const v = JSON.parse((0, import_node_fs23.readFileSync)(this.opts.statePath, "utf8"));
17352
17454
  return v.version && typeof v.at === "number" ? { version: v.version, at: v.at } : null;
17353
17455
  } catch {
17354
17456
  return null;
@@ -17356,7 +17458,7 @@ var AutoUpdate = class {
17356
17458
  }
17357
17459
  recordAttempt(version) {
17358
17460
  try {
17359
- (0, import_node_fs22.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
17461
+ (0, import_node_fs23.writeFileSync)(this.opts.statePath, JSON.stringify({ version, at: this.now() }));
17360
17462
  } catch (err) {
17361
17463
  this.opts.log(`[update] could not record attempt: ${err.message}`);
17362
17464
  }
@@ -17365,9 +17467,9 @@ var AutoUpdate = class {
17365
17467
 
17366
17468
  // src/daemon/workers/threat-feeds.ts
17367
17469
  var import_node_child_process6 = require("child_process");
17368
- var import_node_fs23 = require("fs");
17369
- var import_node_path17 = require("path");
17370
- var import_node_net8 = require("net");
17470
+ var import_node_fs24 = require("fs");
17471
+ var import_node_path18 = require("path");
17472
+ var import_node_net9 = require("net");
17371
17473
  var EGRESS_TABLE = "threatcrush_egress";
17372
17474
  var DEFAULT_REFRESH_MS = 36e5;
17373
17475
  var POLL_MS = 15e3;
@@ -17385,8 +17487,8 @@ function threatFeedSettings(section) {
17385
17487
  };
17386
17488
  }
17387
17489
  function egressRuleset(ips) {
17388
- const v4 = ips.filter((ip) => (0, import_node_net8.isIP)(ip) === 4);
17389
- const v6 = ips.filter((ip) => (0, import_node_net8.isIP)(ip) === 6);
17490
+ const v4 = ips.filter((ip) => (0, import_node_net9.isIP)(ip) === 4);
17491
+ const v6 = ips.filter((ip) => (0, import_node_net9.isIP)(ip) === 6);
17390
17492
  const set = (name, type, items) => ` set ${name} { type ${type};${items.length ? ` elements = { ${items.join(", ")} }` : ""} }`;
17391
17493
  const chain = (name, hook) => [
17392
17494
  ` chain ${name} {`,
@@ -17411,7 +17513,7 @@ function splitAddr(addr) {
17411
17513
  const m = /^\[?(.+?)\]?:(\d+|\*)$/.exec(addr);
17412
17514
  if (!m) return null;
17413
17515
  const ip = m[1].replace(/%.*$/, "").replace(/^::ffff:/i, "");
17414
- return (0, import_node_net8.isIP)(ip) ? { ip, port: m[2] === "*" ? 0 : Number(m[2]) } : null;
17516
+ return (0, import_node_net9.isIP)(ip) ? { ip, port: m[2] === "*" ? 0 : Number(m[2]) } : null;
17415
17517
  }
17416
17518
  function parseSs(text) {
17417
17519
  const out = [];
@@ -17537,14 +17639,14 @@ var ThreatFeeds = class {
17537
17639
  */
17538
17640
  writeResolverFiles(set) {
17539
17641
  const domains = this.wantsDomainBlock ? Object.keys(set.domains).sort() : [];
17540
- const dir = this.opts.resolverDir ?? (0, import_node_path17.dirname)(this.opts.cachePath);
17642
+ const dir = this.opts.resolverDir ?? (0, import_node_path18.dirname)(this.opts.cachePath);
17541
17643
  const hooks = this.opts.resolverHooks ?? RESOLVER_HOOKS;
17542
17644
  const write = (name, content) => {
17543
- const path = (0, import_node_path17.join)(dir, name);
17645
+ const path = (0, import_node_path18.join)(dir, name);
17544
17646
  if (this.resolverWritten.get(name) === content) return false;
17545
17647
  try {
17546
- (0, import_node_fs23.writeFileSync)(`${path}.tmp`, content);
17547
- (0, import_node_fs23.renameSync)(`${path}.tmp`, path);
17648
+ (0, import_node_fs24.writeFileSync)(`${path}.tmp`, content);
17649
+ (0, import_node_fs24.renameSync)(`${path}.tmp`, path);
17548
17650
  this.resolverWritten.set(name, content);
17549
17651
  return true;
17550
17652
  } catch (err) {
@@ -17555,11 +17657,11 @@ var ThreatFeeds = class {
17555
17657
  const hostsChanged = write(RESOLVER_FILES.hosts, hostsBlocklist(domains));
17556
17658
  const unboundChanged = write(RESOLVER_FILES.unbound, unboundBlocklist(domains));
17557
17659
  const via = [];
17558
- if ((0, import_node_fs23.existsSync)(hooks.dnsmasq)) {
17660
+ if ((0, import_node_fs24.existsSync)(hooks.dnsmasq)) {
17559
17661
  via.push("dnsmasq");
17560
17662
  if (hostsChanged) this.run("systemctl", ["kill", "-s", "HUP", "dnsmasq.service"]);
17561
17663
  }
17562
- if ((0, import_node_fs23.existsSync)(hooks.unbound)) {
17664
+ if ((0, import_node_fs24.existsSync)(hooks.unbound)) {
17563
17665
  via.push("unbound");
17564
17666
  if (unboundChanged && this.run("unbound-control", ["reload"]) === null) {
17565
17667
  this.run("systemctl", ["reload", "unbound.service"]);
@@ -17620,8 +17722,8 @@ var ThreatFeeds = class {
17620
17722
  };
17621
17723
 
17622
17724
  // src/daemon/workers/privilege-watch.ts
17623
- var import_node_fs24 = require("fs");
17624
- var import_node_path18 = require("path");
17725
+ var import_node_fs25 = require("fs");
17726
+ var import_node_path19 = require("path");
17625
17727
  var import_node_child_process7 = require("child_process");
17626
17728
 
17627
17729
  // src/core/privileges/index.ts
@@ -17812,31 +17914,31 @@ function countryName(code) {
17812
17914
  var fsIO = {
17813
17915
  readFile: (p) => {
17814
17916
  try {
17815
- return (0, import_node_fs24.readFileSync)(p, "utf-8");
17917
+ return (0, import_node_fs25.readFileSync)(p, "utf-8");
17816
17918
  } catch {
17817
17919
  return null;
17818
17920
  }
17819
17921
  },
17820
17922
  readDir: (p) => {
17821
17923
  try {
17822
- return (0, import_node_fs24.readdirSync)(p);
17924
+ return (0, import_node_fs25.readdirSync)(p);
17823
17925
  } catch {
17824
17926
  return null;
17825
17927
  }
17826
17928
  },
17827
- exists: (p) => (0, import_node_fs24.existsSync)(p)
17929
+ exists: (p) => (0, import_node_fs25.existsSync)(p)
17828
17930
  };
17829
17931
  function readJson(path) {
17830
17932
  try {
17831
- return JSON.parse((0, import_node_fs24.readFileSync)(path, "utf-8"));
17933
+ return JSON.parse((0, import_node_fs25.readFileSync)(path, "utf-8"));
17832
17934
  } catch {
17833
17935
  return null;
17834
17936
  }
17835
17937
  }
17836
17938
  function writeJson(path, value) {
17837
- (0, import_node_fs24.mkdirSync)((0, import_node_path18.dirname)(path), { recursive: true });
17838
- (0, import_node_fs24.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
17839
- (0, import_node_fs24.renameSync)(`${path}.tmp`, path);
17939
+ (0, import_node_fs25.mkdirSync)((0, import_node_path19.dirname)(path), { recursive: true });
17940
+ (0, import_node_fs25.writeFileSync)(`${path}.tmp`, JSON.stringify(value));
17941
+ (0, import_node_fs25.renameSync)(`${path}.tmp`, path);
17840
17942
  }
17841
17943
  function defaultRun3(cmd, args) {
17842
17944
  const res = (0, import_node_child_process7.spawnSync)(cmd, args, { encoding: "utf-8", timeout: 2e4, maxBuffer: 16 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
@@ -17992,7 +18094,7 @@ var PrivilegeWatch = class {
17992
18094
  * raised a "new country" alert on its first run; on dev2 it did, at once.
17993
18095
  */
17994
18096
  async backfillLogins() {
17995
- if ((0, import_node_fs24.existsSync)(this.opts.loginsPath)) return;
18097
+ if ((0, import_node_fs25.existsSync)(this.opts.loginsPath)) return;
17996
18098
  const out = this.run("journalctl", ["_COMM=sshd", "_COMM=sshd-session", "--since=-30d", "-o", "cat", "--no-pager"]);
17997
18099
  const byUser = parseAcceptedLogins(out ?? "");
17998
18100
  const ips = [...new Set([...byUser.values()].flatMap((s) => [...s]))];
@@ -18005,7 +18107,7 @@ var PrivilegeWatch = class {
18005
18107
  return;
18006
18108
  }
18007
18109
  }
18008
- if ((0, import_node_fs24.existsSync)(this.opts.loginsPath)) return;
18110
+ if ((0, import_node_fs25.existsSync)(this.opts.loginsPath)) return;
18009
18111
  const at = this.now().toISOString();
18010
18112
  const history = {};
18011
18113
  for (const [user, userIps] of byUser) {
@@ -18217,8 +18319,8 @@ var RuleEngine = class {
18217
18319
  };
18218
18320
 
18219
18321
  // src/daemon/rules/loader.ts
18220
- var import_node_fs25 = require("fs");
18221
- var import_node_path19 = require("path");
18322
+ var import_node_fs26 = require("fs");
18323
+ var import_node_path20 = require("path");
18222
18324
 
18223
18325
  // src/daemon/rules/default-rules.ts
18224
18326
  var AT_CRS_THRESHOLD = { field: "severity", operator: "regex", value: "^(high|critical)$" };
@@ -18688,11 +18790,11 @@ var RULES_DIR = "/etc/threatcrush/rules.d";
18688
18790
  function loadAllRules(customDir) {
18689
18791
  const rules = [...DEFAULT_RULES];
18690
18792
  const dir = customDir || RULES_DIR;
18691
- if ((0, import_node_fs25.existsSync)(dir)) {
18692
- const files = (0, import_node_fs25.readdirSync)(dir).filter((f) => f.endsWith(".json"));
18793
+ if ((0, import_node_fs26.existsSync)(dir)) {
18794
+ const files = (0, import_node_fs26.readdirSync)(dir).filter((f) => f.endsWith(".json"));
18693
18795
  for (const file of files) {
18694
18796
  try {
18695
- const raw = (0, import_node_fs25.readFileSync)((0, import_node_path19.join)(dir, file), "utf-8");
18797
+ const raw = (0, import_node_fs26.readFileSync)((0, import_node_path20.join)(dir, file), "utf-8");
18696
18798
  const parsed = JSON.parse(raw);
18697
18799
  const customRules = Array.isArray(parsed) ? parsed : [parsed];
18698
18800
  for (const rule of customRules) {
@@ -18724,23 +18826,23 @@ function loadAllRules(customDir) {
18724
18826
 
18725
18827
  // src/daemon/firewall/adapters.ts
18726
18828
  var import_node_child_process8 = require("child_process");
18727
- var import_node_fs26 = require("fs");
18728
- var import_node_path20 = require("path");
18729
- var import_node_net9 = require("net");
18829
+ var import_node_fs27 = require("fs");
18830
+ var import_node_path21 = require("path");
18831
+ var import_node_net10 = require("net");
18730
18832
  function assertValidFirewallIp(ip) {
18731
- if ((0, import_node_net9.isIP)(ip) !== 4) {
18833
+ if ((0, import_node_net10.isIP)(ip) !== 4) {
18732
18834
  throw new Error(`Invalid IPv4 address: ${ip}`);
18733
18835
  }
18734
18836
  }
18735
18837
  function assertBannableIp(ip) {
18736
- if ((0, import_node_net9.isIP)(ip) === 0) {
18838
+ if ((0, import_node_net10.isIP)(ip) === 0) {
18737
18839
  throw new Error(`Invalid IP address: ${ip}`);
18738
18840
  }
18739
18841
  }
18740
18842
  function writeIfAbsent(path, contents) {
18741
- (0, import_node_fs26.mkdirSync)((0, import_node_path20.dirname)(path), { recursive: true });
18843
+ (0, import_node_fs27.mkdirSync)((0, import_node_path21.dirname)(path), { recursive: true });
18742
18844
  try {
18743
- (0, import_node_fs26.writeFileSync)(path, contents, { flag: "wx" });
18845
+ (0, import_node_fs27.writeFileSync)(path, contents, { flag: "wx" });
18744
18846
  } catch (err) {
18745
18847
  if (err.code !== "EEXIST") throw err;
18746
18848
  }
@@ -18839,7 +18941,7 @@ var Fail2banAdapter = class {
18839
18941
  const status = this.client(["status", this.jail]);
18840
18942
  const line = status.split("\n").find((l) => /Banned IP list:/i.test(l));
18841
18943
  if (!line) return [];
18842
- return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net9.isIP)(s) !== 0);
18944
+ return line.split(":").slice(1).join(":").trim().split(/\s+/).filter((s) => (0, import_node_net10.isIP)(s) !== 0);
18843
18945
  } catch {
18844
18946
  return [];
18845
18947
  }
@@ -18849,10 +18951,10 @@ var Fail2banAdapter = class {
18849
18951
  function parseBannedList(output) {
18850
18952
  const found = [];
18851
18953
  for (const match of output.matchAll(/['"]([^'"]+)['"]/g)) {
18852
- if ((0, import_node_net9.isIP)(match[1]) !== 0) found.push(match[1]);
18954
+ if ((0, import_node_net10.isIP)(match[1]) !== 0) found.push(match[1]);
18853
18955
  }
18854
18956
  if (found.length > 0) return found;
18855
- return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net9.isIP)(s) !== 0);
18957
+ return output.replace(/[[\],]/g, " ").split(/\s+/).filter((s) => (0, import_node_net10.isIP)(s) !== 0);
18856
18958
  }
18857
18959
  var NftablesAdapter = class {
18858
18960
  name = "nftables";
@@ -18999,9 +19101,9 @@ function detectFirewallAdapter(backend = "auto") {
18999
19101
  }
19000
19102
 
19001
19103
  // src/daemon/firewall/remediation.ts
19002
- var import_node_fs27 = require("fs");
19104
+ var import_node_fs28 = require("fs");
19003
19105
  var import_node_child_process9 = require("child_process");
19004
- var import_node_net10 = require("net");
19106
+ var import_node_net11 = require("net");
19005
19107
 
19006
19108
  // src/daemon/firewall/crawlers.ts
19007
19109
  var import_node_dns = require("dns");
@@ -19068,19 +19170,19 @@ var defaultDiscovery = {
19068
19170
  const snapshot = takeSnapshot({
19069
19171
  readFile: (p) => {
19070
19172
  try {
19071
- return (0, import_node_fs27.readFileSync)(p, "utf-8");
19173
+ return (0, import_node_fs28.readFileSync)(p, "utf-8");
19072
19174
  } catch {
19073
19175
  return null;
19074
19176
  }
19075
19177
  },
19076
19178
  readDir: (p) => {
19077
19179
  try {
19078
- return (0, import_node_fs27.readdirSync)(p);
19180
+ return (0, import_node_fs28.readdirSync)(p);
19079
19181
  } catch {
19080
19182
  return null;
19081
19183
  }
19082
19184
  },
19083
- exists: (p) => (0, import_node_fs27.existsSync)(p)
19185
+ exists: (p) => (0, import_node_fs28.existsSync)(p)
19084
19186
  });
19085
19187
  const out = /* @__PURE__ */ new Set();
19086
19188
  for (const keys of Object.values(snapshot.keys)) {
@@ -19088,12 +19190,12 @@ var defaultDiscovery = {
19088
19190
  }
19089
19191
  return out;
19090
19192
  },
19091
- keyLoginJournal: (sinceSeconds) => new Promise((resolve3) => {
19193
+ keyLoginJournal: (sinceSeconds) => new Promise((resolve4) => {
19092
19194
  (0, import_node_child_process9.execFile)(
19093
19195
  "journalctl",
19094
19196
  ["_COMM=sshd", "_COMM=sshd-session", `--since=-${Math.ceil(sinceSeconds / 86400)}d`, "-o", "short-unix", "--no-pager", "--grep", "Accepted publickey"],
19095
19197
  { maxBuffer: 32 * 1024 * 1024, timeout: 6e4 },
19096
- (_err, stdout) => resolve3(stdout ?? "")
19198
+ (_err, stdout) => resolve4(stdout ?? "")
19097
19199
  );
19098
19200
  })
19099
19201
  };
@@ -19128,6 +19230,7 @@ var RemediationManager = class {
19128
19230
  this.config.allowlist = [...this.config.allowlist];
19129
19231
  this.protectedList = [...DEFAULT_PROTECTED, ...SHARED_INFRASTRUCTURE, ...this.config.allowlist];
19130
19232
  for (const gateway of defaultGateways()) this.protectedList.push(gateway);
19233
+ this.pinned = new Set(this.protectedList);
19131
19234
  if (this.adapter.enforces === false) this.config.dry_run = true;
19132
19235
  this.loadState();
19133
19236
  this.refreshSshProtection();
@@ -19143,6 +19246,12 @@ var RemediationManager = class {
19143
19246
  blocklist = [];
19144
19247
  strikes = {};
19145
19248
  protectedList = [];
19249
+ /**
19250
+ * What was protected at start: built-ins, shared infrastructure, the
19251
+ * operator's `[remediation] allowlist`, default gateways. The dashboard may
19252
+ * add to the protected set but never take these out of it.
19253
+ */
19254
+ pinned = /* @__PURE__ */ new Set();
19146
19255
  /** Operator address → last time seen (ms), persisted. */
19147
19256
  operators = {};
19148
19257
  expiryTimer = null;
@@ -19215,7 +19324,7 @@ var RemediationManager = class {
19215
19324
  if (remediation?.action !== "block") return;
19216
19325
  }
19217
19326
  const ip = event.source_ip;
19218
- if (!ip || (0, import_node_net10.isIP)(ip) === 0) return;
19327
+ if (!ip || (0, import_node_net11.isIP)(ip) === 0) return;
19219
19328
  if (this.isAllowlisted(ip)) return;
19220
19329
  if (this.blocklist.some((b) => b.ip === ip)) return;
19221
19330
  if (this.config.spare_verified_crawlers) {
@@ -19234,7 +19343,7 @@ var RemediationManager = class {
19234
19343
  * 4th offence and so on, clamped to `max_ban_seconds`.
19235
19344
  */
19236
19345
  async ban(ip, reason, opts = {}) {
19237
- if ((0, import_node_net10.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
19346
+ if ((0, import_node_net11.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
19238
19347
  if (this.isAllowlisted(ip)) {
19239
19348
  return { ok: false, error: `${ip} is protected and can never be blocked` };
19240
19349
  }
@@ -19391,6 +19500,10 @@ var RemediationManager = class {
19391
19500
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
19392
19501
  if (!this.config.allowlist.includes(ip)) this.config.allowlist.push(ip);
19393
19502
  }
19503
+ /** Protected since start (built-in, shared infrastructure, operator config, gateway): not removable from the cloud. */
19504
+ isPinned(ip) {
19505
+ return this.pinned.has(ip);
19506
+ }
19394
19507
  removeFromAllowlist(ip) {
19395
19508
  if (DEFAULT_PROTECTED.includes(ip)) return;
19396
19509
  this.protectedList = this.protectedList.filter((a) => a !== ip);
@@ -19497,7 +19610,7 @@ var RemediationManager = class {
19497
19610
  if (saved && typeof saved === "object" && this.config.protect_recent_operators) {
19498
19611
  const cutoff = Date.now() - this.config.operator_memory_seconds * 1e3;
19499
19612
  for (const [ip, at] of Object.entries(saved)) {
19500
- if (typeof at !== "number" || at < cutoff || !(0, import_node_net10.isIP)(ip)) continue;
19613
+ if (typeof at !== "number" || at < cutoff || !(0, import_node_net11.isIP)(ip)) continue;
19501
19614
  this.operators[ip] = at;
19502
19615
  if (!this.protectedList.includes(ip)) this.protectedList.push(ip);
19503
19616
  }
@@ -19521,7 +19634,7 @@ var RemediationManager = class {
19521
19634
  }
19522
19635
  logLine(line) {
19523
19636
  try {
19524
- (0, import_node_fs27.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
19637
+ (0, import_node_fs28.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
19525
19638
  `);
19526
19639
  } catch {
19527
19640
  }
@@ -19560,13 +19673,13 @@ function remediationSettings(section) {
19560
19673
  }
19561
19674
 
19562
19675
  // src/daemon/watchdog-service.ts
19563
- var import_node_fs29 = require("fs");
19564
- var import_node_path22 = require("path");
19676
+ var import_node_fs30 = require("fs");
19677
+ var import_node_path23 = require("path");
19565
19678
 
19566
19679
  // src/core/watchdog.ts
19567
- var import_node_fs28 = require("fs");
19680
+ var import_node_fs29 = require("fs");
19568
19681
  var import_node_crypto7 = require("crypto");
19569
- var import_node_path21 = require("path");
19682
+ var import_node_path22 = require("path");
19570
19683
  var WATCHDOG_DIRNAME = "watchdog";
19571
19684
  var LOG_FILE2 = "attacks.jsonl";
19572
19685
  var ROTATED_FILE = "attacks.1.jsonl";
@@ -19655,12 +19768,12 @@ var WatchdogLog = class {
19655
19768
  stats = { logged: 0, answered: 0, errored: 0 };
19656
19769
  constructor(dir, options = {}) {
19657
19770
  this.dir = dir;
19658
- this.file = (0, import_node_path21.join)(dir, LOG_FILE2);
19771
+ this.file = (0, import_node_path22.join)(dir, LOG_FILE2);
19659
19772
  this.shareGid = options.shareGid;
19660
- (0, import_node_fs28.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
19773
+ (0, import_node_fs29.mkdirSync)(dir, { recursive: true, mode: this.shareGid === void 0 ? 448 : 1528 });
19661
19774
  if (this.shareGid !== void 0) {
19662
- (0, import_node_fs28.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
19663
- (0, import_node_fs28.chmodSync)(dir, 1528);
19775
+ (0, import_node_fs29.chownSync)(dir, process.getuid?.() ?? 0, this.shareGid);
19776
+ (0, import_node_fs29.chmodSync)(dir, 1528);
19664
19777
  }
19665
19778
  for (const r of readTail(this.file, 512 * 1024)) this.remember(dedupeKey(r));
19666
19779
  }
@@ -19689,16 +19802,16 @@ var WatchdogLog = class {
19689
19802
  const chunk = this.buffer.join("\n") + "\n";
19690
19803
  this.buffer = [];
19691
19804
  try {
19692
- if ((0, import_node_fs28.statSync)(this.file).size > ROTATE_BYTES) {
19693
- (0, import_node_fs28.renameSync)(this.file, (0, import_node_path21.join)(this.dir, ROTATED_FILE));
19805
+ if ((0, import_node_fs29.statSync)(this.file).size > ROTATE_BYTES) {
19806
+ (0, import_node_fs29.renameSync)(this.file, (0, import_node_path22.join)(this.dir, ROTATED_FILE));
19694
19807
  }
19695
19808
  } catch {
19696
19809
  }
19697
- (0, import_node_fs28.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
19810
+ (0, import_node_fs29.appendFileSync)(this.file, chunk, { mode: this.shareGid === void 0 ? 384 : 432 });
19698
19811
  if (this.shareGid !== void 0) {
19699
19812
  try {
19700
- (0, import_node_fs28.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
19701
- (0, import_node_fs28.chmodSync)(this.file, 432);
19813
+ (0, import_node_fs29.chownSync)(this.file, process.getuid?.() ?? 0, this.shareGid);
19814
+ (0, import_node_fs29.chmodSync)(this.file, 432);
19702
19815
  } catch {
19703
19816
  }
19704
19817
  }
@@ -19719,21 +19832,21 @@ function parseLines(text) {
19719
19832
  function readTail(file, bytes) {
19720
19833
  let fd;
19721
19834
  try {
19722
- fd = (0, import_node_fs28.openSync)(file, "r");
19835
+ fd = (0, import_node_fs29.openSync)(file, "r");
19723
19836
  } catch (err) {
19724
19837
  if (err.code === "ENOENT") return [];
19725
19838
  throw err;
19726
19839
  }
19727
19840
  try {
19728
- const size = (0, import_node_fs28.fstatSync)(fd).size;
19841
+ const size = (0, import_node_fs29.fstatSync)(fd).size;
19729
19842
  const start = Math.max(0, size - bytes);
19730
19843
  const buf = Buffer.alloc(size - start);
19731
- (0, import_node_fs28.readSync)(fd, buf, 0, buf.length, start);
19844
+ (0, import_node_fs29.readSync)(fd, buf, 0, buf.length, start);
19732
19845
  let text = buf.toString("utf8");
19733
19846
  if (start > 0) text = text.slice(text.indexOf("\n") + 1);
19734
19847
  return parseLines(text);
19735
19848
  } finally {
19736
- (0, import_node_fs28.closeSync)(fd);
19849
+ (0, import_node_fs29.closeSync)(fd);
19737
19850
  }
19738
19851
  }
19739
19852
 
@@ -19742,13 +19855,13 @@ function defaultShareGid() {
19742
19855
  const isRoot2 = process.platform === "linux" && typeof process.getuid === "function" && process.getuid() === 0;
19743
19856
  if (!isRoot2) return void 0;
19744
19857
  try {
19745
- return (0, import_node_fs29.statSync)("/var/log/auth.log").gid;
19858
+ return (0, import_node_fs30.statSync)("/var/log/auth.log").gid;
19746
19859
  } catch {
19747
19860
  return void 0;
19748
19861
  }
19749
19862
  }
19750
19863
  function startWatchdog(opts) {
19751
- const dir = opts.config?.dir ?? (0, import_node_path22.join)(opts.stateDir, WATCHDOG_DIRNAME);
19864
+ const dir = opts.config?.dir ?? (0, import_node_path23.join)(opts.stateDir, WATCHDOG_DIRNAME);
19752
19865
  const base = { dir, logged: 0, answered: 0, errored: 0 };
19753
19866
  if (opts.config?.enabled === false) {
19754
19867
  opts.log("[watchdog] off ([watchdog] enabled = false)");
@@ -19855,7 +19968,7 @@ function daemonNodeProblem(version) {
19855
19968
  // src/daemon/index.ts
19856
19969
  function readVersion2() {
19857
19970
  try {
19858
- const pkg = JSON.parse((0, import_node_fs30.readFileSync)((0, import_node_path23.join)(__dirname, "..", "package.json"), "utf-8"));
19971
+ const pkg = JSON.parse((0, import_node_fs31.readFileSync)((0, import_node_path24.join)(__dirname, "..", "package.json"), "utf-8"));
19859
19972
  return pkg.version || "0.0.0";
19860
19973
  } catch {
19861
19974
  return "0.0.0";
@@ -19864,7 +19977,7 @@ function readVersion2() {
19864
19977
  async function runHardeningChecks() {
19865
19978
  const { stdout } = await (0, import_node_util.promisify)(import_node_child_process11.execFile)(
19866
19979
  process.execPath,
19867
- [(0, import_node_path23.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
19980
+ [(0, import_node_path24.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
19868
19981
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
19869
19982
  );
19870
19983
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -19878,7 +19991,7 @@ async function runHardeningChecks() {
19878
19991
  async function runPatchCheck() {
19879
19992
  const { stdout } = await (0, import_node_util.promisify)(import_node_child_process11.execFile)(
19880
19993
  process.execPath,
19881
- [(0, import_node_path23.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
19994
+ [(0, import_node_path24.join)(__dirname, "index.js"), "patches", "--json", "--no-upload"],
19882
19995
  { timeout: 3e5, maxBuffer: 16 * 1024 * 1024 }
19883
19996
  );
19884
19997
  const parsed = JSON.parse(stdout.slice(stdout.indexOf("{")));
@@ -19886,7 +19999,7 @@ async function runPatchCheck() {
19886
19999
  }
19887
20000
  function logLine(line) {
19888
20001
  try {
19889
- (0, import_node_fs30.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
20002
+ (0, import_node_fs31.appendFileSync)(PATHS.logFile, `${(/* @__PURE__ */ new Date()).toISOString()} ${line}
19890
20003
  `);
19891
20004
  } catch {
19892
20005
  }
@@ -19928,7 +20041,7 @@ async function runDaemon() {
19928
20041
  } catch (err) {
19929
20042
  logLine(`[daemon] state db unavailable: ${err.message}`);
19930
20043
  }
19931
- const config = loadConfig((0, import_node_fs30.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
20044
+ const config = loadConfig((0, import_node_fs31.existsSync)(PATHS.configFile) ? PATHS.configFile : void 0);
19932
20045
  configureAttackDetection(config.detection);
19933
20046
  const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
19934
20047
  const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
@@ -19992,7 +20105,7 @@ async function runDaemon() {
19992
20105
  const threatFeeds = new ThreatFeeds({
19993
20106
  settings: { ...feedSettings, allow: [...feedSettings.allow, ...remediation.getAllowlist()] },
19994
20107
  enforcing: !remediationStatus.dry_run && firewallAdapter.enforces !== false,
19995
- cachePath: (0, import_node_path23.join)(PATHS.stateDir, "threat-feeds.json"),
20108
+ cachePath: (0, import_node_path24.join)(PATHS.stateDir, "threat-feeds.json"),
19996
20109
  bus,
19997
20110
  log: logLine
19998
20111
  });
@@ -20000,14 +20113,18 @@ async function runDaemon() {
20000
20113
  const privilegeWatch = new PrivilegeWatch({
20001
20114
  settings: privilegeSettings(config.privileged),
20002
20115
  bus,
20003
- snapshotPath: (0, import_node_path23.join)(PATHS.stateDir, "privileges.json"),
20004
- loginsPath: (0, import_node_path23.join)(PATHS.stateDir, "login-countries.json"),
20005
- cursorPath: (0, import_node_path23.join)(PATHS.stateDir, "sudo-cursor.json"),
20116
+ snapshotPath: (0, import_node_path24.join)(PATHS.stateDir, "privileges.json"),
20117
+ loginsPath: (0, import_node_path24.join)(PATHS.stateDir, "login-countries.json"),
20118
+ cursorPath: (0, import_node_path24.join)(PATHS.stateDir, "sudo-cursor.json"),
20006
20119
  log: logLine
20007
20120
  });
20008
20121
  privilegeWatch.start();
20009
20122
  new AlertDispatcher(bus, config);
20010
- const runsWorker = new RunsWorker(bus);
20123
+ const runsWorker = new RunsWorker(bus, {
20124
+ enabled: config.cloud?.enabled !== false && config.cloud?.runs === true,
20125
+ scanRoots: Array.isArray(config.cloud?.run_scan_paths) ? config.cloud.run_scan_paths.filter((p) => typeof p === "string") : [],
20126
+ log: logLine
20127
+ });
20011
20128
  try {
20012
20129
  await runsWorker.start();
20013
20130
  } catch (err) {
@@ -20015,6 +20132,7 @@ async function runDaemon() {
20015
20132
  }
20016
20133
  let cloudSync = null;
20017
20134
  let remediationConsumer = null;
20135
+ let autoUpdateRef = null;
20018
20136
  let allowlistSync = null;
20019
20137
  if (config.cloud?.enabled === false) {
20020
20138
  logLine("[cloud] disabled by [cloud] enabled = false");
@@ -20025,13 +20143,18 @@ async function runDaemon() {
20025
20143
  version,
20026
20144
  hostname: (0, import_node_os5.hostname)(),
20027
20145
  minSeverity,
20028
- spoolPath: (0, import_node_path23.join)(PATHS.stateDir, "cloud-spool.jsonl"),
20146
+ spoolPath: (0, import_node_path24.join)(PATHS.stateDir, "cloud-spool.jsonl"),
20029
20147
  log: logLine,
20030
20148
  ruleModules: new Set(ruleEngine.getRules().flatMap((rule) => rule.source_types)),
20031
20149
  runHardening: runHardeningChecks
20032
20150
  });
20033
20151
  cloudSync.start();
20034
- remediationConsumer = new RemediationConsumer(remediation, { log: logLine, restartDaemon });
20152
+ remediationConsumer = new RemediationConsumer(remediation, {
20153
+ log: logLine,
20154
+ restartDaemon,
20155
+ // autoUpdate is created below; the action only runs once polling starts.
20156
+ updateNow: () => autoUpdateRef ? autoUpdateRef.check({ force: true, restartDelayMs: 3e3 }) : Promise.resolve("updater not started")
20157
+ });
20035
20158
  remediationConsumer.start();
20036
20159
  allowlistSync = new AllowlistSync(remediation, { log: logLine });
20037
20160
  allowlistSync.start();
@@ -20041,11 +20164,11 @@ async function runDaemon() {
20041
20164
  const abuseReporter = new AbuseReporter({ bus, section: config.abuse_reporter, log: logLine });
20042
20165
  abuseReporter.start();
20043
20166
  const watchdog = startWatchdog({ bus, config: config.watchdog, stateDir: PATHS.stateDir, log: logLine });
20044
- const autoUpdate = new AutoUpdate({
20167
+ const autoUpdate = autoUpdateRef = new AutoUpdate({
20045
20168
  version,
20046
20169
  settings: updateSettings(config.update),
20047
- pkgRoot: (0, import_node_path23.join)(__dirname, ".."),
20048
- statePath: (0, import_node_path23.join)(PATHS.stateDir, "auto-update.json"),
20170
+ pkgRoot: (0, import_node_path24.join)(__dirname, ".."),
20171
+ statePath: (0, import_node_path24.join)(PATHS.stateDir, "auto-update.json"),
20049
20172
  bus,
20050
20173
  log: logLine,
20051
20174
  restartDaemon