/** * Sanitize a value for safe interpolation into log messages. * Strips ANSI escape sequences, C0/C1 control characters, and DEL to * prevent log forging / terminal escape injection (CWE-117).
*/
export function sanitizeForLog(v: string): string { // Pattern built at runtime so the source file stays free of literal control // characters AND the linter cannot statically detect them (no-control-regex). const c0Start = String.fromCharCode(0x00); const c0End = String.fromCharCode(0x1f); const del = String.fromCharCode(0x7f); const c1Start = String.fromCharCode(0x80); const c1End = String.fromCharCode(0x9f); const controlCharsRegex = new RegExp(`[${c0Start}-${c0End}${del}${c1Start}-${c1End}]`, "g"); return stripAnsi(v).replace(controlCharsRegex, "");
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.