Repository navigation
Only trust the verified terminal folder when auto-approving agent commands - #350618
Draft
Anthony Kim (anthonykim1) wants to merge 3 commits into
Draft
Anthony Kim (anthonykim1) wants to merge 3 commits into
Anthony Kim (anthonykim1) wants to merge 3 commits into
Conversation
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Authorization-boundary changes across four shell integrations and terminal/sandbox preparation require live validation of nonce emission and trust recovery, with no local PowerShell parsing or runtime verification reported.
No open issues 🎉
What changed in this PR
Hardens VS Code’s terminal command approval by treating explicitly untrusted working-directory reports as unknown, preventing those paths from being used to auto-approve relative file writes.
Changes:
- Add nonces to Bash, Zsh, Fish, and PowerShell cwd reports, and fix Fish’s nonce lifetime.
- Ignore untrusted terminal cwd during command preparation without falling back to session or workspace directories.
- Update Agent Host parsing for nonce-bearing reports and add parser and approval regression tests.
| File | Description |
|---|---|
src/vs/workbench/contrib/terminalContrib/chatAgentTools/test/electron-browser/runInTerminalTool.test.ts |
Tests trusted versus untrusted cwd in relative-write approval. |
src/vs/workbench/contrib/terminalContrib/chatAgentTools/browser/tools/runInTerminalTool.ts |
Rejects explicitly untrusted cwd before directory fallback. |
src/vs/workbench/contrib/terminal/common/scripts/shellIntegration.ps1 |
Adds the nonce to PowerShell cwd reports. |
src/vs/workbench/contrib/terminal/common/scripts/shellIntegration.fish |
Preserves the nonce globally and includes it in cwd reports. |
src/vs/workbench/contrib/terminal/common/scripts/shellIntegration-rc.zsh |
Adds the nonce to Zsh cwd reports. |
src/vs/workbench/contrib/terminal/common/scripts/shellIntegration-bash.sh |
Adds the nonce to Bash cwd reports. |
src/vs/platform/agentHost/test/node/osc633Parser.test.ts |
Tests parsing a cwd report with a trailing nonce. |
src/vs/platform/agentHost/node/osc633Parser.ts |
Strips trailing nonce data before decoding properties. |
Review effort: Balanced
Anthony Kim (anthonykim1)
force-pushed
the
anthonykim1/trusted-cwd-for-command-approval
branch
from
November 29, 2026 20:19
86178db to
a854955
Compare
Create the tool after stubbing the history service, so the test fails if an untrusted cwd falls back to the workspace folder. Add a case for a terminal without cwd detection, and cover an escaped `;` before the nonce in the Agent Host parser test. Co-authored-by: Copilot <[email protected]>
…cwd themselves An untrusted report that repeats the verified cwd, like fish 4.3+'s own OSC 7 or a prompt's OSC 9;9, no longer drops trust. The cwd is only treated as unknown once the terminal has sent a signed report, so shells without VS Code's script and restored terminals keep the existing behavior. PowerShell skips the cwd nonce on Windows 10, like it already does for command lines.
This branch has not been deployed
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.
Replaces #335978.
When the local agent's
run_in_terminaltool checks a command before running it, it now ignores a cwd report that VS Code's shell integration script didn't sign, in terminals where the script signs its reports. Any program can print a cwd report to the terminal, so an unverified report shouldn't decide where a relative file write lands or whether the command is auto approved.Which agent tools this affects
run_in_terminaltool: yes. It's the only tool whose command approval uses the terminal's reported cwd, so everything under "What changes for users" applies here.chat.agentHost.customTerminalTool.enabled(off by default, not supported on Windows): no change to command approval, which uses the session's working directory rather than the terminal's reported cwd. These terminals do load the shell integration scripts, so Agent Host's parser now drops the nonce from cwd reports (see below).What changes for users
pwdoption or a PowerShell prompt that sends OSC 9;9 for Windows Terminal: nothing. A report that repeats the verified cwd keeps it verified.run_in_terminaltreats the cwd as unknown until the next signed report:package.jsonfrom the cwd, doesn't apply.Code changes
OSC 633 ; P ; Cwd=<value> ; <nonce>) from the bash, zsh, fish and PowerShell scripts. The workbench already checks it and treats reports without it as untrusted.set -linside anifblock dropped it atend, so it's nowset -g. Fish command lines (OSC 633 ; E) are now nonce-verified too, like the other shells.CwdDetectionCapability, keep the cwd trusted when an unsigned report repeats the verified cwd, and addhasVerifiedCwd, which turns true at the first signed report.RunInTerminalTool, use no cwd when the terminal has sent a signed cwd report but the latest one is untrusted.;<nonce>fromPpayloads so the cwd value stays correct. Scripts escape;inside values, so the first;ends the value. Agent Host doesn't use this cwd for command approval.Tests
RunInTerminalTool›should only use trusted terminal cwd when checking relative file writescovers trusted, untrusted, a shell that never signs, and no cwd detection, with a live workspace folder fallback. It fails without the fix, if an untrusted cwd falls back to the workspace folder, and if an unsigned shell's cwd is ignored.ShellIntegrationAddon›should keep a verified cwd trusted only while untrusted reports repeat itfeeds real OSC 7 and OSC 633 sequences. It fails without the repeat rule.Osc633Parser›Property (P) Cwd with noncedrops the nonce and keeps a\x3b-escaped;in the path. It fails without the parser change.pnpm run test-node --run src/vs/platform/agentHost/test/node/osc633Parser.test.ts: 28 passing../scripts/test.shwith--runforrunInTerminalTool.test.ts,shellIntegrationAddon.test.ts,terminalInstance.test.ts,terminalCapabilityStore.test.tsandterminalEvents.test.ts: 429 passing.pnpm run typecheck-clientandpnpm run oxlinton the changed TypeScript files: clean.dir;semi: each sendsCwd=…dir\x3bsemi;<nonce>. Before this change, fish sent neither the cwd nor the command line with its nonce.--init-command) and fed its output through the builtShellIntegrationAddon: the cwd stays verified at every prompt, and an unsigned report of another folder from a background job makes it unverified.Promptsends the nonce with the cwd, and leaves it off withIsWindows10set.772b7877ccfeanddbd1badaca92with this branch's commits applied. None of the changed files differ on this branch's base.Inspirations from:
Cwd=<value> ; <nonce>format and the trust check come from theCwdcase inShellIntegrationAddon, which passesisTrustedtoCwdDetectionCapability.updateCwd.EnvJson ; <Environment> ; <Nonce>report.Psplit mirrors how its parser already separates the nonce forEcommand lines.IHistoryService, so the workspace folder fallback is live, follows an existingRunInTerminalTooltest.