@profullstack/threatcrush 0.13.60 → 0.13.61
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 +35 -5
- package/dist/daemon.js.map +1 -1
- package/dist/index.js +35 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/daemon.js
CHANGED
|
@@ -11692,11 +11692,21 @@ function trimMetadata(meta) {
|
|
|
11692
11692
|
let truncated = entries.length !== Object.keys(meta).length;
|
|
11693
11693
|
if (jsonBytes(out) > MAX_METADATA_BYTES) {
|
|
11694
11694
|
truncated = true;
|
|
11695
|
-
const
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
|
|
11695
|
+
const work = new Map(entries);
|
|
11696
|
+
const shrunk = /* @__PURE__ */ new Set();
|
|
11697
|
+
const size = () => jsonBytes({ ...Object.fromEntries(work), _truncated: true });
|
|
11698
|
+
while (work.size > 0 && size() > MAX_METADATA_BYTES) {
|
|
11699
|
+
const [key] = [...work.entries()].filter(([k]) => k !== "evidence" || !shrunk.has(k)).sort((a, b) => jsonBytes(b[1]) - jsonBytes(a[1]))[0] ?? [];
|
|
11700
|
+
if (key === void 0) break;
|
|
11701
|
+
if (!shrunk.has(key)) {
|
|
11702
|
+
const text = typeof work.get(key) === "string" ? work.get(key) : JSON.stringify(work.get(key));
|
|
11703
|
+
work.set(key, text.length > MAX_STRING_CHARS ? `${text.slice(0, MAX_STRING_CHARS)}\u2026` : text);
|
|
11704
|
+
shrunk.add(key);
|
|
11705
|
+
} else if (key !== "evidence") {
|
|
11706
|
+
work.delete(key);
|
|
11707
|
+
} else break;
|
|
11708
|
+
}
|
|
11709
|
+
out = Object.fromEntries(work);
|
|
11700
11710
|
}
|
|
11701
11711
|
return truncated ? { ...out, _truncated: true } : out;
|
|
11702
11712
|
}
|
|
@@ -18172,6 +18182,23 @@ function expire(window, now) {
|
|
|
18172
18182
|
window.head = 0;
|
|
18173
18183
|
}
|
|
18174
18184
|
}
|
|
18185
|
+
var EVIDENCE_MESSAGE_CHARS = 500;
|
|
18186
|
+
var EVIDENCE_FIELD_CHARS = 200;
|
|
18187
|
+
var EVIDENCE_FIELDS = ["unit", "identifier", "process", "comm", "pid", "user", "path", "method", "status", "host", "priority"];
|
|
18188
|
+
function evidenceOf(event) {
|
|
18189
|
+
const details = event.details ?? {};
|
|
18190
|
+
const out = {
|
|
18191
|
+
at: event.timestamp instanceof Date ? event.timestamp.toISOString() : String(event.timestamp ?? ""),
|
|
18192
|
+
module: event.module,
|
|
18193
|
+
message: String(event.message ?? "").slice(0, EVIDENCE_MESSAGE_CHARS)
|
|
18194
|
+
};
|
|
18195
|
+
if (event.source_ip) out.source_ip = event.source_ip;
|
|
18196
|
+
for (const k of EVIDENCE_FIELDS) {
|
|
18197
|
+
const v = details[k];
|
|
18198
|
+
if (typeof v === "string" || typeof v === "number") out[k] = String(v).slice(0, EVIDENCE_FIELD_CHARS);
|
|
18199
|
+
}
|
|
18200
|
+
return out;
|
|
18201
|
+
}
|
|
18175
18202
|
var RuleEngine = class {
|
|
18176
18203
|
constructor(onDetection) {
|
|
18177
18204
|
this.onDetection = onDetection;
|
|
@@ -18240,6 +18267,9 @@ var RuleEngine = class {
|
|
|
18240
18267
|
tags: rule.tags,
|
|
18241
18268
|
category: rule.category,
|
|
18242
18269
|
remediation: rule.remediation,
|
|
18270
|
+
// What actually happened: without this every alert, page and incident
|
|
18271
|
+
// could only repeat the rule's description ("a critical log message").
|
|
18272
|
+
evidence: evidenceOf(event),
|
|
18243
18273
|
...aggregate ? { group_by: groupBy, group: groupValue, distinct_ips: distinctIps, hits } : {}
|
|
18244
18274
|
}
|
|
18245
18275
|
});
|