'Use parent process directory' not being respected for new Tabs #19353

Open
opened 2026-01-31 06:40:51 +00:00 by claunia · 6 comments
Owner

Originally created by @EskimoRuler on GitHub (Feb 9, 2023).

Windows Terminal version

1.16.10262.0

Windows build number

10.0.2621.1105

Other Software

No response

Steps to reproduce

I have my WT setup so my default profile is lauch as admin and with the 'Use parent process directory' checked for starting directory. I then have all my other profiles set to 'Use parent process directory' for starting directory as well.

  1. Use the context menu to launch Windows Terminal from a folder.
  2. WT will launch default profile in the directory of the folder it was launch
  3. Opening a new Tab launches the new profile to the 'C:\Windows\System32' folder

Expected Behavior

Each new tab opened with different profiles should open in the same directory that WT was launched from

Actual Behavior

Each new tab is launch to the 'C:\Windows\System32' folder.

Originally created by @EskimoRuler on GitHub (Feb 9, 2023). ### Windows Terminal version 1.16.10262.0 ### Windows build number 10.0.2621.1105 ### Other Software _No response_ ### Steps to reproduce I have my WT setup so my default profile is lauch as admin and with the 'Use parent process directory' checked for starting directory. I then have all my other profiles set to 'Use parent process directory' for starting directory as well. 1. Use the context menu to launch Windows Terminal from a folder. 2. WT will launch default profile in the directory of the folder it was launch 3. Opening a new Tab launches the new profile to the 'C:\Windows\System32' folder ### Expected Behavior Each new tab opened with different profiles should open in the same directory that WT was launched from ### Actual Behavior Each new tab is launch to the 'C:\Windows\System32' folder.
Author
Owner

@zadjii-msft commented on GitHub (Feb 10, 2023):

Huh. I guess that makes sense, we're probably not passing the initial CWD of the Terminal to the elevate-shim to forward that to the elevated terminal instance.

Note

Walkthrough

Probably wouldn't be terribly difficult to pass the original terminal's CWD to elevate-shim. I'd look at TerminalPage::_maybeElevate - that's where the handoff from an unelevated -> elevated process happens.

@zadjii-msft commented on GitHub (Feb 10, 2023): Huh. I guess that makes sense, we're probably not passing the _initial_ CWD of the Terminal to the elevate-shim to forward that to the elevated terminal instance. > **Note** > ## Walkthrough Probably wouldn't be terribly difficult to pass the original terminal's CWD to elevate-shim. I'd look at `TerminalPage::_maybeElevate` - that's where the handoff from an unelevated -> elevated process happens.
Author
Owner

@zadjii-msft commented on GitHub (May 2, 2023):

Hmmmmmm.

This almost looks like a dupe of #15173, but subtly different.

With #15173, it's sufficient to just pass -d <path> to elevate-shim, to open the new tab in the requested directory.

This however, requests that elevate-shim somehow communicates that the Terminal itself should set it's CWD. In this case, the auto-self-elevate case, we need to pass the current virtual directory of the terminal to the elevate shim, to pass to the new one. Ew. Almost like #4637

I dunno if this regressed in 1.16 or was always broken.

@zadjii-msft commented on GitHub (May 2, 2023): Hmmmmmm. This almost looks like a dupe of #15173, but subtly different. With #15173, it's sufficient to just pass `-d <path>` to `elevate-shim`, to open the new tab in the requested directory. This however, requests that `elevate-shim` somehow communicates that the Terminal _itself_ should set it's CWD. In this case, the auto-self-elevate case, we need to pass the current virtual directory of the terminal to the elevate shim, to pass to the new one. Ew. Almost like #4637 I dunno if this regressed in 1.16 or was always broken.
Author
Owner

@zadjii-msft commented on GitHub (May 2, 2023):

There's maybe an equal and opposite here - maybe the Terminal should have it's CWD set to system32 when it's run elevated. That seems like pseudo-security, but there's some precedent here discussed in #7062.

I don't think that's incompatible with #7062. I just wonder if there's perhaps a reason why it shouldn't be automatic. Is there a vector for malicious.exe to get elevated when the CWD is set to something other than system32, that it wouldn't otherwise be able to do just by inserting itself into the profile? I doubt it, but I'm no security expert.

@zadjii-msft commented on GitHub (May 2, 2023): There's maybe an equal and opposite here - maybe the Terminal _should_ have it's CWD set to `system32` when it's run elevated. That seems like pseudo-security, but there's some precedent here discussed in #7062. I don't think that's incompatible with #7062. I just wonder if there's perhaps a reason why it _shouldn't_ be automatic. Is there a vector for `malicious.exe` to get elevated when the CWD is set to something other than `system32`, that it wouldn't otherwise be able to do just by inserting itself into the profile? I doubt it, but I'm no security expert.
Author
Owner

@EskimoRuler commented on GitHub (May 31, 2023):

Hmmmmmm.

This almost looks like a dupe of #15173, but subtly different.

With #15173, it's sufficient to just pass -d <path> to elevate-shim, to open the new tab in the requested directory.

This however, requests that elevate-shim somehow communicates that the Terminal itself should set it's CWD. In this case, the auto-self-elevate case, we need to pass the current virtual directory of the terminal to the elevate shim, to pass to the new one. Ew. Almost like #4637

I dunno if this regressed in 1.16 or was always broken.

This did work in previous versions. It broke with the latest. Been tough dealing with it not working. Was just so used to the workflow being able to switch to different consoles for the same directory.

@EskimoRuler commented on GitHub (May 31, 2023): > Hmmmmmm. > > This almost looks like a dupe of #15173, but subtly different. > > With #15173, it's sufficient to just pass `-d <path>` to `elevate-shim`, to open the new tab in the requested directory. > > This however, requests that `elevate-shim` somehow communicates that the Terminal _itself_ should set it's CWD. In this case, the auto-self-elevate case, we need to pass the current virtual directory of the terminal to the elevate shim, to pass to the new one. Ew. Almost like #4637 > > I dunno if this regressed in 1.16 or was always broken. This did work in previous versions. It broke with the latest. Been tough dealing with it not working. Was just so used to the workflow being able to switch to different consoles for the same directory.
Author
Owner

@medallyon commented on GitHub (Jun 8, 2023):

I am also experiencing this bug on Windows 11 version 10.0.22621.1702. I believe this still works on my other PC which probably uses an older version. Will verify soon.

@medallyon commented on GitHub (Jun 8, 2023): I am also experiencing this bug on Windows 11 version 10.0.22621.1702. I believe this still works on my other PC which probably uses an older version. Will verify soon.
Author
Owner

@zadjii-msft commented on GitHub (Jun 8, 2023):

FWIW I'm pretty confident this isn't a OS version issue, this is a Terminal version issue. Terminal 1.16 includes the change that regressed this, regardless of OS version

@zadjii-msft commented on GitHub (Jun 8, 2023): FWIW I'm pretty confident this isn't a OS version issue, this is a Terminal version issue. Terminal 1.16 includes the change that regressed this, regardless of OS version
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19353