Skip to content

Commit a8c289b

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 5b25741 commit a8c289b

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

Documentation/config.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,8 @@ include::config/sequencer.txt[]
511511

512512
include::config/showbranch.txt[]
513513

514+
include::config/sideband.txt[]
515+
514516
include::config/sparse.txt[]
515517

516518
include::config/splitindex.txt[]

Documentation/config/sideband.txt

Lines changed: 5 additions & 0 deletions
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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ static struct keyword_entry keywords[] = {
2020
{ "error", GIT_COLOR_BOLD_RED },
2121
};
2222

23+
static int allow_control_characters;
24+
2325
/* Returns a color setting (GIT_COLOR_NEVER, etc). */
2426
static int use_sideband_colors(void)
2527
{
@@ -33,6 +35,9 @@ static int use_sideband_colors(void)
3335
if (use_sideband_colors_cached >= 0)
3436
return use_sideband_colors_cached;
3537

38+
git_config_get_bool("sideband.allowcontrolcharacters",
39+
&allow_control_characters);
40+
3641
if (!git_config_get_string(key, &value)) {
3742
use_sideband_colors_cached = git_config_colorbool(key, value);
3843
} else if (!git_config_get_string("color.ui", &value)) {
@@ -63,6 +68,11 @@ void list_config_color_sideband_slots(struct string_list *list, const char *pref
6368

6469
static void strbuf_add_sanitized(struct strbuf *dest, const char *src, int n)
6570
{
71+
if (allow_control_characters) {
72+
strbuf_add(dest, src, n);
73+
return;
74+
}
75+
6676
strbuf_grow(dest, n);
6777
for (; n && *src; src++, n--) {
6878
if (!iscntrl(*src) || *src == '\t' || *src == '\n')

t/t5409-colorize-remote-messages.sh

Lines changed: 7 additions & 1 deletion
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_i18ngrep ! RED decoded
111+
test_i18ngrep ! 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_i18ngrep RED decoded
111117
'
112118

113119
test_done

0 commit comments

Comments
 (0)