Skip to content

When running as Administrator, Terminal should always start built-in Windows apps in C:\Windows\System32 #7062

Open

Description

Description of the new feature/enhancement

When you open Command Prompt or PowerShell from the Start Menu, Start --> Run (Windows-R), or the set of options you get by right-clicking the Start button (Windows-X), the starting current directory for the shell can vary:

  • When the shell is run as an ordinary user (or a administrator without elevation to admin privilege/token), the starting directory is C:\Users\me , or whatever the user's home location is.
  • When the shell is run as an administrator, the starting directory is always C:\Windows\System32 .

This is also true for non-shell command-line apps that are launched this way, like C:\Windows\System32\choice.exe - EDIT: as long as they come with Windows.

However, when command-line apps are launched from Terminal using a Terminal profile, the starting directory is always static:

  • If startingDirectory is set to non-null and non-empty (in settings.json or defaults.json): that directory
  • If startingDirectory is set to an empty string: C:\Users\me
  • Otherwise - if startingDirectory is set to null or not set: C:\Windows\System32

What I'd like is for Terminal to emulate part of the built-in behavior of the Windows system described above:
If Terminal is elevated, then the starting directory for any new Terminal tab or pane should always be the system directory C:\Windows\System32.
EDIT: If Terminal is elevated, then the starting directory for any new Terminal tab or pane opening a built-in Windows system file should always be the system directory C:\Windows\System32.
This reduces the chance of damage when you accidentally run (or are maliciously tricked into running) a program from your home location or other unprivileged folder that has the same name as a program in C:\Windows\System32.

Activity

  1. ghost added
    Needs-Tag-FixDoesn't match tag requirements
    on Jul 24, 2020
  2. ghost added
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    on Jul 24, 2020
  3. KalleOlaviNiemitalo commented on Jul 25, 2020

    @KalleOlaviNiemitalo

    This reduces the chance of damage when you accidentally run (or are maliciously tricked into running) a program from your home location or other unprivileged folder that has the same name as a program in C:\Windows\System32.

    You could set the NoDefaultCurrentDirectoryInExePath environment variable, documented at NeedCurrentDirectoryForExePathW function.

  4. DHowett commented on Jul 25, 2020

    @DHowett
    Member

    You know, I think the behavior you're seeing is actually a side effect of how the shell spawns elevated applications. When you run an application as an administrator from its installation directory using the context menu, it runs in its installation directory. When you run it from a shortcut designated to run as an admin but with a specified startup directory, it actually does open in that startup directory.

    This sounds like an implementation detail wearing a white coat with "Dr. Security" embroidered on it.

  5. metathinker commented on Jul 28, 2020

    @metathinker
    ContributorAuthor

    You know, I think the behavior you're seeing is actually a side effect of how the shell spawns elevated applications. When you run an application as an administrator from its installation directory using the context menu, it runs in its installation directory. When you run it from a shortcut designated to run as an admin but with a specified startup directory, it actually does open in that startup directory.

    This sounds like an implementation detail wearing a white coat with "Dr. Security" embroidered on it.

    It's a bit more complex than that... I studied the implementation of starting an application elevated. When Explorer or some other unelevated process running the shell API impl. needs to start an elevated process, it (actually the "Application Information"/AppInfo NT service, the trustworthy worker process that starts the elevated process for Explorer) special-cases applications in C:\Windows and most other directories in that tree, which for our purposes includes Command Prompt and Windows PowerShell. For those applications, the start-in folder specified by the shortcut is ignored in favor of C:\Windows\System32. The ignorance is deliberate - there's even a comment to call out that the specified start-in folder path is being thrown away to discourage attacks by using the program loader to load untrustworthy DLLs.

    Windows Terminal doesn't follow the same path when launching an elevated cmd.exe or powershell.exe because it is already elevated - it doesn't need to use the special-case code described above in order to launch cmd.exe. So the feature request is that it should do the same thing, but perhaps that is not easy to implement as you have to mirror at least some of the logic to answer the question "is this program in a known, safe C:\Windows path?"

  6. ghost added
    Needs-AttentionThe core contributors need to come back around and look at this ASAP.
    on Jul 28, 2020
  7. ghost removed
    Needs-Author-FeedbackThe original author of the issue/PR needs to come back and respond to something
    on Jul 28, 2020
  8. changed the title [-]When running as Administrator, Terminal should always start apps in C:\Windows\System32[/-] [+]When running as Administrator, Terminal should always start built-in Windows apps in C:\Windows\System32[/+] on Jul 28, 2020
  9. miniksa commented on Jul 19, 2021

    @miniksa
    Contributor

    I've contacted one of our friends on the security research team. I gave him the rundown of what we discussed in our triage meeting about this particular issue today and he provided several counter points that we should consider. There wasn't a definitive conclusion beyond the fact that he will raise this with the rest of his team later this week to get more security minds thinking about it and advise us on a recommendation going forward.

  10. 3 remaining items

  11. removed
    Needs-TriageIt's a new issue that the core contributor team needs to triage at the next triage meeting
    Needs-AttentionThe core contributors need to come back around and look at this ASAP.
    on Aug 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions