Skip to content

Commit e6a6b9d

Browse files
committed
sideband: introduce an "escape hatch" to allow control characters
The preceding commit fixed the vulnerability whereas sideband messages (that are under the control of the remote server) could contain ANSI escape sequences that would be sent to the terminal verbatim. However, this fix may not be desirable under all circumstances, e.g. when remote servers deliberately add coloring to their messages to increase their urgency. To help with those use cases, give users a way to opt-out of the protections: `sideband.allowControlCharacters`. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 20dfd7e commit e6a6b9d

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

Documentation/config.txt

+2
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,8 @@ include::config/sequencer.txt[]
522522

523523
include::config/showbranch.txt[]
524524

525+
include::config/sideband.txt[]
526+
525527
include::config/sparse.txt[]
526528

527529
include::config/splitindex.txt[]

Documentation/config/sideband.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sideband.allowControlCharacters::
2+
By default, control characters that are delivered via the sideband
3+
are masked, to prevent potentially unwanted ANSI escape sequences
4+
from being sent to the terminal. Use this config setting to override
5+
this behavior.

sideband.c

+10
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ static struct keyword_entry keywords[] = {
2626
{ "error", GIT_COLOR_BOLD_RED },
2727
};
2828

29+
static int allow_control_characters;
30+
2931
/* Returns a color setting (GIT_COLOR_NEVER, etc). */
3032
static int use_sideband_colors(void)
3133
{
@@ -39,6 +41,9 @@ static int use_sideband_colors(void)
3941
if (use_sideband_colors_cached >= 0)
4042
return use_sideband_colors_cached;
4143

44+
git_config_get_bool("sideband.allowcontrolcharacters",
45+
&allow_control_characters);
46+
4247
if (!git_config_get_string_tmp(key, &value))
4348
use_sideband_colors_cached = git_config_colorbool(key, value);
4449
else if (!git_config_get_string_tmp("color.ui", &value))
@@ -68,6 +73,11 @@ void list_config_color_sideband_slots(struct string_list *list, const char *pref
6873

6974
static void strbuf_add_sanitized(struct strbuf *dest, const char *src, int n)
7075
{
76+
if (allow_control_characters) {
77+
strbuf_add(dest, src, n);
78+
return;
79+
}
80+
7181
strbuf_grow(dest, n);
7282
for (; n && *src; src++, n--) {
7383
if (!iscntrl(*src) || *src == '\t' || *src == '\n')

t/t5409-colorize-remote-messages.sh

+7-1
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,15 @@ test_expect_success 'disallow (color) control sequences in sideband' '
105105
EOF
106106
test_config_global uploadPack.packObjectshook ./color-me-surprised &&
107107
test_commit need-at-least-one-commit &&
108+
108109
git clone --no-local . throw-away 2>stderr &&
109110
test_decode_color <stderr >decoded &&
110-
test_grep ! RED decoded
111+
test_grep ! RED decoded &&
112+
113+
rm -rf throw-away &&
114+
git -c sideband.allowControlCharacters clone --no-local . throw-away 2>stderr &&
115+
test_decode_color <stderr >decoded &&
116+
test_grep RED decoded
111117
'
112118

113119
test_done

0 commit comments

Comments
 (0)