Make a string that originates in an attacker-controlled response — the error
detail — safe to print into an error message on stderr:
C0 and C1 controls and DEL are dropped. A JSON error body can encode an escape
(U+001B) that JSON.parse turns into a real control byte; printed raw, a hostile
or MITM'd endpoint could drive ANSI/OSC sequences into the terminal (display
spoofing, title changes).
Bidi formatting characters (isBidiControl) are dropped, so server text cannot
reorder the visible message.
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.
The CLI's JSON output is escaped separately (escapeControlChars in
cli/shared.ts): JSON.stringify alone leaves DEL, C1 and bidi characters raw.
Written as a char-code filter so no raw control byte appears in this source.
Make a string that originates in an attacker-controlled response — the error
detail— safe to print into an error message on stderr: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 as a char-code filter so no raw control byte appears in this source.