* Redact secrets from a string. Returns the string with sensitive * substrings replaced by [REDACTED: ]. Original input is never mutated. * Empty/non-string inputs pass through unchanged.
(input)
| 62 | * Empty/non-string inputs pass through unchanged. |
| 63 | */ |
| 64 | function redactString(input) { |
| 65 | if (typeof input !== 'string' || input.length === 0) return input; |
| 66 | let out = input; |
| 67 | for (const { name, re } of SECRET_PATTERNS) { |
| 68 | if (name === 'env_api_key') { |
| 69 | // Preserve the variable name, redact the value. |
| 70 | out = out.replace(re, (_, k) => `${k}=[REDACTED:env_value]`); |
| 71 | } else { |
| 72 | out = out.replace(re, `[REDACTED:${name}]`); |
| 73 | } |
| 74 | } |
| 75 | return out; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Recursively redact a value (object, array, or primitive). |
no outgoing calls
no test coverage detected