(value, depth = 0)
| 22 | ].join('|'), 'gi'); |
| 23 | |
| 24 | function redactValue(value, depth = 0) { |
| 25 | if (depth > 8) return '[REDACTED_DEPTH]'; |
| 26 | if (Array.isArray(value)) return value.map((entry) => redactValue(entry, depth + 1)); |
| 27 | if (!value || typeof value !== 'object') { |
| 28 | return typeof value === 'string' ? redactText(value) : value; |
| 29 | } |
| 30 | |
| 31 | const out = {}; |
| 32 | for (const [key, child] of Object.entries(value)) { |
| 33 | if (SECRET_KEY_RE.test(key)) { |
| 34 | out[key] = '[REDACTED]'; |
| 35 | } else if (isLargeSensitiveField(key, child)) { |
| 36 | out[key] = '[REDACTED_SENSITIVE_DETAIL]'; |
| 37 | } else { |
| 38 | out[key] = redactValue(child, depth + 1); |
| 39 | } |
| 40 | } |
| 41 | return out; |
| 42 | } |
| 43 | |
| 44 | function redactText(text) { |
| 45 | if (typeof text !== 'string') return text; |
no test coverage detected