@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/index.js
CHANGED
|
@@ -43574,11 +43574,21 @@ function trimMetadata(meta) {
|
|
|
43574
43574
|
let truncated = entries.length !== Object.keys(meta).length;
|
|
43575
43575
|
if (jsonBytes(out) > MAX_METADATA_BYTES) {
|
|
43576
43576
|
truncated = true;
|
|
43577
|
-
const
|
|
43578
|
-
|
|
43579
|
-
|
|
43580
|
-
|
|
43581
|
-
|
|
43577
|
+
const work = new Map(entries);
|
|
43578
|
+
const shrunk = /* @__PURE__ */ new Set();
|
|
43579
|
+
const size = () => jsonBytes({ ...Object.fromEntries(work), _truncated: true });
|
|
43580
|
+
while (work.size > 0 && size() > MAX_METADATA_BYTES) {
|
|
43581
|
+
const [key] = [...work.entries()].filter(([k]) => k !== "evidence" || !shrunk.has(k)).sort((a, b) => jsonBytes(b[1]) - jsonBytes(a[1]))[0] ?? [];
|
|
43582
|
+
if (key === void 0) break;
|
|
43583
|
+
if (!shrunk.has(key)) {
|
|
43584
|
+
const text = typeof work.get(key) === "string" ? work.get(key) : JSON.stringify(work.get(key));
|
|
43585
|
+
work.set(key, text.length > MAX_STRING_CHARS ? `${text.slice(0, MAX_STRING_CHARS)}\u2026` : text);
|
|
43586
|
+
shrunk.add(key);
|
|
43587
|
+
} else if (key !== "evidence") {
|
|
43588
|
+
work.delete(key);
|
|
43589
|
+
} else break;
|
|
43590
|
+
}
|
|
43591
|
+
out = Object.fromEntries(work);
|
|
43582
43592
|
}
|
|
43583
43593
|
return truncated ? { ...out, _truncated: true } : out;
|
|
43584
43594
|
}
|
|
@@ -45783,6 +45793,23 @@ function expire(window, now) {
|
|
|
45783
45793
|
window.head = 0;
|
|
45784
45794
|
}
|
|
45785
45795
|
}
|
|
45796
|
+
var EVIDENCE_MESSAGE_CHARS = 500;
|
|
45797
|
+
var EVIDENCE_FIELD_CHARS = 200;
|
|
45798
|
+
var EVIDENCE_FIELDS = ["unit", "identifier", "process", "comm", "pid", "user", "path", "method", "status", "host", "priority"];
|
|
45799
|
+
function evidenceOf(event) {
|
|
45800
|
+
const details = event.details ?? {};
|
|
45801
|
+
const out = {
|
|
45802
|
+
at: event.timestamp instanceof Date ? event.timestamp.toISOString() : String(event.timestamp ?? ""),
|
|
45803
|
+
module: event.module,
|
|
45804
|
+
message: String(event.message ?? "").slice(0, EVIDENCE_MESSAGE_CHARS)
|
|
45805
|
+
};
|
|
45806
|
+
if (event.source_ip) out.source_ip = event.source_ip;
|
|
45807
|
+
for (const k of EVIDENCE_FIELDS) {
|
|
45808
|
+
const v = details[k];
|
|
45809
|
+
if (typeof v === "string" || typeof v === "number") out[k] = String(v).slice(0, EVIDENCE_FIELD_CHARS);
|
|
45810
|
+
}
|
|
45811
|
+
return out;
|
|
45812
|
+
}
|
|
45786
45813
|
var RuleEngine = class {
|
|
45787
45814
|
constructor(onDetection) {
|
|
45788
45815
|
this.onDetection = onDetection;
|
|
@@ -45851,6 +45878,9 @@ var RuleEngine = class {
|
|
|
45851
45878
|
tags: rule.tags,
|
|
45852
45879
|
category: rule.category,
|
|
45853
45880
|
remediation: rule.remediation,
|
|
45881
|
+
// What actually happened: without this every alert, page and incident
|
|
45882
|
+
// could only repeat the rule's description ("a critical log message").
|
|
45883
|
+
evidence: evidenceOf(event),
|
|
45854
45884
|
...aggregate ? { group_by: groupBy, group: groupValue, distinct_ips: distinctIps, hits } : {}
|
|
45855
45885
|
}
|
|
45856
45886
|
});
|