@profullstack/threatcrush 0.13.62 → 0.13.63
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 +57 -30
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +64 -24
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/daemon.js
CHANGED
|
@@ -11053,7 +11053,6 @@ var DnsMonitor = class {
|
|
|
11053
11053
|
var import_node_fs13 = require("fs");
|
|
11054
11054
|
var import_node_path6 = require("path");
|
|
11055
11055
|
var import_toml = __toESM(require_toml());
|
|
11056
|
-
var DEFAULT_CONFIG_PATH = "/etc/threatcrush/threatcrushd.conf";
|
|
11057
11056
|
var DEFAULT_CONFDIR = "/etc/threatcrush/threatcrushd.conf.d";
|
|
11058
11057
|
var DEFAULT_CONFIG = {
|
|
11059
11058
|
daemon: {
|
|
@@ -11075,35 +11074,49 @@ var DEFAULT_CONFIG = {
|
|
|
11075
11074
|
config_dir: DEFAULT_CONFDIR
|
|
11076
11075
|
}
|
|
11077
11076
|
};
|
|
11078
|
-
function
|
|
11079
|
-
const
|
|
11080
|
-
|
|
11081
|
-
|
|
11082
|
-
|
|
11077
|
+
function parseConfigText(raw) {
|
|
11078
|
+
const parsed = import_toml.default.parse(raw);
|
|
11079
|
+
return {
|
|
11080
|
+
daemon: { ...DEFAULT_CONFIG.daemon, ...parsed.daemon },
|
|
11081
|
+
api: { ...DEFAULT_CONFIG.api, ...parsed.api },
|
|
11082
|
+
alerts: parsed.alerts || {},
|
|
11083
|
+
modules: { ...DEFAULT_CONFIG.modules, ...parsed.modules },
|
|
11084
|
+
remediation: parsed.remediation,
|
|
11085
|
+
detection: parsed.detection,
|
|
11086
|
+
cloud: parsed.cloud,
|
|
11087
|
+
watchdog: parsed.watchdog,
|
|
11088
|
+
update: parsed.update,
|
|
11089
|
+
threat_feeds: parsed.threat_feeds,
|
|
11090
|
+
privileged: parsed.privileged,
|
|
11091
|
+
lightning: parsed.lightning,
|
|
11092
|
+
storage: parsed.storage,
|
|
11093
|
+
// TOML's `[abuse-reporter]` parses to a hyphenated key; expose it under
|
|
11094
|
+
// the JS-friendly name the rest of the daemon reads.
|
|
11095
|
+
abuse_reporter: parsed["abuse-reporter"] ?? parsed.abuse_reporter,
|
|
11096
|
+
license: parsed.license
|
|
11097
|
+
};
|
|
11098
|
+
}
|
|
11099
|
+
function loadDaemonConfig(configPath, lastGoodPath) {
|
|
11100
|
+
if (!(0, import_node_fs13.existsSync)(configPath)) return { config: { ...DEFAULT_CONFIG }, usedLastGood: false };
|
|
11101
|
+
let raw = "";
|
|
11083
11102
|
try {
|
|
11084
|
-
|
|
11085
|
-
const
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
|
|
11099
|
-
|
|
11100
|
-
|
|
11101
|
-
// the JS-friendly name the rest of the daemon reads.
|
|
11102
|
-
abuse_reporter: parsed["abuse-reporter"] ?? parsed.abuse_reporter,
|
|
11103
|
-
license: parsed.license
|
|
11104
|
-
};
|
|
11105
|
-
} catch {
|
|
11106
|
-
return { ...DEFAULT_CONFIG };
|
|
11103
|
+
raw = (0, import_node_fs13.readFileSync)(configPath, "utf-8");
|
|
11104
|
+
const config = parseConfigText(raw);
|
|
11105
|
+
try {
|
|
11106
|
+
(0, import_node_fs13.mkdirSync)((0, import_node_path6.dirname)(lastGoodPath), { recursive: true });
|
|
11107
|
+
(0, import_node_fs13.writeFileSync)(lastGoodPath, raw, { mode: 384 });
|
|
11108
|
+
} catch {
|
|
11109
|
+
}
|
|
11110
|
+
return { config, usedLastGood: false };
|
|
11111
|
+
} catch (err) {
|
|
11112
|
+
const error = `${configPath} is not valid TOML: ${err.message.split("\n")[0]}`;
|
|
11113
|
+
try {
|
|
11114
|
+
if ((0, import_node_fs13.existsSync)(lastGoodPath)) {
|
|
11115
|
+
return { config: parseConfigText((0, import_node_fs13.readFileSync)(lastGoodPath, "utf-8")), error, usedLastGood: true };
|
|
11116
|
+
}
|
|
11117
|
+
} catch {
|
|
11118
|
+
}
|
|
11119
|
+
return { config: { ...DEFAULT_CONFIG }, error, usedLastGood: false };
|
|
11107
11120
|
}
|
|
11108
11121
|
}
|
|
11109
11122
|
function loadModuleConfigs(confDir) {
|
|
@@ -20978,7 +20991,11 @@ async function runDaemon() {
|
|
|
20978
20991
|
} catch (err) {
|
|
20979
20992
|
logLine(`[daemon] state db unavailable: ${err.message}`);
|
|
20980
20993
|
}
|
|
20981
|
-
const
|
|
20994
|
+
const loaded = loadDaemonConfig(PATHS.configFile, (0, import_node_path26.join)(PATHS.stateDir, "threatcrushd.conf.last-good"));
|
|
20995
|
+
const config = loaded.config;
|
|
20996
|
+
if (loaded.error) {
|
|
20997
|
+
logLine(`[daemon] CONFIG ERROR: ${loaded.error}; ${loaded.usedLastGood ? "running on the last config that parsed" : "no earlier good copy, running on DEFAULTS (no protected list)"}`);
|
|
20998
|
+
}
|
|
20982
20999
|
configureAttackDetection(config.detection);
|
|
20983
21000
|
const retentionSeconds = parseDuration(config.storage?.event_retention) ?? DEFAULT_EVENT_RETENTION_SECONDS;
|
|
20984
21001
|
const maxEvents = config.storage?.max_events ?? DEFAULT_MAX_EVENTS;
|
|
@@ -21079,6 +21096,16 @@ async function runDaemon() {
|
|
|
21079
21096
|
lightningWatch.start();
|
|
21080
21097
|
let cloudSyncRef = null;
|
|
21081
21098
|
new AlertDispatcher(bus, config, { cloudHealthy: () => cloudSyncRef?.healthy ?? false, log: logLine });
|
|
21099
|
+
if (loaded.error) {
|
|
21100
|
+
setTimeout(() => bus.publish({
|
|
21101
|
+
timestamp: /* @__PURE__ */ new Date(),
|
|
21102
|
+
module: "daemon",
|
|
21103
|
+
category: "system",
|
|
21104
|
+
severity: "critical",
|
|
21105
|
+
message: `threatcrushd.conf does not parse; ${loaded.usedLastGood ? "running on the last good copy" : "running on defaults with NO protected list"}: ${loaded.error}`.slice(0, 500),
|
|
21106
|
+
details: { rule_id: "daemon-config-invalid", used_last_good: loaded.usedLastGood }
|
|
21107
|
+
}), 15e3).unref?.();
|
|
21108
|
+
}
|
|
21082
21109
|
const runsWorker = new RunsWorker(bus, {
|
|
21083
21110
|
enabled: config.cloud?.enabled !== false && config.cloud?.runs === true,
|
|
21084
21111
|
scanRoots: Array.isArray(config.cloud?.run_scan_paths) ? config.cloud.run_scan_paths.filter((p) => typeof p === "string") : [],
|