]> git.kaiwu.me - haproxy.git/commit
MINOR: ring: add "-s" flag to "show events" to sanitize the output
authorWilly Tarreau <w@1wt.eu>
Sat, 15 Aug 2026 18:43:58 +0000 (20:43 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 3 Sep 2026 05:47:17 +0000 (07:47 +0200)
commit76a739c5deafb7bfe5f5ab341d85e0d66f83c54a
tree8c3b1e1be86fc8860f41fda630fc3d5a6c51537f
parenteefc5312f5c075025073d8fdff9299c5ac346d66
MINOR: ring: add "-s" flag to "show events" to sanitize the output

"show events" and the other ring dumps (show startup-logs, show errors)
emit each ring message verbatim via applet_append_line(). Rings can hold
attacker-influenced contents (forwarded syslog lines, log-format output
emitted without "+E") that contains ESC, CR, LF or BS. Because the CLI
writes the result straight to the user's terminal, such a dump can for
example inject ANSI escape sequences and rewrite the screen, BS and
visually erase some fields on the screen, or even use UNICODE code points
that switch the writing direction from LTR to RTL and conversely.

This patch adds an opt-in "-s" flag to "show events", in order to sanitize
displayed strings. When set, each event is copied into the thread-local
trash chunk and every byte is sanitised before being appended: whitespaces
(spaces and tabs) are printed as a space, any other control character
(ESC, CR, LF, NUL, ...) as well as non-ASCII as '?', and everything else
verbatim. The behaviour is selected by a new RING_WF_SANITIZE watch flag
that switches cli_io_handler_show_ring() to a dedicated appender
(show_ring_append_escaped()) instead of applet_append_line().

The sanitisation is open-coded rather than reusing existing functions
which would stop at NUL. Here we must walk exactly <len> bytes and keep
the output length identical to the input so that offsets stay valid.

The flag is opt-in on purpose: the primary use of "show events" is a
byte-for-byte tail of the log ring piped into grep/awk/parser, or even
the dataplane API, and escaping by default would corrupt that. Users
who who want a safe output should just pass "-s". Default output is
unchanged. Maybe we could change the default in a future version if
there is demand.

No backport needed though it can be useful if it's easily done.

Reported-by: Claude (ANT-2026-ER52H2CR)
doc/management.txt
include/haproxy/ring-t.h
src/ring.c
src/sink.c