[PR #12211] Make sure titles always sanitized before passing over conpty #28912

Open
opened 2026-01-31 09:31:35 +00:00 by claunia · 0 comments
Owner

Original Pull Request: https://github.com/microsoft/terminal/pull/12211

State: closed
Merged: Yes


When title updates are forwarded from the host to the client terminal,
they're passed over conpty in an OSC 0 sequence. If there are any
control characters embedded in that title text it's essential they be
filtered out, otherwise they are likely to be misinterpreted by the VT
parser on the other side. This PR fixes a case where that sanitization
step was missed for titles initialized at startup.

Originally the sanitization step was handled in DoSrvSetConsoleTitleW,
which catches title changes made via VT escape sequences, or through the
console API, but missed the title initialization at startup. I've now
moved that sanitization code into the CONSOLE_INFORMATION::SetTitle
method, which should cover all cases.

This sanitization is only meant to occur when in "pty mode", though,
which we were originally establishing with an IsInVtIoMode call.
However, IsInVtIoMode does not return the correct result when the
title is set at startup, since the VT I/O thread is not initialized at
that point. So I've instead had to change that to an InConptyMode
call, which determines the conpty state from the launch args.

Validation Steps Performed

I've manually confirmed the test case described in issue #12206 is now
working correctly.

However, the change to using InConptyMode caused some of the unit
tests to fail, because there isn't a real conpty connection when
testing. Fortunately there are some EnableConptyModeForTests methods
used by the unit tests to fake the appearance of a conpty connection,
and I just needed to add some additional state in one of those methods
to trigger the correct InConptyMode response.

Closes #12206

**Original Pull Request:** https://github.com/microsoft/terminal/pull/12211 **State:** closed **Merged:** Yes --- When title updates are forwarded from the host to the client terminal, they're passed over conpty in an `OSC 0` sequence. If there are any control characters embedded in that title text it's essential they be filtered out, otherwise they are likely to be misinterpreted by the VT parser on the other side. This PR fixes a case where that sanitization step was missed for titles initialized at startup. Originally the sanitization step was handled in `DoSrvSetConsoleTitleW`, which catches title changes made via VT escape sequences, or through the console API, but missed the title initialization at startup. I've now moved that sanitization code into the `CONSOLE_INFORMATION::SetTitle` method, which should cover all cases. This sanitization is only meant to occur when in "pty mode", though, which we were originally establishing with an `IsInVtIoMode` call. However, `IsInVtIoMode` does not return the correct result when the title is set at startup, since the VT I/O thread is not initialized at that point. So I've instead had to change that to an `InConptyMode` call, which determines the conpty state from the launch args. ## Validation Steps Performed I've manually confirmed the test case described in issue #12206 is now working correctly. However, the change to using `InConptyMode` caused some of the unit tests to fail, because there isn't a real conpty connection when testing. Fortunately there are some `EnableConptyModeForTests` methods used by the unit tests to fake the appearance of a conpty connection, and I just needed to add some additional state in one of those methods to trigger the correct `InConptyMode` response. Closes #12206
claunia added the pull-request label 2026-01-31 09:31:35 +00:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#28912