Skip to content

Block auto-approved file-write redirection to env-var (%) paths - #320664

Merged
Megan Rogge (meganrogge) merged 3 commits into
mainfrom
merogge/block-env-var-redirect-file-writes
Jun 12, 2026
Merged

Megan Rogge (meganrogge) merged 3 commits into
mainfrom
merogge/block-env-var-redirect-file-writes

Conversation

@meganrogge

Copy link
Copy Markdown
Collaborator

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 by posix.isAbsolute or win32.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

  • Extends the redirection guard regex to also block % (Windows environment-variable expansion) in addition to the existing ~ handling.
  • Adds regression tests for both bash (~/file.txt, %HOME%/file.txt) and pwsh (~\file.txt, %APPDATA%\file.txt).

Notes

Tracking: #320660

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.
Copilot AI review requested due to automatic review settings June 9, 2026 20:13
@meganrogge Megan Rogge (meganrogge) added this to the 1.125.0 milestone Jun 9, 2026
@meganrogge
Megan Rogge (meganrogge) enabled auto-merge (squash) June 9, 2026 20:15
@vs-code-engineering

vs-code-engineering Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Anthony Kim (@anthonykim1)

Matched files:

  • src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/commandLineAnalyzer/commandLineFileWriteAnalyzer.ts
  • src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/commandLineAnalyzer/commandLineFileWriteAnalyzer.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

auto-merge was automatically disabled June 9, 2026 20:18

Pull request was closed

roblourens
roblourens previously approved these changes Jun 10, 2026
@meganrogge

Copy link
Copy Markdown
Collaborator Author

Copilot resolve the merge conflicts in this pull request

Copilot AI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Copilot resolve the merge conflicts in this pull request

Done — I merged origin/main, resolved the conflict, and pushed merge commit fcedcf2.

@meganrogge
Megan Rogge (meganrogge) enabled auto-merge (squash) June 10, 2026 18:39
@meganrogge
Megan Rogge (meganrogge) merged commit 6c04097 into main Jun 12, 2026
25 checks passed
@meganrogge
Megan Rogge (meganrogge) deleted the merogge/block-env-var-redirect-file-writes branch June 12, 2026 14:41
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jul 27, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants