Repository navigation
Block auto-approved file-write redirection to env-var (%) paths - #320664
Merged
Megan Rogge (meganrogge) merged 3 commits intoJun 12, 2026
Merged
Conversation
The file-write redirection guard already blocks tilde (~) expansion but did not account for Windows environment-variable expansion (e.g. %APPDATA%\file.txt, %HOME%/file.txt). Such paths are not classified as absolute by posix.isAbsolute or win32.isAbsolute, so they could be auto-approved and write outside the expected workspace scope without confirmation. Adds % to the redirection guard and regression tests for bash and pwsh.
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: Anthony Kim (@anthonykim1)Matched files:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Improves the Terminal Chat “run in terminal” auto-approval safety checks by treating cmd-style %…% paths similarly to ~ paths, preventing file-write redirections that may expand to user-controlled locations from being auto-approved.
Changes:
- Extends the file-write destination guard to also block paths containing
%(in addition to~). - Updates the diagnostic log message to reflect the additional guard.
- Adds regression tests for
~and%…%redirection targets in both bash and PowerShell analyzer suites.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/commandLineAnalyzer/commandLineFileWriteAnalyzer.ts | Extends the redirection destination guard regex to include % and updates logging/commentary. |
| src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/commandLineAnalyzer/commandLineFileWriteAnalyzer.test.ts | Adds regression tests to ensure ~ and %…% redirection targets are blocked under outsideWorkspace. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 3
roblourens
previously approved these changes
Jun 10, 2026
Collaborator
Author
|
Copilot resolve the merge conflicts in this pull request |
Co-authored-by: meganrogge <[email protected]>
Contributor
Done — I merged |
Justin Chen (justschen)
approved these changes
Jun 10, 2026
Megan Rogge (meganrogge)
enabled auto-merge (squash)
June 10, 2026 18:39
Megan Rogge (meganrogge)
deleted the
merogge/block-env-var-redirect-file-writes
branch
June 12, 2026 14:41
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The terminal command auto-approval logic guards against file-write redirection to non-absolute destinations. The guard already blocks POSIX tilde/home expansion (
~, added in #316311), but it did not account for Windows environment-variable expansion (e.g.%APPDATA%\file.txt,%HOME%/file.txt). Such paths are not classified as absolute byposix.isAbsoluteorwin32.isAbsolute, so a redirect to one of them could be auto-approved and write to a sensitive, user-controlled location outside the expected workspace scope without explicit user confirmation.Change
%(Windows environment-variable expansion) in addition to the existing~handling.~/file.txt,%HOME%/file.txt) and pwsh (~\file.txt,%APPDATA%\file.txt).Notes
mainthe~case was already covered by Block auto-approved file writes with literal tilde #316311; the net-new protection here is the%case. The resulting guard covers both.Tracking: #320660