Repository navigation
Only open File Explorer from OpenCWD when CWD is a real directory - #20697
Merged
Dustin L. Howett (DHowett) merged 1 commit intoSep 30, 2026
Merged
Dustin L. Howett (DHowett) merged 1 commit into
Dustin L. Howett (DHowett) merged 1 commit into
Conversation
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: There may be pipelines that require an authorized user to comment /azp run to run. |
Sebastien Tardif (SebTardif)
marked this pull request as ready for review
September 17, 2026 21:30
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Dustin L. Howett (DHowett)
requested changes
Sep 17, 2026
Dustin L. Howett (DHowett)
left a comment
Member
There was a problem hiding this comment.
Blocking to review.
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. |
Leonard Hecker (lhecker)
approved these changes
Sep 29, 2026
Leonard Hecker (lhecker)
left a comment
Member
There was a problem hiding this comment.
This makes sense to me.
Dustin L. Howett (DHowett)
approved these changes
Sep 29, 2026
Member
|
/azp run |
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. |
Dustin L. Howett (DHowett)
enabled auto-merge (squash)
September 29, 2026 23:36
Dustin L. Howett (DHowett)
merged commit Sep 30, 2026
4e2b8bd
into
microsoft:main
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
This was referenced Oct 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.exeas 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::OpenCWDis the command-palette actionTerminal.OpenCWD. It used:The working-directory string comes from OSC 7 (
file:URI, thenPathCreateFromUrlW) or OSC 9;9. Both only requiretil::is_legal_path, which allows:and/. So a remote host can set CWD tohttps://example.com,shell:..., or/select,.... Invoking Open CWD then ran Explorer with that text aslpParameters.Duplicate-tab and related paths already call
Utils::IsValidDirectorybefore trusting this string (TerminalPage.cpp,TerminalPaneContent.cpp). Open CWD now does the same, thenShellExecutes the directory path aslpFileso Explorer switches cannot be supplied as parameters.If the CWD is empty or not a directory, the action does nothing.
Validation Steps Performed
Types.Unit.Tests(Release x64) with VS 2026 Build ToolsUtilsTests::TestIsValidDirectorypassedUtilsTests(11 tests) passedGetFileAttributesExWrejectshttps://example.com,/select,C:\Windows, andshell:AppsFolder\Foo; those strings would previously still have been passed to ExplorerPR Checklist