+ Bytes consumed from an HTTP response body are server-controlled and may + contain ANSI escape sequences. When those bytes reach a terminal writer + without sanitization, a remote attacker can move the cursor, repaint the + screen, fake a shell prompt, write to the clipboard via OSC sequences, + or otherwise manipulate the user's terminal session. +
+
+ This query flags HTTP response content, including bytes reintroduced by
+ base64 decoding, that reaches a terminal writer
+ (IOStreams.Out, IOStreams.ErrOut,
+ os.Stdout, or os.Stderr) without first being
+ written to IOStreams.ContentOut, sanitized, or decoded as a
+ structured format (e.g. encoding/json).
+
+ Choose the writer based on the kind of content you are printing: +
+IOStreams.Out is for application output the developer
+ authored: tables, prompts, formatted messages, color-coded status. It
+ does not sanitize and never should, because the developer controls
+ every byte that reaches it.
+ IOStreams.ContentOut is for external content the
+ developer did not author: HTTP response bodies, file contents fetched
+ from a remote, anything where a third party chose the bytes. It
+ sanitizes ANSI escape sequences by default.
+ + These patterns satisfy the query: +
+iostreams.Untrusted and
+ print it with String() (or any fmt verb, which
+ calls String()); the value sanitizes itself. Its
+ Raw() method is the explicit opt-out and is still flagged if
+ it reaches a terminal.
+ IOStreams.ContentOut.
+ json.Unmarshal, (*json.Decoder).Decode);
+ the fields you print afterwards are no longer raw external content.
+ --allow-escape-sequences flag and call
+ opts.IO.SetContentSanitization(false) before writing.
+ The bytes still go through ContentOut, but ContentOut
+ becomes a passthrough for that invocation.
+
+ In the following BAD example, the response body is written directly to
+ IOStreams.Out. A server can embed ANSI escape sequences in
+ the response and they will be rendered by the user's terminal:
+
+ In the following GOOD example, the same body is written to
+ IOStreams.ContentOut, which sanitizes ANSI escape
+ sequences. An --allow-escape-sequences flag is provided for users who
+ explicitly want raw output for trusted content:
+