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
26 lines (22 loc) 路 868 Bytes
/
Copy pathredact.js
File metadata and controls
26 lines (22 loc) 路 868 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
'use strict';
/**
* Secret redaction module for fatal-guard.
* Independently testable (Step 4 / T16).
*/
const PATTERNS = [
{ name: 'jwt', re: /eyJ[\w-]+\.[\w-]+\.[\w-]+/g },
{ name: 'dsn', re: /(?:postgres|postgresql|mysql|mongodb|redis|amqp):\/\/[^\s"']+/gi },
{ name: 'aws_key', re: /AKIA[0-9A-Z]{16}/g },
{ name: 'gcp_key', re: /AIza[0-9A-Za-z_\-]{35}/g },
{ name: 'openai', re: /sk-[A-Za-z0-9]{20,}/g },
{ name: 'gh_token', re: /gh[pousr]_[A-Za-z0-9]{36,}/g },
{ name: 'authz', re: /(?:authorization|x-api-key|cookie|set-cookie)\s*[:=]\s*[^\s'"]+/gi },
{ name: 'long_tok', re: /\b[A-Za-z0-9_\-]{40,}\b/g },
];
function redact(s) {
if (typeof s !== 'string' || !s) return s;
let out = s;
for (const p of PATTERNS) out = out.replace(p.re, `[REDACTED:${p.name}]`);
return out;
}
module.exports = { redact, PATTERNS };