From 8e0d765d1d7ebf3375e9d82b27ffeb486c5be930 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Feb 2026 18:32:14 +0100 Subject: [PATCH] fix: avoid control-regex lint failure in ws header sanitizer (openclaw#15594) thanks @TsekaLuk --- src/gateway/server/ws-connection.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/gateway/server/ws-connection.ts b/src/gateway/server/ws-connection.ts index 43bda018023..7ecbefda4ee 100644 --- a/src/gateway/server/ws-connection.ts +++ b/src/gateway/server/ws-connection.ts @@ -19,15 +19,29 @@ import { attachGatewayWsMessageHandler } from "./ws-connection/message-handler.j type SubsystemLogger = ReturnType; const LOG_HEADER_MAX_LEN = 300; -const LOG_HEADER_CONTROL_REGEX = /[\u0000-\u001f\u007f-\u009f]/g; const LOG_HEADER_FORMAT_REGEX = /\p{Cf}/gu; +function replaceControlChars(value: string): string { + let cleaned = ""; + for (const char of value) { + const codePoint = char.codePointAt(0); + if ( + codePoint !== undefined && + (codePoint <= 0x1f || (codePoint >= 0x7f && codePoint <= 0x9f)) + ) { + cleaned += " "; + continue; + } + cleaned += char; + } + return cleaned; +} + const sanitizeLogValue = (value: string | undefined): string | undefined => { if (!value) { return undefined; } - const cleaned = value - .replace(LOG_HEADER_CONTROL_REGEX, " ") + const cleaned = replaceControlChars(value) .replace(LOG_HEADER_FORMAT_REGEX, " ") .replace(/\s+/g, " ") .trim();