// eslint-disable-next-line no-control-regex const CONTROL_CHARS_REGEX = /[\r\n\t\x00-\x1F\x7F]/g; /** * Strip CR, LF, tab, and other ASCII control characters from a value before * embedding it in a log line. Prevents log-injection attacks where untrusted * input could forge multi-line log entries or terminal escape sequences. * * Use at every site where a user-controlled string flows into console.log / * console.warn / console.error, including via template literals. */ export function sanitizeForLog(value: unknown): string { const s = typeof value === 'string' ? value : String(value); return s.replace(CONTROL_CHARS_REGEX, ''); }