Skip to content

Commit 1b6a7ec

Browse files
Disable ANSI formatting for security autoconfiguration on Windows cmd line (#83326) (#83329)
In order to display formatted (bolded) autoconfiguration text on Windows cmd prompt using JANSI, one needs to invoke the SetConsoleMode Kernel32 API, via JANSI's AnsiConsole#install. But we lack the testing infra to properly assert the formatting behavior, so this PR disables ANSI-formatted output on Windows cmd prompt. Fixes: #83316
1 parent 43b587f commit 1b6a7ec

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

distribution/tools/ansi-console/src/main/java/org/elasticsearch/io/ansi/AnsiConsoleLoader.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ public ConsoleLoader.Console get() {
4040
// package-private for tests
4141
static @Nullable ConsoleLoader.Console newConsole(AnsiPrintStream out) {
4242
if (isValidConsole(out)) {
43-
return new ConsoleLoader.Console(out, () -> out.getTerminalWidth(), Ansi.isEnabled(), tryExtractPrintCharset(out));
43+
// virtual terminal does support ANSI escape sequences, but the JVM must toggle a mode
44+
// option on the console using the Kernel32 API, which JANSI knows to do, but ES currently lacks
45+
// the testing infra to assert the behavior
46+
boolean ansiEnabled = Ansi.isEnabled() && out.getType() != AnsiType.VirtualTerminal;
47+
return new ConsoleLoader.Console(out, () -> out.getTerminalWidth(), ansiEnabled, tryExtractPrintCharset(out));
4448
} else {
4549
return null;
4650
}

docs/changelog/83326.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 83326
2+
summary: Disable ANSI formatting for security autoconfiguration on Windows cmd line
3+
area: Security
4+
type: bug
5+
issues: []

0 commit comments

Comments
 (0)