Skip to content

Commit 14c612c

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 <[email protected]>
1 parent f7fb7a3 commit 14c612c

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

Diff for: 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[]

Diff for: 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.

Diff for: sideband.c

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

28+
static int allow_control_characters;
29+
2830
/* Returns a color setting (GIT_COLOR_NEVER, etc). */
2931
static int use_sideband_colors(void)
3032
{
@@ -38,6 +40,9 @@ static int use_sideband_colors(void)
3840
if (use_sideband_colors_cached >= 0)
3941
return use_sideband_colors_cached;
4042

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

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

Diff for: t/t5409-colorize-remote-messages.sh

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

114120
test_done

0 commit comments

Comments
 (0)