Untrusted CSV field values are printed to the terminal without escaping (terminal escape injection)
Summary.
mlrwrites field values verbatim to the terminal. A CSV field containing an ANSI/OSC escape sequence is interpreted by the terminal, allowing e.g. silent clipboard writes (OSC 52), window-title spoofing (OSC 0/2) or screen clearing.Affected code.
pkg/output/record_writer_pprint.go:229(writeHeterogenousListBarred→WriteString(colorizer.MaybeColorizeValue(s, …))); the same applies topkg/output/record_writer_csv.go. The colorizer only adds SGR codes and never rewrites the value.Reproduce:
python3 - <<'PY' import base64; B64=base64.b64encode(b"TUI-INJECTION-POC").decode() open("evil.csv","w").write('id,note\n1,"\x1b]52;c;%s\x07"\n' % B64) PY mlr --icsv --opprint cat evil.csv | cat -v # observe ^[]52;c;...In a terminal supporting OSC 52,
${B64}is written into the clipboard.Expected. As
cat -vdoes, escape/C0/C1 bytes that are "terminal-active" (ESC, BEL, and the sequences they start) should be replaced (e.g. with^[,^G). An opt-out flag could preserve the current behaviour.Here is my test:
Environment. Ubuntu 22.04.5 LTS (GNU/Linux 6.8.0-124-generic x86_64).
Source: johnkerl/miller