[PR #12899] Ensure a terminal requesting FG rights actually has them #29284

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

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

State: closed
Merged: Yes


⚠️ Targets #12799 ⚠️

This is an atomic bit of code that partners with #12799. It's separated as an individual PR to keep diffs more simple.

This ensures that when a terminal tells ConPTY that it's focused, that ConPTY doesn't do the ConsoleControl(CONSOLE_FOREGROUND thing unless the terminal application is actually in the foreground. This prevents a trivial exploit whereby a malicious.exe could create a PTY, tell ConPTY it has focus (when it doesn't), then use this mechanism to launch an instance of itself into the foreground.

When the terminal tells us it's in the foreground, we're gonna look at the owner of the ConPTY window handle. If that owner has focus, then cool, this is allowed. Otherwise, we won't grant them the FG right. For this to work, the terminal just have already called ReparentPseudoConsole.

**Original Pull Request:** https://github.com/microsoft/terminal/pull/12899 **State:** closed **Merged:** Yes --- #### ⚠️ _Targets #12799_ ⚠️ This is an atomic bit of code that partners with #12799. It's separated as an individual PR to keep diffs more simple. This ensures that when a terminal tells ConPTY that it's focused, that ConPTY doesn't do the `ConsoleControl(CONSOLE_FOREGROUND` thing unless the terminal application is actually in the foreground. This prevents a trivial exploit whereby a `malicious.exe` could create a PTY, tell ConPTY it has focus (when it doesn't), then use this mechanism to launch an instance of itself into the foreground. When the terminal tells us it's in the foreground, we're gonna look at the owner of the ConPTY window handle. If that owner has focus, then cool, this is allowed. Otherwise, we won't grant them the FG right. For this to work, the terminal just have already called `ReparentPseudoConsole`. * built on top of #12799 and #12526 * [x] Part of #2988 * [x] Tested manually.
claunia added the pull-request label 2026-01-31 09:33:58 +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#29284