@socprime/logtotal-sanitizer 0.2.0-beta.0 → 0.2.0-beta.1
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/CHANGELOG.md +11 -0
- package/{chunk-ISVRNSZF.cjs → chunk-ABKPPAHE.cjs} +15 -4
- package/chunk-ABKPPAHE.cjs.map +1 -0
- package/{chunk-5R34WEOD.js → chunk-MNU2FHP5.js} +15 -4
- package/chunk-MNU2FHP5.js.map +1 -0
- package/{chunk-DBC5DTD5.cjs → chunk-S3UWVOOK.cjs} +57 -40
- package/chunk-S3UWVOOK.cjs.map +1 -0
- package/{chunk-FUDPRHOC.js → chunk-SZLS55UR.js} +33 -16
- package/chunk-SZLS55UR.js.map +1 -0
- package/cli.js +43 -15
- package/cli.js.map +1 -1
- package/{index-HPy5z0l3.d.cts → index-BYhIh1ru.d.cts} +6 -0
- package/{index-HPy5z0l3.d.ts → index-BYhIh1ru.d.ts} +6 -0
- package/index.cjs +25 -25
- package/index.d.cts +2 -2
- package/index.d.ts +2 -2
- package/index.js +2 -2
- package/node.cjs +27 -27
- package/node.d.cts +2 -2
- package/node.d.ts +2 -2
- package/node.js +3 -3
- package/package.json +1 -1
- package/rules.cjs +5 -5
- package/rules.d.cts +1 -1
- package/rules.d.ts +1 -1
- package/rules.js +1 -1
- package/chunk-5R34WEOD.js.map +0 -1
- package/chunk-DBC5DTD5.cjs.map +0 -1
- package/chunk-FUDPRHOC.js.map +0 -1
- package/chunk-ISVRNSZF.cjs.map +0 -1
package/cli.js
CHANGED
|
@@ -1571,13 +1571,15 @@ var hostnamesRule = {
|
|
|
1571
1571
|
"host",
|
|
1572
1572
|
"fqdn",
|
|
1573
1573
|
"domain",
|
|
1574
|
+
"computer",
|
|
1574
1575
|
"computerName",
|
|
1575
1576
|
"serverName",
|
|
1576
1577
|
"nodeName",
|
|
1577
1578
|
"dnsName",
|
|
1578
1579
|
"machineName",
|
|
1579
1580
|
"targetHost"
|
|
1580
|
-
]
|
|
1581
|
+
],
|
|
1582
|
+
jsonKeyContains: ["computer", "domainname"]
|
|
1581
1583
|
};
|
|
1582
1584
|
|
|
1583
1585
|
// src/rules/definitions/ipAddresses.ts
|
|
@@ -2366,7 +2368,8 @@ var usersRule = {
|
|
|
2366
2368
|
"surname",
|
|
2367
2369
|
"userId",
|
|
2368
2370
|
"uid"
|
|
2369
|
-
]
|
|
2371
|
+
],
|
|
2372
|
+
jsonKeyContains: ["owner", "username"]
|
|
2370
2373
|
};
|
|
2371
2374
|
|
|
2372
2375
|
// src/rules/registry.ts
|
|
@@ -2862,27 +2865,44 @@ function looksLikeJson(line) {
|
|
|
2862
2865
|
function normalizeKey2(key) {
|
|
2863
2866
|
return key.toLowerCase().replace(/[-_]/g, "");
|
|
2864
2867
|
}
|
|
2865
|
-
function
|
|
2866
|
-
const
|
|
2868
|
+
function buildJsonKeyMatcher(rules) {
|
|
2869
|
+
const exact = /* @__PURE__ */ new Map();
|
|
2870
|
+
const contains = [];
|
|
2867
2871
|
for (const rule of rules) {
|
|
2868
2872
|
for (const key of rule.jsonKeys ?? []) {
|
|
2869
2873
|
const normalized = normalizeKey2(key);
|
|
2870
|
-
if (!
|
|
2871
|
-
|
|
2874
|
+
if (!exact.has(normalized)) {
|
|
2875
|
+
exact.set(normalized, rule);
|
|
2872
2876
|
}
|
|
2873
2877
|
}
|
|
2878
|
+
for (const fragment of rule.jsonKeyContains ?? []) {
|
|
2879
|
+
contains.push({ fragment: normalizeKey2(fragment), rule });
|
|
2880
|
+
}
|
|
2881
|
+
}
|
|
2882
|
+
return { exact, contains };
|
|
2883
|
+
}
|
|
2884
|
+
function resolveJsonKeyRule(matcher, key) {
|
|
2885
|
+
const normalized = normalizeKey2(key);
|
|
2886
|
+
const exact = matcher.exact.get(normalized);
|
|
2887
|
+
if (exact) {
|
|
2888
|
+
return exact;
|
|
2889
|
+
}
|
|
2890
|
+
for (const entry of matcher.contains) {
|
|
2891
|
+
if (normalized.includes(entry.fragment)) {
|
|
2892
|
+
return entry.rule;
|
|
2893
|
+
}
|
|
2874
2894
|
}
|
|
2875
|
-
return
|
|
2895
|
+
return void 0;
|
|
2876
2896
|
}
|
|
2877
|
-
var
|
|
2878
|
-
function
|
|
2879
|
-
const cached =
|
|
2897
|
+
var jsonKeyMatcherCache = /* @__PURE__ */ new WeakMap();
|
|
2898
|
+
function jsonKeyMatcher(rules) {
|
|
2899
|
+
const cached = jsonKeyMatcherCache.get(rules);
|
|
2880
2900
|
if (cached) {
|
|
2881
2901
|
return cached;
|
|
2882
2902
|
}
|
|
2883
|
-
const
|
|
2884
|
-
|
|
2885
|
-
return
|
|
2903
|
+
const matcher = buildJsonKeyMatcher(rules);
|
|
2904
|
+
jsonKeyMatcherCache.set(rules, matcher);
|
|
2905
|
+
return matcher;
|
|
2886
2906
|
}
|
|
2887
2907
|
function mergeCounts(target, source) {
|
|
2888
2908
|
for (const [id, count] of Object.entries(source)) {
|
|
@@ -2972,7 +2992,7 @@ function redactJsonLine(line, ctx, options = {}) {
|
|
|
2972
2992
|
const withSegments = options.withSegments ?? false;
|
|
2973
2993
|
const withMatches = options.withMatches ?? false;
|
|
2974
2994
|
const collectOriginals = withMatches || withSegments;
|
|
2975
|
-
const
|
|
2995
|
+
const keyMatcher = jsonKeyMatcher(ctx.rules);
|
|
2976
2996
|
const counts = {};
|
|
2977
2997
|
const matches = [];
|
|
2978
2998
|
const originals = [];
|
|
@@ -2995,7 +3015,7 @@ function redactJsonLine(line, ctx, options = {}) {
|
|
|
2995
3015
|
};
|
|
2996
3016
|
const redactValue = (value, key) => {
|
|
2997
3017
|
if (typeof value === "string") {
|
|
2998
|
-
const fieldRule = key === void 0 ? void 0 :
|
|
3018
|
+
const fieldRule = key === void 0 ? void 0 : resolveJsonKeyRule(keyMatcher, key);
|
|
2999
3019
|
if (fieldRule) {
|
|
3000
3020
|
if (isAllowed(ctx.allow, fieldRule.id, value)) {
|
|
3001
3021
|
return value;
|
|
@@ -3220,6 +3240,14 @@ function validateRule(rule) {
|
|
|
3220
3240
|
requireText(key, id, `jsonKeys[${index}]`);
|
|
3221
3241
|
}
|
|
3222
3242
|
}
|
|
3243
|
+
if (rule.jsonKeyContains !== void 0) {
|
|
3244
|
+
if (!Array.isArray(rule.jsonKeyContains)) {
|
|
3245
|
+
throw new InvalidRuleError(`Rule "${id}": \`jsonKeyContains\` must be an array of strings.`);
|
|
3246
|
+
}
|
|
3247
|
+
for (const [index, fragment] of rule.jsonKeyContains.entries()) {
|
|
3248
|
+
requireText(fragment, id, `jsonKeyContains[${index}]`);
|
|
3249
|
+
}
|
|
3250
|
+
}
|
|
3223
3251
|
if (rule.validate !== void 0 && typeof rule.validate !== "function") {
|
|
3224
3252
|
throw new InvalidRuleError(`Rule "${id}": \`validate\` must be a function.`);
|
|
3225
3253
|
}
|