forked from Ikalus1988/MisakaNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredact.js
More file actions
38 lines (34 loc) · 982 Bytes
/
Copy pathredact.js
File metadata and controls
38 lines (34 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Shared redaction module — single source of truth for secret patterns.
*
* Both the /api/intake route and the MCP misakanet_submit_intake tool
* use this module. Patterns live in redact-patterns.json.
*/
const patterns = require("./redact-patterns.json");
const compiled = patterns.map((p) => ({
id: p.id,
regex: new RegExp(p.pattern, p.flags),
replacement: p.replacement,
}));
/**
* Redact secrets from text. Truncates to maxLen characters.
* @param {string} text
* @param {number} [maxLen=2000]
* @returns {string}
*/
function redactText(text, maxLen = 2000) {
if (!text) return "";
let result = String(text).slice(0, maxLen);
for (const { regex, replacement } of compiled) {
result = result.replace(regex, replacement);
}
return result;
}
/**
* Return the list of pattern IDs for diagnostics.
* @returns {string[]}
*/
function patternIds() {
return compiled.map((p) => p.id);
}
module.exports = { redactText, patternIds, patterns };