fix: fetch tool should not warn when reading files inside the workspace#303789
fix: fetch tool should not warn when reading files inside the workspace#303789TylerLeonhardt merged 3 commits intomainfrom
Conversation
Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/d33f23a2-816c-4dec-acca-ac0c989f6467
|
@copilot I was expecting you to just check if the files are in the currently open workspace |
Co-authored-by: TylerLeonhardt <2644648+TylerLeonhardt@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/vscode/sessions/f3f23937-896d-4572-93e8-5780ae4e7425
Reworked in 9b462d8. Now |
There was a problem hiding this comment.
Pull request overview
Adjusts the internal Chat “fetch” tool’s confirmation behavior so that reading file:// URIs inside the currently open workspace no longer triggers the “Fetch web page?” confirmation prompt, while still requiring confirmation for web URLs and file URIs outside the workspace.
Changes:
- Update
FetchWebPageTool.prepareToolInvocationto classify URIs usingIWorkspaceContextService.getWorkspaceFolder()and exclude workspace-contained file URIs from confirmation checks. - Update message counts to use “all fetched URIs” (web + all valid file URIs) while keeping confirmations limited to web + outside-workspace file URIs.
- Extend tests to cover workspace file URIs (no dialog), outside-workspace file URIs (dialog), and mixed workspace file + untrusted web URI (only web prompts).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/electron-browser/builtInTools/fetchPageTool.ts | Injects workspace context to skip confirmations for workspace-contained file URIs; keeps confirmation for web/outside-workspace URIs. |
| src/vs/workbench/contrib/chat/test/electron-browser/tools/builtinTools/fetchPageTool.test.ts | Updates constructor calls and adds coverage for new workspace vs outside-workspace confirmation behavior. |
src/vs/workbench/contrib/chat/electron-browser/builtInTools/fetchPageTool.ts
Show resolved
Hide resolved
|
@copilot what do you think of this comment ... does it feel contrived? |
Yes, I think it's contrived for this context. A few reasons:
Happy to apply it if you feel strongly, but I'd lean toward leaving it as-is and addressing symlinks globally across all workspace membership checks if/when it's deemed necessary. |
The
fetchtool was showing a "Fetch web page?" confirmation dialog forfile://URIs pointing to files inside the currently open workspace. The prompt injection risk warning makes no sense for workspace files that are already accessible.Root cause
prepareToolInvocationadded all URIs — web and file — tourlsNeedingConfirmation. SincetrustedDomainService.isValid()only handles HTTP(S) domains, file URIs always failed the trust check and triggered the dialog.Changes
fetchPageTool.ts: InjectIWorkspaceContextServiceand usegetWorkspaceFolder()to classify file URIs:allFetchedUris(web + all file URIs) — message display onlyfileUrisOutsideWorkspace— file URIs not inside any workspace folderurlsNeedingConfirmation(web URIs + files outside workspace) — trust checks and confirmation dialogWorkspace file fetches now produce
confirmationTitle = undefinedandconfirmResults = false— no dialog, no post-confirmation. Files outside the workspace still trigger confirmation, as do all web (http/https) URIs.fetchPageTool.test.ts: AddedTestContextServiceto all constructor calls; added tests covering: workspace file (no dialog), file outside workspace (still shows dialog), mixed workspace file + untrusted web URI (only web URI appears in confirmation).Notes
Symlink resolution was considered but intentionally omitted — no other workspace membership checks in the codebase (e.g.
read_file,ChatExternalPathConfirmation) resolve symlinks, and the confirmation dialog here is primarily guarding against web prompt injection rather than local filesystem traversal.📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.