(key: string, value: unknown)
| 6 | const SENSITIVE_KEY_PATTERN = /(api[_-]?key|token|password|passwd|secret|authorization|auth(?!or)|access[_-]?key|private[_-]?key|client[_-]?secret|bearer|x[_-]api[_-]key|session[_-]?id)/i; |
| 7 | |
| 8 | export function redactValue(key: string, value: unknown): unknown { |
| 9 | if (SENSITIVE_KEY_PATTERN.test(key)) { |
| 10 | if (typeof value === 'string' && value.length > 0) { |
| 11 | // Keep first 2 chars so the user knows something is set, redact the rest |
| 12 | const visible = value.slice(0, 2); |
| 13 | return `${visible}***[redacted ${value.length} chars]`; |
| 14 | } |
| 15 | return '[redacted]'; |
| 16 | } |
| 17 | return value; |
| 18 | } |
| 19 | |
| 20 | export function redactObject<T extends Record<string, unknown>>(obj: T): Record<string, unknown> { |
| 21 | const out: Record<string, unknown> = {}; |
no outgoing calls
no test coverage detected