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

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/12899
Author: @zadjii-msft
Created: 4/13/2022
Status: Merged
Merged: 4/19/2022
Merged by: @zadjii-msft

Base: mainHead: dev/migrie/b/2988-focus-fg-with-owner


📝 Commits (10+)

  • 9dd1649 Doesn't build. Want to merge in the ConGetSet change first, cause obviously that's gonna blow this diff up.
  • 1a1caf9 cherry-pick 479c6c9f08
  • 5be7f76 comments comments comments
  • 37adb94 remove a todo
  • 172acd2 you knew there'd be typos
  • 0d17cd7 Merge branch 'main' into dev/migrie/b/2988-focus-foreground
  • 3e0c15a Merge branch 'dev/migrie/f/z-order-owner' into dev/migrie/b/2988-focus-foreground
  • 72e3ed4 check the ownership for FG rights. NOT TESTED
  • 6ab1fb2 Both these fixes should be in this branch
  • f12b8c1 Merge remote-tracking branch 'origin/main' into dev/migrie/b/2988-focus-fg-with-owner

📊 Changes

3 files changed (+55 additions, -10 deletions)

View changed files

📝 src/host/outputStream.cpp (+2 -2)
📝 src/interactivity/inc/ServiceLocator.hpp (+1 -1)
📝 src/terminal/adapter/InteractDispatch.cpp (+52 -7)

📄 Description

⚠️ 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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/microsoft/terminal/pull/12899 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 4/13/2022 **Status:** ✅ Merged **Merged:** 4/19/2022 **Merged by:** [@zadjii-msft](https://github.com/zadjii-msft) **Base:** `main` ← **Head:** `dev/migrie/b/2988-focus-fg-with-owner` --- ### 📝 Commits (10+) - [`9dd1649`](https://github.com/microsoft/terminal/commit/9dd16495251e393aa05387c955697ecc7efd64be) Doesn't build. Want to merge in the ConGetSet change first, cause _obviously_ that's gonna blow this diff up. - [`1a1caf9`](https://github.com/microsoft/terminal/commit/1a1caf94357e317ac0c5bc85fc8502e75f988644) cherry-pick 479c6c9f08cf273768e64f9f7fbc74a2c231b815 - [`5be7f76`](https://github.com/microsoft/terminal/commit/5be7f76586e2a9d7363145171383b00fe1a44f0f) comments comments comments - [`37adb94`](https://github.com/microsoft/terminal/commit/37adb94c90454d7b8f8c5ad6671b5edac34c8f39) remove a todo - [`172acd2`](https://github.com/microsoft/terminal/commit/172acd2f8b08ecca2d883de77dd2acdaf55bd48b) you knew there'd be typos - [`0d17cd7`](https://github.com/microsoft/terminal/commit/0d17cd722996bc291b0dc8ec41cd7fd335905a38) Merge branch 'main' into dev/migrie/b/2988-focus-foreground - [`3e0c15a`](https://github.com/microsoft/terminal/commit/3e0c15a75ecbea2f187e28e3a69cdcbb69c892c8) Merge branch 'dev/migrie/f/z-order-owner' into dev/migrie/b/2988-focus-foreground - [`72e3ed4`](https://github.com/microsoft/terminal/commit/72e3ed48093e2ffcd0985a9792cb47f5c619a105) check the ownership for FG rights. NOT TESTED - [`6ab1fb2`](https://github.com/microsoft/terminal/commit/6ab1fb26409ee9ee4f6b3ec45ce2ef6184ea1253) Both these fixes should be in this branch - [`f12b8c1`](https://github.com/microsoft/terminal/commit/f12b8c1c5cdb97c755f73daa52ee97d7b268f601) Merge remote-tracking branch 'origin/main' into dev/migrie/b/2988-focus-fg-with-owner ### 📊 Changes **3 files changed** (+55 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `src/host/outputStream.cpp` (+2 -2) 📝 `src/interactivity/inc/ServiceLocator.hpp` (+1 -1) 📝 `src/terminal/adapter/InteractDispatch.cpp` (+52 -7) </details> ### 📄 Description #### ⚠️ _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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-31 09:33:56 +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#29279