[PR #11308] [CLOSED] Warn before the user runs a new commandline elevated #28488

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

📋 Pull Request Information

Original PR: https://github.com/microsoft/terminal/pull/11308
Author: @zadjii-msft
Created: 9/22/2021
Status: Closed

Base: mainHead: dev/migrie/f/non-terminal-content-elevation-warning


📝 Commits (10+)

  • 42c3eea pull application state members into a base class
  • eb243f5 Split ApplicationState into a Base and add an Elevated version
  • 2857324 proof of concept add a dialog to pop when opening new tabs
  • ccbcb42 Merge remote-tracking branch 'origin/main' into dev/migrie/f/elevation-warning
  • 14d21f4 nits, cleanup
  • c66a566 Allow a Pane to host a UserControl instead of a TermControl
  • ed1cf2a add the boilerplate for a custom content dialog like thing
  • 1ee3522 Allow a TerminalTab to have a UserControl
  • 7fb7d64 These are things I might need for #997
  • 631cdf7 Who ever said nested lambdas is a bad thing?

📊 Changes

18 files changed (+904 additions, -80 deletions)

View changed files

📝 src/cascadia/LocalTests_TerminalApp/TerminalApp.LocalTests.vcxproj (+2 -1)
src/cascadia/LocalTests_TerminalApp/TrustCommandlineTests.cpp (+123 -0)
src/cascadia/TerminalApp/AdminWarningPlaceholder.cpp (+74 -0)
src/cascadia/TerminalApp/AdminWarningPlaceholder.h (+51 -0)
src/cascadia/TerminalApp/AdminWarningPlaceholder.idl (+12 -0)
src/cascadia/TerminalApp/AdminWarningPlaceholder.xaml (+97 -0)
📝 src/cascadia/TerminalApp/Pane.cpp (+165 -55)
📝 src/cascadia/TerminalApp/Pane.h (+7 -3)
📝 src/cascadia/TerminalApp/Resources/en-US/Resources.resw (+18 -0)
📝 src/cascadia/TerminalApp/TabManagement.cpp (+1 -0)
📝 src/cascadia/TerminalApp/TerminalAppLib.vcxproj (+13 -0)
📝 src/cascadia/TerminalApp/TerminalPage.cpp (+293 -19)
📝 src/cascadia/TerminalApp/TerminalPage.h (+10 -0)
📝 src/cascadia/TerminalApp/TerminalTab.cpp (+26 -2)
📝 src/cascadia/TerminalApp/TerminalTab.h (+3 -0)
📝 src/cascadia/TerminalControl/TermControl.cpp (+5 -0)
📝 src/cascadia/TerminalControl/TermControl.h (+2 -0)
📝 src/cascadia/TerminalControl/TermControl.idl (+2 -0)

📄 Description

targets #11222, followed by #11310

Summary of the Pull Request

As a part of #8455, we identified that we should probably warn before running commandlines, to make sure the user knows what they're about to do. This dialog looks like the following:

image

image

When the user approves a commandline, we'll remember that commandline, so they won't get prompted every time.
If they reject a commandline, then we're just going to close that pane.

References

PR Checklist

Detailed Description of the Pull Request / Additional comments

This PR changes Pane to be able to host any UserControl, not necessarily a TermControl. This of course has bigger repurcussions than just revealed here. It's gonna wildly conflict with some of the other open PRs. I wanted to do this more generically for #997, but alas, nobody got time for that.

This adds a AdminWarningPlaceholder which is a type of UserControl that just holds another UserControl. It looks just like a ContentDialog, but will actually resize as the window resizes.

We won't prompt for certain commandlines:

  • Anything that exists in system32 AND IS FULLY QUALIFIED eg C:\windows\system32\cmd.exe.
    • cmd.exe will prompt, because it's unqualified.
    • C:\windows\system32\cmd.exe /k echo sneaky sneak will also prompt, because it's got other args.
  • %SystemRoot%\System32\cmd.exe won't prompt, because it's smart enoguh to handle env vars
  • %SystemRoot%\System32\wsl.exe -d <distroname> won't prompt, because we trust wsl distros.
  • %SystemRoot%\System32\wsl.exe -d <distroname> bash -c do-malicious-shit.sh WILL prompt

Validation Steps Performed

Opened a bunch of terminals, in random orders, and made sure that the above commandlines would work as expected. My list of running profiles:

    {
        "commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
        "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
        "hidden": false,
        "name": "Windows PowerShell"
    },
    {
        "commandline": "%SystemRoot%\\System32\\cmd.exe",
        "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
        "hidden": false,
        "name": "Command Prompt"
    },
    {
        "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",
        "hidden": false,
        "name": "PowerShell",
        "source": "Windows.Terminal.PowershellCore"
    },
    {
        "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}",
        "hidden": false,
        "name": "Ubuntu-18.04",
        "source": "Windows.Terminal.Wsl"
    },
    {
        "commandline": "c:\\windows\\system32\\cmd.exe",
        "guid": "{5aea3919-92fa-5990-bb39-2321f316d9b9}",
        "name": "the COOLER cmd",
        "startingDirectory": "%USERPROFILE%"
    },
    {
        "commandline": "c:\\windows\\system32\\cmd.exe /k echo sneaky sneaks",
        "guid": "{4fd85e9a-919a-5033-9118-1b7518b676a7}",
        "name": "the sneaky cmd",
        "startingDirectory": "%USERPROFILE%"
    },
    {
        "background": "#9C1C0C",
        "commandline": "cmd.exe /k echo This profile is always elevated",
        "guid": "{7a7854d2-65bc-57c2-a2c6-70a32a2f600e}",
        "name": "elevated cmd",
        "startingDirectory": "well this is garbage",
        "tabColor": "#9C1C0C"
    },
    {
        "background": "#1C0C9C",
        "commandline": "cmd.exe /k echo This profile is just as elevated as you started with",
        "guid": "{b5c1cbf5-217f-5e0f-b3ee-3c70150ef037}",
        "name": "unelevated cmd",
        "tabColor": "#1C0C9C",
        "useAcrylic": true
    },


🔄 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/11308 **Author:** [@zadjii-msft](https://github.com/zadjii-msft) **Created:** 9/22/2021 **Status:** ❌ Closed **Base:** `main` ← **Head:** `dev/migrie/f/non-terminal-content-elevation-warning` --- ### 📝 Commits (10+) - [`42c3eea`](https://github.com/microsoft/terminal/commit/42c3eea136326688a10f6fa9ba75a3256bfd6539) pull application state members into a base class - [`eb243f5`](https://github.com/microsoft/terminal/commit/eb243f5e112d20f58e4a4e8de919d4fde042a203) Split ApplicationState into a Base and add an Elevated version - [`2857324`](https://github.com/microsoft/terminal/commit/2857324777ab529f9027f89520bd9d4d50fc2ad4) proof of concept add a dialog to pop when opening new tabs - [`ccbcb42`](https://github.com/microsoft/terminal/commit/ccbcb425da76360ced9f77250e65ad203651ecdd) Merge remote-tracking branch 'origin/main' into dev/migrie/f/elevation-warning - [`14d21f4`](https://github.com/microsoft/terminal/commit/14d21f492bcf529aa329e46bb05de298b5591803) nits, cleanup - [`c66a566`](https://github.com/microsoft/terminal/commit/c66a56656ec6e87d2aea25cc68ee2250880bcd09) Allow a Pane to host a UserControl instead of a TermControl - [`ed1cf2a`](https://github.com/microsoft/terminal/commit/ed1cf2aeac76bde54c57c4058ba92e5db742c0a3) add the boilerplate for a custom content dialog like thing - [`1ee3522`](https://github.com/microsoft/terminal/commit/1ee3522cd806597e9f0b2145094b38a94e500bd2) Allow a TerminalTab to have a UserControl - [`7fb7d64`](https://github.com/microsoft/terminal/commit/7fb7d64b91ce40f030bc43e97fa2e9408f759a7f) These are things I might need for #997 - [`631cdf7`](https://github.com/microsoft/terminal/commit/631cdf7b180a82f8aa5cda540f44ceecde389d6b) Who ever said nested lambdas is a bad thing? ### 📊 Changes **18 files changed** (+904 additions, -80 deletions) <details> <summary>View changed files</summary> 📝 `src/cascadia/LocalTests_TerminalApp/TerminalApp.LocalTests.vcxproj` (+2 -1) ➕ `src/cascadia/LocalTests_TerminalApp/TrustCommandlineTests.cpp` (+123 -0) ➕ `src/cascadia/TerminalApp/AdminWarningPlaceholder.cpp` (+74 -0) ➕ `src/cascadia/TerminalApp/AdminWarningPlaceholder.h` (+51 -0) ➕ `src/cascadia/TerminalApp/AdminWarningPlaceholder.idl` (+12 -0) ➕ `src/cascadia/TerminalApp/AdminWarningPlaceholder.xaml` (+97 -0) 📝 `src/cascadia/TerminalApp/Pane.cpp` (+165 -55) 📝 `src/cascadia/TerminalApp/Pane.h` (+7 -3) 📝 `src/cascadia/TerminalApp/Resources/en-US/Resources.resw` (+18 -0) 📝 `src/cascadia/TerminalApp/TabManagement.cpp` (+1 -0) 📝 `src/cascadia/TerminalApp/TerminalAppLib.vcxproj` (+13 -0) 📝 `src/cascadia/TerminalApp/TerminalPage.cpp` (+293 -19) 📝 `src/cascadia/TerminalApp/TerminalPage.h` (+10 -0) 📝 `src/cascadia/TerminalApp/TerminalTab.cpp` (+26 -2) 📝 `src/cascadia/TerminalApp/TerminalTab.h` (+3 -0) 📝 `src/cascadia/TerminalControl/TermControl.cpp` (+5 -0) 📝 `src/cascadia/TerminalControl/TermControl.h` (+2 -0) 📝 `src/cascadia/TerminalControl/TermControl.idl` (+2 -0) </details> ### 📄 Description ###### targets #11222, followed by #11310 ## Summary of the Pull Request As a part of #8455, we identified that we should probably warn before running commandlines, to make sure the user knows what they're about to do. This dialog looks like the following: ![image](https://user-images.githubusercontent.com/18356694/134420083-4d6d8200-a4e8-4c51-a7a3-cca48626cfc1.png) ![image](https://user-images.githubusercontent.com/18356694/134420045-f7dde558-e34a-4b35-a78a-0be1a9b50745.png) When the user approves a commandline, we'll remember that commandline, so they won't get prompted every time. If they reject a commandline, then we're just going to close that pane. ## References * This is the vegetables so we can do #632 * #5000 ## PR Checklist * [x] Closes #11096 * [x] I work here * [ ] Tests added/passed * [ ] Requires documentation to be updated - SO very much yes but I'm gonna do it all at the end ## Detailed Description of the Pull Request / Additional comments This PR changes `Pane` to be able to host any `UserControl`, not necessarily a `TermControl`. This of course has bigger repurcussions than just revealed here. It's gonna wildly conflict with some of the other open PRs. I wanted to do this more generically for #997, but alas, nobody got time for that. This adds a `AdminWarningPlaceholder` which is a type of `UserControl` that just holds another `UserControl`. It looks just like a `ContentDialog`, but will actually resize as the window resizes. We _won't_ prompt for certain commandlines: - Anything that exists in system32 AND IS FULLY QUALIFIED eg `C:\windows\system32\cmd.exe`. - `cmd.exe` will prompt, because it's unqualified. - `C:\windows\system32\cmd.exe /k echo sneaky sneak` will also prompt, because it's got other args. - `%SystemRoot%\System32\cmd.exe` won't prompt, because it's smart enoguh to handle env vars - `%SystemRoot%\System32\wsl.exe -d <distroname>` won't prompt, because we trust wsl distros. - `%SystemRoot%\System32\wsl.exe -d <distroname> bash -c do-malicious-shit.sh` WILL prompt ## Validation Steps Performed Opened a bunch of terminals, in random orders, and made sure that the above commandlines would work as expected. My list of running profiles: <details> ```json { "commandline": "%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", "hidden": false, "name": "Windows PowerShell" }, { "commandline": "%SystemRoot%\\System32\\cmd.exe", "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}", "hidden": false, "name": "Command Prompt" }, { "guid": "{574e775e-4f2a-5b96-ac1e-a2962a402336}", "hidden": false, "name": "PowerShell", "source": "Windows.Terminal.PowershellCore" }, { "guid": "{c6eaf9f4-32a7-5fdc-b5cf-066e8a4b1e40}", "hidden": false, "name": "Ubuntu-18.04", "source": "Windows.Terminal.Wsl" }, { "commandline": "c:\\windows\\system32\\cmd.exe", "guid": "{5aea3919-92fa-5990-bb39-2321f316d9b9}", "name": "the COOLER cmd", "startingDirectory": "%USERPROFILE%" }, { "commandline": "c:\\windows\\system32\\cmd.exe /k echo sneaky sneaks", "guid": "{4fd85e9a-919a-5033-9118-1b7518b676a7}", "name": "the sneaky cmd", "startingDirectory": "%USERPROFILE%" }, { "background": "#9C1C0C", "commandline": "cmd.exe /k echo This profile is always elevated", "guid": "{7a7854d2-65bc-57c2-a2c6-70a32a2f600e}", "name": "elevated cmd", "startingDirectory": "well this is garbage", "tabColor": "#9C1C0C" }, { "background": "#1C0C9C", "commandline": "cmd.exe /k echo This profile is just as elevated as you started with", "guid": "{b5c1cbf5-217f-5e0f-b3ee-3c70150ef037}", "name": "unelevated cmd", "tabColor": "#1C0C9C", "useAcrylic": true }, ``` </details> --- <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:28:49 +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#28488