Function: sanitizeForLogging()
sanitizeForLogging<Defined in: crypto.ts:264 Recursively shallow-copy an object, replacing any field whose key contains a sensitive substring (case-insensitive) withT>(obj,sensitiveFields?):Partial<T>
[REDACTED],
and masking string fields whose key contains "email" via
maskEmail.
Designed for log structures — preserves shape so log queries continue
to work, but ensures secrets and identifiers don’t leak. Use as a
defensive layer before writing structured log lines.
Type Parameters
T
T extends Record<string, unknown>
Parameters
obj
T
Object to sanitize. Original is not mutated.
sensitiveFields?
string[] = ...
Substring allow-list. Defaults to
["password", "passwordHash", "token", "secret", "twoFactorSecret", "apiKey"]. Substrings match anywhere in the
key, e.g. "token" matches "refreshToken" and "id_token".
Returns
Partial<T>
A new object with sensitive fields redacted and emails
masked. Nested objects are recursed; arrays and primitives pass
through unchanged.