@profullstack/threatcrush 0.13.12 → 0.13.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -12916,20 +12916,13 @@ var init_state = __esm({
12916
12916
  });
12917
12917
 
12918
12918
  // src/daemon/firewall/backoff.ts
12919
- function fibonacciMinutes(strike) {
12919
+ function backoffFactor(strike) {
12920
12920
  const n = Math.max(1, Math.floor(strike));
12921
- let prev = 1;
12922
- let curr = 1;
12923
- for (let i = 1; i < n; i++) {
12924
- const next = prev + curr;
12925
- prev = curr;
12926
- curr = next;
12927
- }
12928
- return curr;
12921
+ return 2 ** Math.min(n - 1, 52);
12929
12922
  }
12930
- function banSeconds(strike, maxSeconds) {
12931
- const seconds = fibonacciMinutes(strike) * 60;
12932
- return Math.min(seconds, Math.max(60, maxSeconds));
12923
+ function banSeconds(strike, maxSeconds, firstSeconds = DEFAULT_FIRST_BAN_SECONDS) {
12924
+ const first = Math.max(60, firstSeconds);
12925
+ return Math.min(first * backoffFactor(strike), Math.max(first, maxSeconds));
12933
12926
  }
12934
12927
  function recordStrike(strikes, ip, now, memorySeconds) {
12935
12928
  const existing = strikes[ip];
@@ -12964,9 +12957,11 @@ function formatDuration(seconds) {
12964
12957
  if (m > 0) return s > 0 && m < 10 ? `${m}m ${s}s` : `${m}m`;
12965
12958
  return `${s}s`;
12966
12959
  }
12960
+ var DEFAULT_FIRST_BAN_SECONDS;
12967
12961
  var init_backoff = __esm({
12968
12962
  "src/daemon/firewall/backoff.ts"() {
12969
12963
  "use strict";
12964
+ DEFAULT_FIRST_BAN_SECONDS = 5 * 60;
12970
12965
  }
12971
12966
  });
12972
12967
 
@@ -15911,10 +15906,10 @@ var source_default = chalk;
15911
15906
 
15912
15907
  // src/index.ts
15913
15908
  var import_readline = __toESM(require("readline"));
15914
- var import_node_child_process14 = require("child_process");
15915
- var import_node_fs35 = require("fs");
15909
+ var import_node_child_process15 = require("child_process");
15910
+ var import_node_fs36 = require("fs");
15916
15911
  var import_node_path24 = require("path");
15917
- var import_node_os9 = require("os");
15912
+ var import_node_os10 = require("os");
15918
15913
 
15919
15914
  // src/commands/monitor.ts
15920
15915
  var import_node_fs7 = require("fs");
@@ -28024,6 +28019,78 @@ function ask(question, opts = {}) {
28024
28019
  return stdinIsInteractive() ? askTerminal(question, mask) : askPiped(question, mask);
28025
28020
  }
28026
28021
 
28022
+ // src/core/link-login.ts
28023
+ var import_node_crypto3 = require("crypto");
28024
+ var import_node_os5 = require("os");
28025
+ function createPkce() {
28026
+ const verifier = (0, import_node_crypto3.randomBytes)(32).toString("base64url");
28027
+ const challenge = (0, import_node_crypto3.createHash)("sha256").update(verifier).digest("base64url");
28028
+ return { verifier, challenge };
28029
+ }
28030
+ async function startLinkLogin(pkce, deviceName = (0, import_node_os5.hostname)()) {
28031
+ const res = await fetch(`${apiUrl()}/api/auth/cli/start`, {
28032
+ method: "POST",
28033
+ headers: { "Content-Type": "application/json" },
28034
+ body: JSON.stringify({
28035
+ code_challenge: pkce.challenge,
28036
+ code_challenge_method: "S256",
28037
+ device_name: deviceName
28038
+ }),
28039
+ signal: AbortSignal.timeout(15e3)
28040
+ });
28041
+ const data = await res.json().catch(() => ({}));
28042
+ if (!res.ok || !data.request_id || !data.verification_url || !data.user_code) {
28043
+ throw new Error(data.error || `Could not start login (${res.status})`);
28044
+ }
28045
+ return data;
28046
+ }
28047
+ var sleep = (ms) => new Promise((resolve5) => setTimeout(resolve5, ms));
28048
+ async function waitForApproval(request, pkce, opts = {}) {
28049
+ const wait = opts.sleepMs ?? sleep;
28050
+ const now = opts.now ?? Date.now;
28051
+ const deadline = Date.parse(request.expires_at) || now() + 10 * 6e4;
28052
+ const intervalMs = Math.max(1, request.interval || 3) * 1e3;
28053
+ while (now() < deadline) {
28054
+ await wait(intervalMs);
28055
+ let res;
28056
+ try {
28057
+ res = await fetch(`${apiUrl()}/api/auth/cli/token`, {
28058
+ method: "POST",
28059
+ headers: { "Content-Type": "application/json" },
28060
+ body: JSON.stringify({ request_id: request.request_id, code_verifier: pkce.verifier }),
28061
+ signal: AbortSignal.timeout(15e3)
28062
+ });
28063
+ } catch {
28064
+ continue;
28065
+ }
28066
+ const data = await res.json().catch(() => ({}));
28067
+ if (res.ok && data.session?.access_token && data.user?.id) {
28068
+ updateCliConfig({
28069
+ email: data.user.email,
28070
+ user_id: data.user.id,
28071
+ token: data.session.access_token,
28072
+ refresh_token: data.session.refresh_token,
28073
+ expires_at: data.session.expires_at
28074
+ });
28075
+ return { ok: true, email: data.user.email || data.user.id, userId: data.user.id };
28076
+ }
28077
+ switch (data.error) {
28078
+ case "authorization_pending":
28079
+ continue;
28080
+ case "access_denied":
28081
+ return { ok: false, error: "The login was denied in the browser." };
28082
+ case "expired_token":
28083
+ return { ok: false, error: "The login link expired before it was approved." };
28084
+ case "invalid_grant":
28085
+ return { ok: false, error: "The login request is no longer valid. Run threatcrush login again." };
28086
+ default:
28087
+ if (res.status === 429 || res.status >= 500) continue;
28088
+ return { ok: false, error: data.error || `Login failed (${res.status})` };
28089
+ }
28090
+ }
28091
+ return { ok: false, error: "The login link expired before it was approved." };
28092
+ }
28093
+
28027
28094
  // src/commands/login.ts
28028
28095
  var API_URL = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
28029
28096
  var INPUT_CLOSED = {
@@ -28078,6 +28145,10 @@ async function loginCommand(opts = {}) {
28078
28145
  `));
28079
28146
  return;
28080
28147
  }
28148
+ if (!opts.password && !opts.email) {
28149
+ await linkLoginCommand();
28150
+ return;
28151
+ }
28081
28152
  console.log(source_default.green(" Log in to threatcrush.com"));
28082
28153
  console.log(source_default.gray(" " + "\u2500".repeat(40)));
28083
28154
  const result = await login({ email: opts.email });
@@ -28095,6 +28166,43 @@ async function loginCommand(opts = {}) {
28095
28166
  \u2713 Logged in as ${source_default.white(result.email)}`));
28096
28167
  console.log(source_default.dim(` Credentials saved to ${CLI_CONFIG_PATH}
28097
28168
  `));
28169
+ await rememberFirstOrg();
28170
+ }
28171
+ async function linkLoginCommand() {
28172
+ const pkce = createPkce();
28173
+ let request;
28174
+ try {
28175
+ request = await startLinkLogin(pkce);
28176
+ } catch (err) {
28177
+ console.log(source_default.red(` \u2717 ${err.message}
28178
+ `));
28179
+ process.exitCode = 1;
28180
+ return;
28181
+ }
28182
+ console.log(source_default.green(" Log in to threatcrush.com"));
28183
+ console.log(source_default.gray(" " + "\u2500".repeat(40)));
28184
+ console.log(` Open this link in a browser where you are signed in:
28185
+ `);
28186
+ console.log(` ${source_default.white.underline(request.verification_url)}
28187
+ `);
28188
+ console.log(` Check it shows this code: ${source_default.green.bold(request.user_code)}
28189
+ `);
28190
+ console.log(source_default.dim(" Waiting for approval\u2026 (Ctrl-C to cancel)"));
28191
+ const result = await waitForApproval(request, pkce);
28192
+ if (!result.ok) {
28193
+ console.log(source_default.red(`
28194
+ \u2717 ${result.error}
28195
+ `));
28196
+ process.exitCode = 1;
28197
+ return;
28198
+ }
28199
+ console.log(source_default.green(`
28200
+ \u2713 Logged in as ${source_default.white(result.email)}`));
28201
+ console.log(source_default.dim(` Credentials saved to ${CLI_CONFIG_PATH}
28202
+ `));
28203
+ await rememberFirstOrg();
28204
+ }
28205
+ async function rememberFirstOrg() {
28098
28206
  try {
28099
28207
  const res = await fetch(`${API_URL}/api/orgs`, { headers: authHeaders() });
28100
28208
  if (res.ok) {
@@ -28622,7 +28730,7 @@ var import_toml3 = __toESM(require_toml());
28622
28730
  init_paths();
28623
28731
 
28624
28732
  // src/daemon/module-trust.ts
28625
- var import_node_crypto3 = require("crypto");
28733
+ var import_node_crypto4 = require("crypto");
28626
28734
  var import_node_fs15 = require("fs");
28627
28735
  var import_node_path12 = require("path");
28628
28736
  init_paths();
@@ -28646,7 +28754,7 @@ function collectFiles(root, dir = root, out = []) {
28646
28754
  return out;
28647
28755
  }
28648
28756
  function computeModuleDigest(modulePath) {
28649
- const hash = (0, import_node_crypto3.createHash)("sha256");
28757
+ const hash = (0, import_node_crypto4.createHash)("sha256");
28650
28758
  for (const entry of collectFiles(modulePath)) {
28651
28759
  const relPath = (0, import_node_path12.relative)(modulePath, entry.path).split(import_node_path12.sep).join("/");
28652
28760
  hash.update(relPath);
@@ -28735,7 +28843,7 @@ function verifyModuleSignature(modulePath, digest) {
28735
28843
  return { ok: false, reason: `mod.sig references unpinned key "${parsed.keyId}"` };
28736
28844
  }
28737
28845
  try {
28738
- const valid = (0, import_node_crypto3.verify)(
28846
+ const valid = (0, import_node_crypto4.verify)(
28739
28847
  null,
28740
28848
  Buffer.from(digest, "hex"),
28741
28849
  publicKey,
@@ -29603,7 +29711,7 @@ function selectProbes(categories = []) {
29603
29711
  }
29604
29712
 
29605
29713
  // src/aiscan/runner.ts
29606
- var sleep = (ms) => new Promise((r) => setTimeout(r, ms));
29714
+ var sleep2 = (ms) => new Promise((r) => setTimeout(r, ms));
29607
29715
  async function runAiScan(target, send, opts = {}) {
29608
29716
  const probes = (opts.probes ?? selectProbes(opts.categories)).slice(
29609
29717
  0,
@@ -29623,7 +29731,7 @@ async function runAiScan(target, send, opts = {}) {
29623
29731
  }
29624
29732
  results.push({ probe, vulnerable, response, error });
29625
29733
  opts.onProbe?.(probe, vulnerable);
29626
- if (opts.delayMs && opts.delayMs > 0) await sleep(opts.delayMs);
29734
+ if (opts.delayMs && opts.delayMs > 0) await sleep2(opts.delayMs);
29627
29735
  }
29628
29736
  const findings = results.filter((r) => r.vulnerable).map((r) => ({
29629
29737
  type: r.probe.id,
@@ -29822,11 +29930,11 @@ async function aiScanMoshCommand(file, args) {
29822
29930
  }
29823
29931
 
29824
29932
  // src/commands/orgs.ts
29825
- var import_node_os5 = require("os");
29933
+ var import_node_os6 = require("os");
29826
29934
  var import_node_fs18 = require("fs");
29827
29935
  var import_node_path14 = require("path");
29828
29936
  var API_URL3 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
29829
- var CONFIG_PATH = (0, import_node_path14.join)((0, import_node_os5.homedir)(), ".threatcrush", "config.json");
29937
+ var CONFIG_PATH = (0, import_node_path14.join)((0, import_node_os6.homedir)(), ".threatcrush", "config.json");
29830
29938
  function readConfig() {
29831
29939
  try {
29832
29940
  return JSON.parse((0, import_node_fs18.readFileSync)(CONFIG_PATH, "utf-8"));
@@ -29835,7 +29943,7 @@ function readConfig() {
29835
29943
  }
29836
29944
  }
29837
29945
  function writeConfig(config) {
29838
- const dir = (0, import_node_path14.join)((0, import_node_os5.homedir)(), ".threatcrush");
29946
+ const dir = (0, import_node_path14.join)((0, import_node_os6.homedir)(), ".threatcrush");
29839
29947
  if (!(0, import_node_fs18.existsSync)(dir)) (0, import_node_fs18.mkdirSync)(dir, { recursive: true });
29840
29948
  (0, import_node_fs18.writeFileSync)(CONFIG_PATH, JSON.stringify(config, null, 2));
29841
29949
  }
@@ -29973,7 +30081,7 @@ async function useOrganization(slug) {
29973
30081
 
29974
30082
  // src/commands/servers.ts
29975
30083
  var import_node_readline3 = __toESM(require("readline"));
29976
- var import_node_os6 = require("os");
30084
+ var import_node_os7 = require("os");
29977
30085
  async function serversCommand(options) {
29978
30086
  const { action, name, org } = options;
29979
30087
  if (action === "list" || !action) {
@@ -30032,7 +30140,7 @@ async function chooseOrg(orgs, flag, ask2) {
30032
30140
  async function linkServer(opts = {}, ask2 = askChoice) {
30033
30141
  if (!hasSession()) throw new Error("Not logged in. Run: threatcrush login");
30034
30142
  const org = await chooseOrg(await fetchOrgs(), opts.org, ask2);
30035
- const host = opts.hostname ?? (0, import_node_os6.hostname)();
30143
+ const host = opts.hostname ?? (0, import_node_os7.hostname)();
30036
30144
  const listRes = await cloudFetch(`/api/orgs/${org.id}/servers`);
30037
30145
  if (!listRes.ok) throw new Error(`Failed to list servers in /${org.slug} (${listRes.status})`);
30038
30146
  const { servers = [] } = await listRes.json();
@@ -30148,12 +30256,12 @@ function timeAgo(dateStr) {
30148
30256
  }
30149
30257
 
30150
30258
  // src/commands/connect.ts
30151
- var import_node_os7 = require("os");
30259
+ var import_node_os8 = require("os");
30152
30260
  var import_node_fs19 = require("fs");
30153
30261
  var import_node_path15 = require("path");
30154
30262
  var import_node_child_process3 = require("child_process");
30155
30263
  var API_URL4 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
30156
- var CONFIG_PATH2 = (0, import_node_path15.join)((0, import_node_os7.homedir)(), ".threatcrush", "config.json");
30264
+ var CONFIG_PATH2 = (0, import_node_path15.join)((0, import_node_os8.homedir)(), ".threatcrush", "config.json");
30157
30265
  function readConfig2() {
30158
30266
  try {
30159
30267
  return JSON.parse((0, import_node_fs19.readFileSync)(CONFIG_PATH2, "utf-8"));
@@ -30278,20 +30386,20 @@ async function resolveServer(nameOrSlug, orgSlug) {
30278
30386
  }
30279
30387
  }
30280
30388
  async function sshConnect(options) {
30281
- const { hostname: hostname2, port, username, identity } = options;
30282
- if (!hostname2) {
30389
+ const { hostname: hostname3, port, username, identity } = options;
30390
+ if (!hostname3) {
30283
30391
  console.log(source_default.red(" No hostname available for this server.\n"));
30284
30392
  return;
30285
30393
  }
30286
30394
  const user = username || "root";
30287
- console.log(source_default.green(` Connecting to ${user}@${hostname2}:${port}...
30395
+ console.log(source_default.green(` Connecting to ${user}@${hostname3}:${port}...
30288
30396
  `));
30289
30397
  console.log(source_default.dim(" (Spawning SSH session \u2014 exit with Ctrl+D or type 'exit')\n"));
30290
30398
  const sshArgs = ["-p", String(port)];
30291
30399
  if (identity) {
30292
30400
  sshArgs.push("-i", identity);
30293
30401
  }
30294
- sshArgs.push(`${user}@${hostname2}`);
30402
+ sshArgs.push(`${user}@${hostname3}`);
30295
30403
  const ssh = (0, import_node_child_process3.spawn)("ssh", sshArgs, { stdio: "inherit" });
30296
30404
  ssh.on("error", (err) => {
30297
30405
  console.log(source_default.red(`
@@ -30310,15 +30418,15 @@ async function sshConnect(options) {
30310
30418
  }
30311
30419
 
30312
30420
  // src/commands/daemon.ts
30313
- var import_node_child_process10 = require("child_process");
30421
+ var import_node_child_process11 = require("child_process");
30314
30422
  var import_node_fs30 = require("fs");
30315
30423
  var import_node_path21 = require("path");
30316
30424
  var import_node_fs31 = require("fs");
30317
30425
 
30318
30426
  // src/daemon/index.ts
30319
30427
  var import_node_fs29 = require("fs");
30320
- var import_node_child_process9 = require("child_process");
30321
- var import_node_os8 = require("os");
30428
+ var import_node_child_process10 = require("child_process");
30429
+ var import_node_os9 = require("os");
30322
30430
  var import_node_path20 = require("path");
30323
30431
  var import_node_util = require("util");
30324
30432
  init_paths();
@@ -31119,9 +31227,9 @@ var NetworkMonitor = class {
31119
31227
  );
31120
31228
  this.scanTrackers.delete(key);
31121
31229
  } else if (
31122
- // A smaller spread across our listening ports is worth surfacing, but
31123
- // at `medium` so it is logged and never banned (auto-defence bans at
31124
- // `high`). These are inbound-to-listening only, so the ephemeral
31230
+ // A smaller spread across our listening ports. The event itself is
31231
+ // `medium`, but the `port-scan-indicator` rule matches it and bans on
31232
+ // first sight. These are inbound-to-listening only, so the ephemeral
31125
31233
  // outbound-port bug that once banned our upstreams cannot recur here.
31126
31234
  tracker.ports.size >= this.portScanNoticeThreshold && withinWindow && !this.noticed.has(key)
31127
31235
  ) {
@@ -32123,7 +32231,7 @@ var RunsWorker = class {
32123
32231
  };
32124
32232
 
32125
32233
  // src/core/cloud-events.ts
32126
- var import_node_crypto4 = require("crypto");
32234
+ var import_node_crypto5 = require("crypto");
32127
32235
  var import_node_net3 = require("net");
32128
32236
  function currentLink() {
32129
32237
  if (!hasSession()) return null;
@@ -32196,7 +32304,7 @@ function remediationEvent(serverId, event) {
32196
32304
  return {
32197
32305
  type: "remediation",
32198
32306
  server_id: serverId,
32199
- event_id: (0, import_node_crypto4.randomUUID)(),
32307
+ event_id: (0, import_node_crypto5.randomUUID)(),
32200
32308
  action_type: d.action,
32201
32309
  target_value: event.source_ip,
32202
32310
  status: d.failed === true ? "failed" : "executed",
@@ -33192,12 +33300,15 @@ var DEFAULT_RULES = [
33192
33300
  enabled: true
33193
33301
  },
33194
33302
  {
33303
+ // A rule that declares `block` must be at the severity auto-defence bans
33304
+ // at, or it fires and is ignored: this one was `medium`, and on dev1 it
33305
+ // detected scanners 25 times and banned none of them.
33195
33306
  id: "web-scanner-detection",
33196
33307
  title: "Web Vulnerability Scanner Detected",
33197
33308
  description: "High volume of 4xx errors suggesting automated scanning",
33198
33309
  version: "1.0.0",
33199
33310
  category: "web",
33200
- severity: "medium",
33311
+ severity: "high",
33201
33312
  source_types: ["log-watcher", "web"],
33202
33313
  match: {
33203
33314
  field: "message",
@@ -33221,7 +33332,7 @@ var DEFAULT_RULES = [
33221
33332
  // and keeps walking URLs: GoogleOther did ~40/min per IP against r4ck's
33222
33333
  // /api/v1/search on dev2, 2026-09-25. `web-scanner-detection` saw it too,
33223
33334
  // but it is `medium`, and auto-defence bans at `high` and above, so it fired
33224
- // every minute and never banned. This one is `high` on purpose.
33335
+ // every minute and never banned (it is `high` now too). This one is `high` on purpose.
33225
33336
  //
33226
33337
  // It cannot see a proxy swarm that asks once per address; nothing per-IP can.
33227
33338
  id: "paywall-hammering",
@@ -33281,12 +33392,16 @@ var DEFAULT_RULES = [
33281
33392
  enabled: true
33282
33393
  },
33283
33394
  {
33395
+ // `high` for the same reason as web-scanner-detection: as `medium` it fired
33396
+ // 21 times on dev1 without a single ban. It also matches network-monitor's
33397
+ // "Possible port scan" notice (5+ of our LISTENING ports from one address),
33398
+ // so that is now banned on first sight as well.
33284
33399
  id: "port-scan-indicator",
33285
33400
  title: "Port Scan Indicators",
33286
33401
  description: "Connection attempts to many ports from a single source",
33287
33402
  version: "1.0.0",
33288
33403
  category: "network",
33289
- severity: "medium",
33404
+ severity: "high",
33290
33405
  source_types: ["network-monitor", "network"],
33291
33406
  match: {
33292
33407
  field: "message",
@@ -33714,8 +33829,11 @@ var DEFAULT_CONFIG2 = {
33714
33829
  enabled: true,
33715
33830
  dry_run: false,
33716
33831
  min_severity: "high",
33717
- max_ban_seconds: 86400,
33718
- strike_memory_seconds: 86400,
33832
+ first_ban_seconds: DEFAULT_FIRST_BAN_SECONDS,
33833
+ max_ban_seconds: 7 * 86400,
33834
+ // Longer than the ceiling, or an address that reaches it is forgotten while
33835
+ // banned and comes back at the first rung.
33836
+ strike_memory_seconds: 30 * 86400,
33719
33837
  allowlist: [],
33720
33838
  protect_current_ssh_client: true,
33721
33839
  spare_verified_crawlers: true
@@ -33807,9 +33925,9 @@ var RemediationManager = class {
33807
33925
  await this.ban(ip, event.message, { ruleId, source: "auto" });
33808
33926
  }
33809
33927
  /**
33810
- * Ban `ip`. With no explicit TTL the length comes from the Fibonacci ladder:
33811
- * 1m, 2m, 3m, 5m, 8m, 13m … for the 1st, 2nd, 3rd offence and so on, clamped
33812
- * to `max_ban_seconds`.
33928
+ * Ban `ip`. With no explicit TTL the length comes from the doubling ladder:
33929
+ * `first_ban_seconds` (5m by default), then 10m, 20m, 40m … for the 2nd, 3rd,
33930
+ * 4th offence and so on, clamped to `max_ban_seconds`.
33813
33931
  */
33814
33932
  async ban(ip, reason, opts = {}) {
33815
33933
  if ((0, import_node_net8.isIP)(ip) === 0) return { ok: false, error: `not an IP address: ${ip}` };
@@ -33847,7 +33965,7 @@ var RemediationManager = class {
33847
33965
  }
33848
33966
  }
33849
33967
  const strike = recordStrike(this.strikes, ip, now, this.config.strike_memory_seconds);
33850
- const ttl = opts.ttlSeconds ?? banSeconds(strike, this.config.max_ban_seconds);
33968
+ const ttl = opts.ttlSeconds ?? banSeconds(strike, this.config.max_ban_seconds, this.config.first_ban_seconds);
33851
33969
  const entry = {
33852
33970
  ip,
33853
33971
  reason,
@@ -33947,6 +34065,7 @@ var RemediationManager = class {
33947
34065
  backend: this.adapter.name,
33948
34066
  min_severity: this.config.min_severity,
33949
34067
  banned: this.blocklist.length,
34068
+ first_ban_seconds: this.config.first_ban_seconds,
33950
34069
  max_ban_seconds: this.config.max_ban_seconds,
33951
34070
  warning: this.privilegeWarning()
33952
34071
  };
@@ -34085,6 +34204,8 @@ function remediationSettings(section) {
34085
34204
  else if (section.mode === "enforce") settings.dry_run = false;
34086
34205
  else if (typeof section.dry_run === "boolean") settings.dry_run = section.dry_run;
34087
34206
  if (section.min_severity) settings.min_severity = section.min_severity;
34207
+ const firstBan = parseDuration(section.first_ban);
34208
+ if (firstBan) settings.first_ban_seconds = firstBan;
34088
34209
  const maxBan = parseDuration(section.max_ban);
34089
34210
  if (maxBan) settings.max_ban_seconds = maxBan;
34090
34211
  const memory = parseDuration(section.strike_memory);
@@ -34100,6 +34221,9 @@ function remediationSettings(section) {
34100
34221
  return settings;
34101
34222
  }
34102
34223
 
34224
+ // src/daemon/index.ts
34225
+ init_backoff();
34226
+
34103
34227
  // src/core/telemetry.ts
34104
34228
  var ready = false;
34105
34229
  var sentry = null;
@@ -34146,6 +34270,25 @@ async function flushTelemetry(timeoutMs = 2e3) {
34146
34270
  }
34147
34271
  }
34148
34272
 
34273
+ // src/core/node-runtime.ts
34274
+ var import_node_child_process9 = require("child_process");
34275
+ var MIN_DAEMON_NODE_MAJOR = 22;
34276
+ function nodeMajor(version) {
34277
+ const m = String(version ?? "").trim().replace(/^v/, "").match(/^(\d+)\./);
34278
+ return m ? Number(m[1]) : null;
34279
+ }
34280
+ function daemonNodeProblem(version) {
34281
+ const major = nodeMajor(version);
34282
+ if (major === null) return `cannot tell which Node version this is (${version ?? "unknown"})`;
34283
+ if (major >= MIN_DAEMON_NODE_MAJOR) return null;
34284
+ return `Node ${version} is too old for threatcrushd (needs ${MIN_DAEMON_NODE_MAJOR}+): its SQLite driver crashes the process with SIGSEGV. Install threatcrush with Node ${MIN_DAEMON_NODE_MAJOR} or newer and re-run threatcrush install-service.`;
34285
+ }
34286
+ function versionOfNode(path) {
34287
+ if (path === process.execPath) return process.versions.node;
34288
+ const res = (0, import_node_child_process9.spawnSync)(path, ["-p", "process.versions.node"], { encoding: "utf-8", timeout: 5e3 });
34289
+ return res.status === 0 ? res.stdout.trim() : null;
34290
+ }
34291
+
34149
34292
  // src/daemon/index.ts
34150
34293
  function readVersion2() {
34151
34294
  try {
@@ -34156,7 +34299,7 @@ function readVersion2() {
34156
34299
  }
34157
34300
  }
34158
34301
  async function runHardeningChecks() {
34159
- const { stdout } = await (0, import_node_util.promisify)(import_node_child_process9.execFile)(
34302
+ const { stdout } = await (0, import_node_util.promisify)(import_node_child_process10.execFile)(
34160
34303
  process.execPath,
34161
34304
  [(0, import_node_path20.join)(__dirname, "index.js"), "harden", "--json", "--no-upload"],
34162
34305
  { timeout: 12e4, maxBuffer: 4 * 1024 * 1024 }
@@ -34189,6 +34332,12 @@ async function runDaemon() {
34189
34332
  });
34190
34333
  const version = readVersion2();
34191
34334
  logLine(`[daemon] starting threatcrushd v${version} mode=${PATHS.mode}`);
34335
+ const nodeProblem = daemonNodeProblem(process.versions.node);
34336
+ if (nodeProblem) {
34337
+ logLine(`[daemon] ${nodeProblem}`);
34338
+ console.error(nodeProblem);
34339
+ process.exit(1);
34340
+ }
34192
34341
  try {
34193
34342
  initStateDB(PATHS.stateDb);
34194
34343
  } catch (err) {
@@ -34234,7 +34383,7 @@ async function runDaemon() {
34234
34383
  });
34235
34384
  const remediationStatus = remediation.status();
34236
34385
  logLine(
34237
- `[daemon] auto-defence ${remediationStatus.enabled ? "ON" : "OFF"} (backend=${remediationStatus.backend}, mode=${remediationStatus.dry_run ? "dry_run" : "enforce"}, min_severity=${remediationStatus.min_severity}, bans escalate 1m\u21922m\u21923m\u21925m\u21928m\u2026)`
34386
+ `[daemon] auto-defence ${remediationStatus.enabled ? "ON" : "OFF"} (backend=${remediationStatus.backend}, mode=${remediationStatus.dry_run ? "dry_run" : "enforce"}, min_severity=${remediationStatus.min_severity}, bans double from ${formatDuration(remediationStatus.first_ban_seconds)} up to ${formatDuration(remediationStatus.max_ban_seconds)})`
34238
34387
  );
34239
34388
  if (remediationStatus.dry_run && firewallAdapter.enforces !== false) {
34240
34389
  logLine("[daemon] dry_run is set in [remediation] \u2014 detections will be logged, not blocked");
@@ -34259,7 +34408,7 @@ async function runDaemon() {
34259
34408
  cloudSync = new CloudSync({
34260
34409
  bus,
34261
34410
  version,
34262
- hostname: (0, import_node_os8.hostname)(),
34411
+ hostname: (0, import_node_os9.hostname)(),
34263
34412
  minSeverity,
34264
34413
  spoolPath: (0, import_node_path20.join)(PATHS.stateDir, "cloud-spool.jsonl"),
34265
34414
  log: logLine,
@@ -34381,7 +34530,7 @@ async function daemonStart() {
34381
34530
  }
34382
34531
  return;
34383
34532
  }
34384
- const child = (0, import_node_child_process10.spawn)(process.execPath, [DAEMON_ENTRY], {
34533
+ const child = (0, import_node_child_process11.spawn)(process.execPath, [DAEMON_ENTRY], {
34385
34534
  detached: true,
34386
34535
  stdio: ["ignore", out, err],
34387
34536
  env: { ...process.env, THREATCRUSH_DAEMON: "1" }
@@ -34468,7 +34617,7 @@ async function releaseStaleSocket() {
34468
34617
  }
34469
34618
 
34470
34619
  // src/commands/service.ts
34471
- var import_node_child_process11 = require("child_process");
34620
+ var import_node_child_process12 = require("child_process");
34472
34621
  var import_node_fs32 = require("fs");
34473
34622
  var import_node_path22 = require("path");
34474
34623
  var UNIT_PATH = "/etc/systemd/system/threatcrushd.service";
@@ -34489,7 +34638,7 @@ function resolveBinPath() {
34489
34638
  const arg = process.argv[1];
34490
34639
  if (arg && (0, import_node_fs32.existsSync)(arg)) return stableBinPath(arg);
34491
34640
  try {
34492
- return (0, import_node_child_process11.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
34641
+ return (0, import_node_child_process12.execSync)("command -v threatcrush", { encoding: "utf-8" }).trim();
34493
34642
  } catch {
34494
34643
  return "threatcrush";
34495
34644
  }
@@ -34525,18 +34674,18 @@ function isRoot3() {
34525
34674
  return typeof process.getuid === "function" && process.getuid() === 0;
34526
34675
  }
34527
34676
  function reexecWithSudo(args) {
34528
- if ((0, import_node_child_process11.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
34677
+ if ((0, import_node_child_process12.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
34529
34678
  console.log(source_default.dim(" This needs root \u2014 sudo will ask for your password.\n"));
34530
34679
  const bin = resolveBinPath();
34531
34680
  const argv = looksLikeNodeScript(bin) ? [stableNodePath(process.execPath), bin, ...args] : [bin, ...args];
34532
- const result = (0, import_node_child_process11.spawnSync)("sudo", argv, { stdio: "inherit" });
34681
+ const result = (0, import_node_child_process12.spawnSync)("sudo", argv, { stdio: "inherit" });
34533
34682
  return result.status === 0;
34534
34683
  }
34535
34684
  function callerHome() {
34536
34685
  const user = process.env.SUDO_USER;
34537
34686
  if (!user) return null;
34538
34687
  try {
34539
- const line = (0, import_node_child_process11.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
34688
+ const line = (0, import_node_child_process12.execSync)(`getent passwd ${user}`, { encoding: "utf-8" }).trim();
34540
34689
  const home = line.split(":")[5];
34541
34690
  return home && (0, import_node_fs32.existsSync)(home) ? home : null;
34542
34691
  } catch {
@@ -34571,7 +34720,7 @@ function stopUserModeDaemon() {
34571
34720
  }
34572
34721
  }
34573
34722
  function unitIsActive() {
34574
- const result = (0, import_node_child_process11.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
34723
+ const result = (0, import_node_child_process12.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT_NAME], { stdio: "pipe" });
34575
34724
  return result.status === 0;
34576
34725
  }
34577
34726
  async function installServiceCommand() {
@@ -34582,7 +34731,7 @@ async function installServiceCommand() {
34582
34731
  return;
34583
34732
  }
34584
34733
  const noSystemd = systemdUnavailableReason({
34585
- hasSystemctl: (0, import_node_child_process11.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
34734
+ hasSystemctl: (0, import_node_child_process12.spawnSync)("sh", ["-c", "command -v systemctl"], { stdio: "ignore" }).status === 0,
34586
34735
  booted: (0, import_node_fs32.existsSync)("/run/systemd/system")
34587
34736
  });
34588
34737
  if (noSystemd) {
@@ -34608,6 +34757,15 @@ async function installServiceCommand() {
34608
34757
  binPath = (0, import_node_fs32.realpathSync)(binPath);
34609
34758
  nodePath = process.execPath;
34610
34759
  }
34760
+ if (isNodeScript) {
34761
+ const problem = daemonNodeProblem(versionOfNode(nodePath));
34762
+ if (problem) {
34763
+ console.log(source_default.red(` \u2717 ${problem}`));
34764
+ console.log(source_default.dim(" Nothing was installed."));
34765
+ process.exitCode = 1;
34766
+ return;
34767
+ }
34768
+ }
34611
34769
  const exec = execStartCommand(binPath, nodePath, isNodeScript);
34612
34770
  const unit = resolveTemplate().replace("{{BIN_PATH}} daemon", exec).replace("{{BIN_PATH}}", binPath);
34613
34771
  (0, import_node_fs32.writeFileSync)(UNIT_PATH, unit, { mode: 420 });
@@ -34624,8 +34782,8 @@ async function installServiceCommand() {
34624
34782
  ensureSystemDirs();
34625
34783
  stopUserModeDaemon();
34626
34784
  try {
34627
- (0, import_node_child_process11.execSync)("systemctl daemon-reload", { stdio: "inherit" });
34628
- (0, import_node_child_process11.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
34785
+ (0, import_node_child_process12.execSync)("systemctl daemon-reload", { stdio: "inherit" });
34786
+ (0, import_node_child_process12.execSync)(`systemctl enable --now ${DAEMON_UNIT_NAME}`, { stdio: "inherit" });
34629
34787
  } catch (err) {
34630
34788
  console.log(source_default.yellow(` ! systemctl error: ${err.message}`));
34631
34789
  console.log(source_default.dim(` Logs: journalctl -u ${DAEMON_UNIT_NAME} -n 50`));
@@ -34667,7 +34825,7 @@ function ensureSystemDirs() {
34667
34825
  try {
34668
34826
  if (groupWritable && admGid !== null) {
34669
34827
  (0, import_node_fs32.chmodSync)(path, sticky ? 1533 : 509);
34670
- (0, import_node_child_process11.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
34828
+ (0, import_node_child_process12.execSync)(`chgrp adm ${path}`, { stdio: "ignore" });
34671
34829
  } else {
34672
34830
  (0, import_node_fs32.chmodSync)(path, 493);
34673
34831
  }
@@ -34689,27 +34847,95 @@ async function uninstallServiceCommand() {
34689
34847
  return;
34690
34848
  }
34691
34849
  try {
34692
- (0, import_node_child_process11.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
34850
+ (0, import_node_child_process12.execSync)("systemctl stop threatcrushd.service", { stdio: "inherit" });
34693
34851
  } catch {
34694
34852
  }
34695
34853
  try {
34696
- (0, import_node_child_process11.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
34854
+ (0, import_node_child_process12.execSync)("systemctl disable threatcrushd.service", { stdio: "inherit" });
34697
34855
  } catch {
34698
34856
  }
34699
34857
  try {
34700
34858
  if ((0, import_node_fs32.existsSync)(UNIT_PATH)) {
34701
- (0, import_node_child_process11.execSync)(`rm -f ${UNIT_PATH}`);
34859
+ (0, import_node_child_process12.execSync)(`rm -f ${UNIT_PATH}`);
34702
34860
  console.log(source_default.green(` \u2713 Removed unit file: ${UNIT_PATH}`));
34703
34861
  }
34704
34862
  } catch {
34705
34863
  }
34706
34864
  try {
34707
- (0, import_node_child_process11.execSync)("systemctl daemon-reload", { stdio: "inherit" });
34865
+ (0, import_node_child_process12.execSync)("systemctl daemon-reload", { stdio: "inherit" });
34708
34866
  } catch {
34709
34867
  }
34710
34868
  console.log(source_default.green(" \u2713 threatcrushd service removed."));
34711
34869
  }
34712
34870
 
34871
+ // src/commands/save.ts
34872
+ var import_node_fs33 = require("fs");
34873
+ var import_toml5 = __toESM(require_toml());
34874
+ init_paths();
34875
+ var SECRET_KEY = /pass(word)?|secret|token|api_?key|private|webhook|dsn|url|routing_key|auth/i;
34876
+ var REDACTED = "[redacted]";
34877
+ var UNSAFE_KEYS = /* @__PURE__ */ new Set(["__proto__", "constructor", "prototype"]);
34878
+ function redactConfig(value, depth = 0) {
34879
+ if (depth > 10) return REDACTED;
34880
+ if (Array.isArray(value)) return value.map((v) => redactConfig(v, depth + 1));
34881
+ if (value && typeof value === "object") {
34882
+ return Object.fromEntries(
34883
+ Object.entries(value).filter(([key]) => !UNSAFE_KEYS.has(key)).map(([key, v]) => [
34884
+ key,
34885
+ SECRET_KEY.test(key) && v !== null && typeof v !== "object" && typeof v !== "boolean" ? REDACTED : redactConfig(v, depth + 1)
34886
+ ])
34887
+ );
34888
+ }
34889
+ return value;
34890
+ }
34891
+ async function saveCommand(opts = {}) {
34892
+ banner();
34893
+ if (!hasSession()) {
34894
+ console.log(source_default.yellow(" Not logged in."));
34895
+ console.log(source_default.dim(` Log in with ${source_default.white("threatcrush login")}, then link this machine with ${source_default.white("threatcrush servers link")}.
34896
+ `));
34897
+ process.exitCode = 1;
34898
+ return;
34899
+ }
34900
+ const link = currentLink();
34901
+ if (!link) {
34902
+ console.log(source_default.yellow(" This machine is not linked to a dashboard server."));
34903
+ console.log(source_default.dim(` Link it with ${source_default.white("threatcrush servers link")}.
34904
+ `));
34905
+ process.exitCode = 1;
34906
+ return;
34907
+ }
34908
+ const path = opts.config ?? PATHS.configFile;
34909
+ let config = {};
34910
+ if ((0, import_node_fs33.existsSync)(path)) {
34911
+ try {
34912
+ config = import_toml5.default.parse((0, import_node_fs33.readFileSync)(path, "utf-8"));
34913
+ } catch (err) {
34914
+ console.log(source_default.red(` \u2717 ${path} is not valid TOML: ${err.message}
34915
+ `));
34916
+ process.exitCode = 1;
34917
+ return;
34918
+ }
34919
+ }
34920
+ const res = await cloudFetch(`/api/orgs/${link.orgId}/servers/${link.serverId}/config`, {
34921
+ method: "PUT",
34922
+ body: JSON.stringify({ config: redactConfig(config), source: path })
34923
+ });
34924
+ const data = await res.json().catch(() => ({}));
34925
+ if (!res.ok) {
34926
+ console.log(source_default.red(` \u2717 ${data.error || `Save failed (${res.status})`}
34927
+ `));
34928
+ process.exitCode = 1;
34929
+ return;
34930
+ }
34931
+ const sections = Object.keys(config);
34932
+ console.log(source_default.green(` \u2713 Saved ${path} to ${source_default.white(data.server?.name ?? link.serverId)}`));
34933
+ console.log(source_default.dim(
34934
+ sections.length > 0 ? ` Sections: ${sections.join(", ")} (secrets redacted)
34935
+ ` : " No config file here, so the built-in defaults were saved as empty.\n"
34936
+ ));
34937
+ }
34938
+
34713
34939
  // src/commands/welcome.ts
34714
34940
  init_paths();
34715
34941
  var LOGO = source_default.green(`
@@ -34795,7 +35021,7 @@ function welcomeCommand() {
34795
35021
  }
34796
35022
 
34797
35023
  // src/commands/properties.ts
34798
- var import_node_fs33 = require("fs");
35024
+ var import_node_fs34 = require("fs");
34799
35025
  var import_node_path23 = require("path");
34800
35026
  var import_node_readline6 = __toESM(require("readline"));
34801
35027
  var API_URL5 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
@@ -35126,7 +35352,7 @@ async function propertiesRunsCommand(opts) {
35126
35352
  }
35127
35353
  function parseImportFile(path) {
35128
35354
  const ext = (0, import_node_path23.extname)(path).toLowerCase();
35129
- const raw = (0, import_node_fs33.readFileSync)(path, "utf-8");
35355
+ const raw = (0, import_node_fs34.readFileSync)(path, "utf-8");
35130
35356
  if (ext === ".json") {
35131
35357
  const parsed = JSON.parse(raw);
35132
35358
  if (!Array.isArray(parsed)) throw new Error("JSON must be an array of objects");
@@ -35285,7 +35511,7 @@ async function rulesShowCommand(ruleId) {
35285
35511
  if (rule.remediation) {
35286
35512
  console.log(` Remediation: ${source_default.gray(rule.remediation.description || rule.remediation.action || "none")}`);
35287
35513
  if (rule.remediation.action === "block") {
35288
- console.log(` Ban length: ${source_default.gray("escalation ladder, 1m \u2192 2m \u2192 3m \u2192 5m \u2192 8m \u2026 up to max_ban")}`);
35514
+ console.log(` Ban length: ${source_default.gray("escalation ladder, doubling from first_ban: 5m \u2192 10m \u2192 20m \u2192 40m \u2026 up to max_ban")}`);
35289
35515
  }
35290
35516
  }
35291
35517
  console.log();
@@ -35321,18 +35547,18 @@ async function rulesCommand(opts) {
35321
35547
  }
35322
35548
 
35323
35549
  // src/commands/harden.ts
35324
- var import_node_fs34 = require("fs");
35325
- var import_node_child_process12 = require("child_process");
35550
+ var import_node_fs35 = require("fs");
35551
+ var import_node_child_process13 = require("child_process");
35326
35552
  function tryExec(cmd) {
35327
35553
  try {
35328
- return (0, import_node_child_process12.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
35554
+ return (0, import_node_child_process13.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
35329
35555
  } catch {
35330
35556
  return null;
35331
35557
  }
35332
35558
  }
35333
35559
  function tryRead(path) {
35334
35560
  try {
35335
- return (0, import_node_fs34.readFileSync)(path, "utf-8");
35561
+ return (0, import_node_fs35.readFileSync)(path, "utf-8");
35336
35562
  } catch {
35337
35563
  return null;
35338
35564
  }
@@ -35436,8 +35662,8 @@ function checkSshWeakConfig() {
35436
35662
  };
35437
35663
  }
35438
35664
  function checkAutoUpdates() {
35439
- const unattended = (0, import_node_fs34.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs34.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
35440
- const dnfAuto = (0, import_node_fs34.existsSync)("/etc/dnf/automatic.conf");
35665
+ const unattended = (0, import_node_fs35.existsSync)("/etc/apt/apt.conf.d/20auto-upgrades") || (0, import_node_fs35.existsSync)("/etc/apt/apt.conf.d/50unattended-upgrades");
35666
+ const dnfAuto = (0, import_node_fs35.existsSync)("/etc/dnf/automatic.conf");
35441
35667
  if (unattended || dnfAuto) {
35442
35668
  return {
35443
35669
  key: "auto-updates",
@@ -35563,7 +35789,7 @@ function checkFail2ban() {
35563
35789
  explanation: "fail2ban is installed and running."
35564
35790
  };
35565
35791
  }
35566
- if ((0, import_node_fs34.existsSync)("/etc/fail2ban/fail2ban.conf")) {
35792
+ if ((0, import_node_fs35.existsSync)("/etc/fail2ban/fail2ban.conf")) {
35567
35793
  return {
35568
35794
  key: checkKey,
35569
35795
  status: "warn",
@@ -35892,11 +36118,11 @@ async function allowlistCommand(opts) {
35892
36118
  init_paths();
35893
36119
 
35894
36120
  // src/upgrade.ts
35895
- var import_node_child_process13 = require("child_process");
36121
+ var import_node_child_process14 = require("child_process");
35896
36122
  var PACKAGE_MANAGERS = ["npm", "pnpm", "yarn", "bun"];
35897
36123
  var defaultRunner = (cmd) => {
35898
36124
  try {
35899
- return (0, import_node_child_process13.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
36125
+ return (0, import_node_child_process14.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
35900
36126
  } catch {
35901
36127
  return null;
35902
36128
  }
@@ -36011,25 +36237,25 @@ ${source_default.dim(" C R U S H")}
36011
36237
  var API_URL6 = process.env.THREATCRUSH_API_URL || "https://threatcrush.com";
36012
36238
  var PKG_NAME = "@profullstack/threatcrush";
36013
36239
  var DESKTOP_PKG_NAME = "@profullstack/threatcrush-desktop";
36014
- var INSTALL_CONFIG_PATH = (0, import_node_path24.join)((0, import_node_os9.homedir)(), ".threatcrush", "install.json");
36240
+ var INSTALL_CONFIG_PATH = (0, import_node_path24.join)((0, import_node_os10.homedir)(), ".threatcrush", "install.json");
36015
36241
  function detectPackageManager() {
36016
36242
  try {
36017
- const npmGlobal = (0, import_node_child_process14.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
36243
+ const npmGlobal = (0, import_node_child_process15.execSync)("npm ls -g --depth=0 --json 2>/dev/null", { encoding: "utf-8" });
36018
36244
  if (npmGlobal.includes(PKG_NAME)) return "npm";
36019
36245
  } catch {
36020
36246
  }
36021
36247
  try {
36022
- (0, import_node_child_process14.execSync)("pnpm --version", { stdio: "pipe" });
36248
+ (0, import_node_child_process15.execSync)("pnpm --version", { stdio: "pipe" });
36023
36249
  return "pnpm";
36024
36250
  } catch {
36025
36251
  }
36026
36252
  try {
36027
- (0, import_node_child_process14.execSync)("yarn --version", { stdio: "pipe" });
36253
+ (0, import_node_child_process15.execSync)("yarn --version", { stdio: "pipe" });
36028
36254
  return "yarn";
36029
36255
  } catch {
36030
36256
  }
36031
36257
  try {
36032
- (0, import_node_child_process14.execSync)("bun --version", { stdio: "pipe" });
36258
+ (0, import_node_child_process15.execSync)("bun --version", { stdio: "pipe" });
36033
36259
  return "bun";
36034
36260
  } catch {
36035
36261
  }
@@ -36037,14 +36263,14 @@ function detectPackageManager() {
36037
36263
  }
36038
36264
  function readInstallConfig() {
36039
36265
  try {
36040
- return JSON.parse((0, import_node_fs35.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
36266
+ return JSON.parse((0, import_node_fs36.readFileSync)(INSTALL_CONFIG_PATH, "utf-8"));
36041
36267
  } catch {
36042
36268
  return {};
36043
36269
  }
36044
36270
  }
36045
36271
  function packageLooksInstalled(pm, pkgName) {
36046
36272
  try {
36047
- const output = (0, import_node_child_process14.execSync)(globalListCommand(pm, pkgName), {
36273
+ const output = (0, import_node_child_process15.execSync)(globalListCommand(pm, pkgName), {
36048
36274
  encoding: "utf-8",
36049
36275
  stdio: ["pipe", "pipe", "pipe"]
36050
36276
  });
@@ -36147,14 +36373,14 @@ async function promoteUnprivilegedDaemon() {
36147
36373
  function restartSystemdDaemon() {
36148
36374
  const asRoot = typeof process.getuid === "function" && process.getuid() === 0;
36149
36375
  const argv = asRoot ? ["systemctl", "restart", DAEMON_UNIT] : ["sudo", "systemctl", "restart", DAEMON_UNIT];
36150
- if (!asRoot && (0, import_node_child_process14.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
36376
+ if (!asRoot && (0, import_node_child_process15.spawnSync)("sudo", ["--version"], { stdio: "pipe" }).status !== 0) return false;
36151
36377
  const [cmd, ...args] = argv;
36152
- if ((0, import_node_child_process14.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
36153
- return (0, import_node_child_process14.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
36378
+ if ((0, import_node_child_process15.spawnSync)(cmd, args, { stdio: "inherit" }).status !== 0) return false;
36379
+ return (0, import_node_child_process15.spawnSync)("systemctl", ["is-active", "--quiet", DAEMON_UNIT], { stdio: "pipe" }).status === 0;
36154
36380
  }
36155
36381
  function execQuiet(cmd) {
36156
36382
  try {
36157
- return (0, import_node_child_process14.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
36383
+ return (0, import_node_child_process15.execSync)(cmd, { encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
36158
36384
  } catch {
36159
36385
  return null;
36160
36386
  }
@@ -36207,8 +36433,11 @@ program2.command("tui").description("Interactive security dashboard (htop for se
36207
36433
  program2.command("init").description("Sign in, auto-detect services, and configure ThreatCrush").option("-y, --yes", "Don't ask; answer yes to every question").option("--offline", "Skip signing in to threatcrush.com").action(async (opts) => {
36208
36434
  await initCommand({ yes: opts.yes, offline: opts.offline });
36209
36435
  });
36210
- program2.command("login").description("Log in to your threatcrush.com account").option("-e, --email <email>", "Email to log in with").action(async (opts) => {
36211
- await loginCommand({ email: opts.email });
36436
+ program2.command("login").description("Log in to your threatcrush.com account (prints a link to approve in your browser)").option("-p, --password", "Log in with email and password instead of a link").option("-e, --email <email>", "Email to log in with (implies --password)").action(async (opts) => {
36437
+ await loginCommand({ email: opts.email, password: opts.password });
36438
+ });
36439
+ program2.command("save").description("Save this machine's daemon config to its threatcrush.com server (secrets redacted)").option("-c, --config <path>", "Config file to save (default: the one the daemon reads)").action(async (opts) => {
36440
+ await saveCommand({ config: opts.config });
36212
36441
  });
36213
36442
  program2.command("logout").description("Clear stored threatcrush.com credentials").action(async () => {
36214
36443
  await logoutCommand();
@@ -36308,7 +36537,7 @@ program2.command("uninstall-service").description("Remove the threatcrushd syste
36308
36537
  program2.command("logs").description("Tail daemon logs").action(async () => {
36309
36538
  console.log(LOGO2);
36310
36539
  const logPath = PATHS.logFile;
36311
- if (!(0, import_node_fs35.existsSync)(logPath)) {
36540
+ if (!(0, import_node_fs36.existsSync)(logPath)) {
36312
36541
  console.log(source_default.yellow(` No log file found at ${logPath}`));
36313
36542
  console.log(source_default.dim(" Start the daemon first with `threatcrush start`\n"));
36314
36543
  return;
@@ -36316,7 +36545,7 @@ program2.command("logs").description("Tail daemon logs").action(async () => {
36316
36545
  console.log(source_default.green(` Tailing ${logPath}...
36317
36546
  `));
36318
36547
  console.log(source_default.gray(" Press Ctrl+C to stop\n"));
36319
- (0, import_node_child_process14.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
36548
+ (0, import_node_child_process15.execSync)(`tail -f ${logPath}`, { stdio: "inherit" });
36320
36549
  });
36321
36550
  program2.command("update").description("Update ThreatCrush CLI and installed bundle").option("--cli", "Update CLI only").option("--modules", "Update modules only").option("--desktop", "Update desktop app too").action(async (opts) => {
36322
36551
  console.log(LOGO2);
@@ -36328,7 +36557,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
36328
36557
  for (const cmd of commands2) {
36329
36558
  console.log(source_default.green(` \u2192 ${cmd}
36330
36559
  `));
36331
- (0, import_node_child_process14.execSync)(cmd, { stdio: "inherit" });
36560
+ (0, import_node_child_process15.execSync)(cmd, { stdio: "inherit" });
36332
36561
  }
36333
36562
  console.log(source_default.green("\n \u2713 Modules updated successfully!\n"));
36334
36563
  await reportIfStillStale();
@@ -36353,7 +36582,7 @@ program2.command("update").description("Update ThreatCrush CLI and installed bun
36353
36582
  for (const cmd of commands) {
36354
36583
  console.log(source_default.green(` \u2192 ${cmd}
36355
36584
  `));
36356
- (0, import_node_child_process14.execSync)(cmd, { stdio: "inherit" });
36585
+ (0, import_node_child_process15.execSync)(cmd, { stdio: "inherit" });
36357
36586
  }
36358
36587
  console.log(source_default.green("\n \u2713 ThreatCrush updated successfully!\n"));
36359
36588
  if (installMode === "desktop") {
@@ -36404,7 +36633,7 @@ program2.command("remove").description("Uninstall ThreatCrush and the installed
36404
36633
  for (const cmd of commands) {
36405
36634
  console.log(source_default.green(` \u2192 ${cmd}
36406
36635
  `));
36407
- (0, import_node_child_process14.execSync)(cmd, { stdio: "inherit" });
36636
+ (0, import_node_child_process15.execSync)(cmd, { stdio: "inherit" });
36408
36637
  }
36409
36638
  console.log(source_default.green("\n \u2713 ThreatCrush has been uninstalled.\n"));
36410
36639
  console.log(source_default.dim(" We're sorry to see you go! \u{1F44B}\n"));
@@ -36481,10 +36710,10 @@ storeCmd.command("search <query>").description("Search for modules in the store"
36481
36710
  });
36482
36711
  storeCmd.command("publish <url>").description("Publish a module from a git URL or web URL").action(async (url) => {
36483
36712
  console.log(LOGO2);
36484
- const configPath = (0, import_node_path24.join)((0, import_node_os9.homedir)(), ".threatcrush", "config.json");
36713
+ const configPath = (0, import_node_path24.join)((0, import_node_os10.homedir)(), ".threatcrush", "config.json");
36485
36714
  let email = "";
36486
36715
  try {
36487
- const config = JSON.parse((0, import_node_fs35.readFileSync)(configPath, "utf-8"));
36716
+ const config = JSON.parse((0, import_node_fs36.readFileSync)(configPath, "utf-8"));
36488
36717
  email = config.email || "";
36489
36718
  } catch {
36490
36719
  }
@@ -36501,9 +36730,9 @@ storeCmd.command("publish <url>").description("Publish a module from a git URL o
36501
36730
  return;
36502
36731
  }
36503
36732
  try {
36504
- const dir = (0, import_node_path24.join)((0, import_node_os9.homedir)(), ".threatcrush");
36505
- if (!(0, import_node_fs35.existsSync)(dir)) (0, import_node_fs35.mkdirSync)(dir, { recursive: true });
36506
- (0, import_node_fs35.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
36733
+ const dir = (0, import_node_path24.join)((0, import_node_os10.homedir)(), ".threatcrush");
36734
+ if (!(0, import_node_fs36.existsSync)(dir)) (0, import_node_fs36.mkdirSync)(dir, { recursive: true });
36735
+ (0, import_node_fs36.writeFileSync)(configPath, JSON.stringify({ email }, null, 2));
36507
36736
  console.log(source_default.dim(` Saved email to ${configPath}`));
36508
36737
  } catch {
36509
36738
  }