Skip to content

Only open File Explorer from OpenCWD when CWD is a real directory - #20697

Merged
Dustin L. Howett (DHowett) merged 1 commit into
microsoft:mainfrom
SebTardif:fix/open-cwd-validate-directory
Sep 30, 2026
Merged

Dustin L. Howett (DHowett) merged 1 commit into
microsoft:mainfrom
SebTardif:fix/open-cwd-validate-directory

Conversation

@SebTardif

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Open CWD now no-ops unless the terminal working directory is an existing directory, then opens that folder. It no longer passes the raw OSC string to explorer.exe as parameters.

References and Relevant Issues

Ref #12859 (the original action asked to do nothing when no CWD is set)

Introduced in #18013 (7cdf9eeafb, 2024-12-05).

Detailed Description of the Pull Request / Additional comments

ControlCore::OpenCWD is the command-palette action Terminal.OpenCWD. It used:

ShellExecute(nullptr, nullptr, L"explorer", workingDirectory.c_str(), nullptr, SW_SHOW);

The working-directory string comes from OSC 7 (file: URI, then PathCreateFromUrlW) or OSC 9;9. Both only require til::is_legal_path, which allows : and /. So a remote host can set CWD to https://example.com, shell:..., or /select,.... Invoking Open CWD then ran Explorer with that text as lpParameters.

Duplicate-tab and related paths already call Utils::IsValidDirectory before trusting this string (TerminalPage.cpp, TerminalPaneContent.cpp). Open CWD now does the same, then ShellExecutes the directory path as lpFile so Explorer switches cannot be supplied as parameters.

If the CWD is empty or not a directory, the action does nothing.

Validation Steps Performed

  • Built Types.Unit.Tests (Release x64) with VS 2026 Build Tools
  • TAEF: UtilsTests::TestIsValidDirectory passed
  • TAEF: full UtilsTests (11 tests) passed
  • Host check: GetFileAttributesExW rejects https://example.com, /select,C:\Windows, and shell:AppsFolder\Foo; those strings would previously still have been passed to Explorer

PR Checklist

  • Tests added/passed
  • Documentation updated
  • Schema updated (if necessary)

OpenCWD passed the OSC 7 / 9;9 working-directory string to explorer.exe as parameters. That string is not required to be a directory. Match duplicate-tab: require Utils::IsValidDirectory, then ShellExecute the path as the file to open.

Ref microsoft#12859

Signed-off-by: Sebastien Tardif <SebTardif@ncf.ca>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

@SebTardif
Sebastien Tardif (SebTardif) marked this pull request as ready for review September 17, 2026 21:30
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking to review.

@microsoft-github-policy-service microsoft-github-policy-service Bot added the Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something label Sep 17, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. label Sep 25, 2026
@microsoft-github-policy-service

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 7 days. It will be closed if no further activity occurs within 7 days of this comment.

@lhecker Leonard Hecker (lhecker) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense to me.

@microsoft-github-policy-service microsoft-github-policy-service Bot removed the No-Recent-Activity This issue/PR is going stale and may be auto-closed without further activity. label Sep 29, 2026
@DHowett

Copy link
Copy Markdown
Member

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.

@github-project-automation github-project-automation Bot moved this to To Cherry Pick in 1.25 Servicing Pipeline Sep 29, 2026
@github-project-automation github-project-automation Bot moved this to To Cherry Pick in 1.26 Servicing Pipeline Sep 29, 2026
@DHowett
Dustin L. Howett (DHowett) merged commit 4e2b8bd into microsoft:main Sep 30, 2026
14 of 16 checks passed
Dustin L. Howett (DHowett) pushed a commit that referenced this pull request Sep 30, 2026
…0697)

OpenCWD now no-ops unless the terminal working directory is an existing
directory, then opens that folder. It no longer passes the raw OSC
string to `explorer.exe` as parameters.

Refs #12859 (the original action asked to do nothing when no CWD is set)

OpenCWD was introduced in #18013.

`ControlCore::OpenCWD` is the command-palette action `Terminal.OpenCWD`.
It used:

```cpp
ShellExecute(nullptr, nullptr, L"explorer", workingDirectory.c_str(), nullptr, SW_SHOW);
```

The working-directory string comes from OSC 7 (`file:` URI, then
`PathCreateFromUrlW`) or OSC 9;9. Both only require
`til::is_legal_path`, which allows `:` and `/`. So a remote host can set
CWD to `https://example.com`, `shell:...`, or `/select,...`. Invoking
Open CWD then ran Explorer with that text as `lpParameters`.

Duplicate-tab and related paths already call `Utils::IsValidDirectory`
before trusting this string (`TerminalPage.cpp`,
`TerminalPaneContent.cpp`). Open CWD now does the same, then
`ShellExecute`s the directory path as `lpFile` so Explorer switches
cannot be supplied as parameters.

If the CWD is empty or not a directory, the action does nothing.

(cherry picked from commit 4e2b8bd)
Service-Card-Id: PVTI_lADOAF3p4s4BQX0-zg9jO2A
Service-Version: 1.25
Dustin L. Howett (DHowett) pushed a commit that referenced this pull request Sep 30, 2026
…0697)

OpenCWD now no-ops unless the terminal working directory is an existing
directory, then opens that folder. It no longer passes the raw OSC
string to `explorer.exe` as parameters.

Refs #12859 (the original action asked to do nothing when no CWD is set)

OpenCWD was introduced in #18013.

`ControlCore::OpenCWD` is the command-palette action `Terminal.OpenCWD`.
It used:

```cpp
ShellExecute(nullptr, nullptr, L"explorer", workingDirectory.c_str(), nullptr, SW_SHOW);
```

The working-directory string comes from OSC 7 (`file:` URI, then
`PathCreateFromUrlW`) or OSC 9;9. Both only require
`til::is_legal_path`, which allows `:` and `/`. So a remote host can set
CWD to `https://example.com`, `shell:...`, or `/select,...`. Invoking
Open CWD then ran Explorer with that text as `lpParameters`.

Duplicate-tab and related paths already call `Utils::IsValidDirectory`
before trusting this string (`TerminalPage.cpp`,
`TerminalPaneContent.cpp`). Open CWD now does the same, then
`ShellExecute`s the directory path as `lpFile` so Explorer switches
cannot be supplied as parameters.

If the CWD is empty or not a directory, the action does nothing.

(cherry picked from commit 4e2b8bd)
Service-Card-Id: PVTI_lADOAF3p4s4BlIihzg9jO10
Service-Version: 1.26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs-Author-Feedback The original author of the issue/PR needs to come back and respond to something

Projects

Status: Cherry Picked

Development

Successfully merging this pull request may close these issues.

3 participants

Sponsor
SponsoredKunjungi sekarang
Promo