Make a string that originates in an attacker-controlled response — the error
detail (a JSON field, an Errors value or a text snippet), a FilterName or code quoted
from the filter columns, and the echoed Content-Type or charset — safe to print into an
error message on stderr:
Whole escape sequences (CSI, OSC and other control strings) are dropped first, then any
remaining C0 and C1 controls and DEL. JSON.parse decodes an escaped ESC into a real ESC
byte; printed raw, a hostile or MITM'd endpoint could drive ANSI/OSC sequences into the
terminal.
Unicode format characters (General Category Cf) are dropped: the bidi controls
(isBidiControl), so server text cannot reorder the visible message, and the invisible
ones — zero-width space/joiners, word joiner, soft hyphen, BOM — so two messages that look
identical are identical.
Every run of whitespace — newlines, tabs, U+2028/U+2029 included — becomes one
space and the ends are trimmed, so the text stays on one line and a server
cannot forge an Error: line of its own.
Only the first MAX_SERVER_TEXT (16 384) units are read, and every step is a linear regex
replace: a hostile error body costs neither seconds nor the heap. A caller that scrubs
credentials does so first, so a cut never splits one.
The CLI's JSON output is escaped separately (escapeControlChars in
cli/shared.ts): JSON.stringify alone leaves DEL, C1 and bidi characters raw.
Written with escapes so no raw control byte appears in this source.
Make a string that originates in an attacker-controlled response — the error
detail(a JSON field, anErrorsvalue or a text snippet), a FilterName or code quoted from the filter columns, and the echoed Content-Type or charset — safe to print into an error message on stderr:JSON.parsedecodes an escaped ESC into a real ESC byte; printed raw, a hostile or MITM'd endpoint could drive ANSI/OSC sequences into the terminal.Error:line of its own.The CLI's JSON output is escaped separately (
escapeControlCharsin cli/shared.ts):JSON.stringifyalone leaves DEL, C1 and bidi characters raw. Written with escapes so no raw control byte appears in this source.