Conhost/ConPTY as used by Win32 Open-SSH inserts/modifies ANSI escape codes (specifically testing bolded text) #12136

Closed
opened 2026-01-31 03:07:11 +00:00 by claunia · 6 comments
Owner

Originally created by @bavis-m on GitHub (Jan 22, 2021).

Environment

Windows build number: 10.0.19041.746
Windows Terminal version (if applicable): Preview v1.5.3242.0\

The Problem

My color scheme in Windows Terminal has default black text, and the default foreground bold color (<ESC>[1m) comes out dark grey. I'm assuming this is due to Windows Terminal using bright colors since we have no actual bold font support.

The default foreground bold color fails to work correctly when ssh-ing into a machine running the windows OpenSSH server (as installed from the Optional Features settings page). It comes out as bright white (color 97 for 256 color supporting terminals). It doesn't appear to matter what the shell on the other end is, I've tested this using both bash.exe as the shell, or the default cmd.exe. All that matters is that sshd allocates a pty.

Steps to reproduce

On a machine running Win32 OpenSSH server, make a script that outputs some default fg color bolded text.

For instance, if bash.exe is your shell, test.sh with contents:

#! /usr/bin/env bash
echo -e "\e[1m Bold Text \e[m"

If cmd.exe is you shell, try test.bat:

forfiles /m some_file_in_your_default_folder /c "cmd /c echo 0x1B[1m Bold Text 0x1B[m"

Then, ssh into that machine from a terminal (note this works with either Windows Terminal, or the default conhost.exe terminal, and it doesn't matter what your local shell is, WSL or cmd.exe) and run the command. It is helpful if you are in a color scheme that has a white background and a dark foreground color.

ssh user@targetmachine test.sh will write Bold Text to the terminal with correct ("light black") colors.

ssh -t user@targetmachine test.sh will write Bold Text to the terminal in bright white text. This is easily visible by showing the control codes themselves:

ssh -t user@targetmachine test.sh | sed 's/\x1b/\\e/g' Will show something like: \e[2J\e[m\e[H\e]0;C:\WINDOWS\system32\conhost.exe\e[?25h\e[1m\e[97m Bold Text \e[m

You can clearly see, along with sending an additional code to set the terminal title string, it changes <ESC>[1m to <ESC>[1m<ESC>[97m

Expected behavior

conhost.exe leaves my terminal control codes well enough alone.

I'm not sure if this is the right place for this, if conhost.exe is doing this, or if I'm even understanding/diagnosing the problem 100% correctly. I'll also crosspost this to PowerShell/Win32-OpenSSH on github.

NOTE: I do not see this incorrect behaviour if I ssh into sshd running as a service in WSL, i.e. apt get openssh-server && service sshd start.

Originally created by @bavis-m on GitHub (Jan 22, 2021). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> <!-- This bug tracker is monitored by Windows Terminal development team and other technical folks. **Important: When reporting BSODs or security issues, DO NOT attach memory dumps, logs, or traces to Github issues**. Instead, send dumps/traces to secure@microsoft.com, referencing this GitHub issue. If this is an application crash, please also provide a Feedback Hub submission link so we can find your diagnostic data on the backend. Use the category "Apps > Windows Terminal (Preview)" and choose "Share My Feedback" after submission to get the link. Please use this form and describe your issue, concisely but precisely, with as much detail as possible. --> # Environment ```none Windows build number: 10.0.19041.746 Windows Terminal version (if applicable): Preview v1.5.3242.0\ ``` # The Problem My color scheme in Windows Terminal has default black text, and the default foreground bold color (`<ESC>[1m`) comes out dark grey. I'm assuming this is due to Windows Terminal using bright colors since we have no actual bold font support. The default foreground bold color fails to work correctly when ssh-ing into a machine running the windows OpenSSH server (as installed from the Optional Features settings page). It comes out as bright white (color 97 for 256 color supporting terminals). It doesn't appear to matter what the shell on the other end is, I've tested this using both `bash.exe` as the shell, or the default `cmd.exe`. All that matters is that sshd allocates a pty. <!-- A description of how to trigger this bug. --> # Steps to reproduce On a machine running Win32 OpenSSH server, make a script that outputs some default fg color bolded text. For instance, if bash.exe is your shell, `test.sh` with contents: ```sh #! /usr/bin/env bash echo -e "\e[1m Bold Text \e[m" ``` If cmd.exe is you shell, try `test.bat`: ```bat forfiles /m some_file_in_your_default_folder /c "cmd /c echo 0x1B[1m Bold Text 0x1B[m" ``` Then, ssh into that machine from a terminal (note this works with either Windows Terminal, or the default conhost.exe terminal, and it doesn't matter what your local shell is, WSL or cmd.exe) and run the command. It is helpful if you are in a color scheme that has a white background and a dark foreground color. `ssh user@targetmachine test.sh` will write `Bold Text` to the terminal with correct ("light black") colors. `ssh -t user@targetmachine test.sh` will write `Bold Text` to the terminal in bright white text. This is easily visible by showing the control codes themselves: `ssh -t user@targetmachine test.sh | sed 's/\x1b/\\e/g'` Will show something like: `\e[2J\e[m\e[H\e]0;C:\WINDOWS\system32\conhost.exe\e[?25h\e[1m\e[97m Bold Text \e[m` You can clearly see, along with sending an additional code to set the terminal title string, it changes `<ESC>[1m` to `<ESC>[1m<ESC>[97m` # Expected behavior conhost.exe leaves my terminal control codes well enough alone. I'm not sure if this is the right place for this, if conhost.exe is doing this, or if I'm even understanding/diagnosing the problem 100% correctly. I'll also crosspost this to PowerShell/Win32-OpenSSH on github. NOTE: I do *not* see this incorrect behaviour if I ssh into sshd running as a service in WSL, i.e. `apt get openssh-server && service sshd start`. <!-- A description of what you're expecting, possibly containing screenshots or reference material. -->
claunia added the Resolution-Duplicate label 2026-01-31 03:07:11 +00:00
Author
Owner

@DHowett commented on GitHub (Jan 22, 2021):

So! This is definitely the right place. I’ve got good news and bad news.

This was one of our most annoying subtle bugs (in my opinion), which we tracked with #2661. There’s a heck of a lot of technical detail on why it existed and how it was fixed over there.

Good news: it’s fixed.

Bad news: the version of conpty OpenSSH uses is tied to the version of Windows on the server. Unfortunately, we can’t service that one. 😦

Thanks for writing up such a comprehensive report. Sorry to dupe it.

/dup #2661

@DHowett commented on GitHub (Jan 22, 2021): So! This is definitely the right place. I’ve got good news and bad news. This was one of our most annoying subtle bugs (in my opinion), which we tracked with #2661. There’s a heck of a lot of technical detail on why it existed and how it was fixed over there. Good news: it’s fixed. Bad news: the version of conpty OpenSSH uses is tied to the version of Windows on the server. Unfortunately, we can’t service that one. 😦 Thanks for writing up such a comprehensive report. Sorry to dupe it. /dup #2661
Author
Owner

@ghost commented on GitHub (Jan 22, 2021):

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost commented on GitHub (Jan 22, 2021): Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!
Author
Owner

@DHowett commented on GitHub (Jan 22, 2021):

(That issue bugged me so much that even as our issue tracker is approaching 9,000 total issues I still remember it by number 😄)

@DHowett commented on GitHub (Jan 22, 2021): (That issue bugged me so much that even as our issue tracker is approaching 9,000 total issues I still remember it by number :smile:)
Author
Owner

@bavis-m commented on GitHub (Jan 22, 2021):

Thanks for the response. I don't think I ever would have come up with the right search terms to find that issue on my own, so I appreciate the link. Is the real fix to wait until a windows update comes down the line that pulls this in to the packaged conhost? Will me being on an insider ring affect that time? Would #1817 help at all with this in the meantime?

@bavis-m commented on GitHub (Jan 22, 2021): Thanks for the response. I don't think I ever would have come up with the right search terms to find that issue on my own, so I appreciate the link. Is the real fix to wait until a windows update comes down the line that pulls this in to the packaged conhost? Will me being on an insider ring affect that time? Would #1817 help at all with this in the meantime?
Author
Owner

@DHowett commented on GitHub (Jan 22, 2021):

Insider builds are closer to our development branches, and I believe the current one does have the fix. :)

re 1817: no warranty expressed/implied but it should work and I can’t officially support it if it doesn’t 😉

@DHowett commented on GitHub (Jan 22, 2021): Insider builds are closer to our development branches, and I believe the current one does have the fix. :) re 1817: no warranty expressed/implied but _it should work_ and I can’t officially support it if it doesn’t 😉
Author
Owner

@bavis-m commented on GitHub (Jan 22, 2021):

It appears like the beta track (on windows build 19042.782 and conhost.exe version 10.0.19041.746, same as the non-insider track windows version) still exhibits the problem, and I don't have any machines on the dev track, so maybe I'll give 1817 a try (but you didn't hear that...). Thanks again for your help, I'll stop spamming this issue now.

@bavis-m commented on GitHub (Jan 22, 2021): It appears like the beta track (on windows build 19042.782 and conhost.exe version 10.0.19041.746, same as the non-insider track windows version) still exhibits the problem, and I don't have any machines on the dev track, so maybe I'll give 1817 a try (but you didn't hear that...). Thanks again for your help, I'll stop spamming this issue now.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#12136