(value: string)
| 184 | * without leaking the account name. |
| 185 | */ |
| 186 | export function sanitizeString(value: string): string { |
| 187 | const home = process.env.HOME || homedir(); |
| 188 | const username = userInfo().username; |
| 189 | const userHash = `<USER:${currentUserHash()}>`; |
| 190 | let sanitized = redactSecretString(value); |
| 191 | if (home) { |
| 192 | sanitized = sanitized.replace(new RegExp(escapeRegex(home), "g"), "<HOME>"); |
| 193 | } |
| 194 | sanitized = sanitized.replace(/\/Users\/[^/]+\//g, `/Users/${userHash}/`); |
| 195 | sanitized = sanitized.replace(/\/home\/[^/]+\//g, `/home/${userHash}/`); |
| 196 | sanitized = sanitized.replace(/C:\\Users\\[^\\]+\\/g, `C:\\Users\\${userHash}\\`); |
| 197 | if (username) { |
| 198 | sanitized = sanitized.replace(new RegExp(escapeRegex(username), "g"), userHash); |
| 199 | } |
| 200 | return sanitized; |
| 201 | } |
| 202 | |
| 203 | function shouldRedactKey(key: string): boolean { |
| 204 | return /api[_-]?key|token|secret|password|authorization|cookie/i.test(key); |
no test coverage detected