Skip to content

Add BrowserChatToolsAllowedDomains policy to restrict browser chat tools to specific domains#315471

Open
HyderYash wants to merge 2 commits into
microsoft:mainfrom
HyderYash:feat/browser-chat-tools-allowed-domains
Open

Add BrowserChatToolsAllowedDomains policy to restrict browser chat tools to specific domains#315471
HyderYash wants to merge 2 commits into
microsoft:mainfrom
HyderYash:feat/browser-chat-tools-allowed-domains

Conversation

@HyderYash
Copy link
Copy Markdown

Add Domain Allowlist Policy for Browser Chat Tools

Fixes #315458

Overview

This PR adds a domain allowlist policy for Browser Chat Tools, enabling organizations to use browser tools while restricting them to trusted/internal domains without affecting the fetch tool.

Configuration & Policy

New Setting

  • Setting: workbench.browser.chatTools.allowedDomains: string[]
  • Enterprise Policy: BrowserChatToolsAllowedDomains

Key Details

  • Default: Empty array (no restriction)
  • Restricted: true
  • Registry: Added to policy registry and policyData catalog
  • Minimum Version: 1.120
  • Note: This setting does NOT affect:
    • chat.agent.allowedNetworkDomains
    • chat.agent.networkFilter

Domain Matching

Implementation

Domain validation is implemented in browserChatToolsAllowedDomains.ts

Behavior

  • Empty allowlist → No restriction
  • file: URIs → Allowed
  • URIs without authority → Allowed

Supported Patterns

  • Exact domains (e.g., localhost, 127.0.0.1)
  • Wildcard patterns (e.g., *.example.com)
  • Wildcards match apex and nested subdomains

Note: Matching reuses existing domain parsing helpers to maintain consistency with network filter behavior.

Enforcement (Browser Tools Only)

Guard Implementation

Added assertBrowserChatToolNavigationAllowed() guard

Error Message

Blocked operations show a localized error:

Navigation blocked by BrowserChatToolsAllowedDomains policy.

Validated Actions

  • Navigation: open / navigate / reload / back / forward
  • Interaction: click / type / hover / drag
  • Reading: read_page / screenshot_page
  • Dialogs: handle_dialog
  • Code execution: run_playwright_code (before + after execution)

Impact

  • ✅ No changes to fetch tools
  • ✅ No changes to IAgentNetworkFilterService

Tests

Added comprehensive coverage for:

  • matchesDomainPolicyPattern
  • isAllowedDomain

Test Coverage

  • ✅ Exact domain matches
  • ✅ Wildcard patterns
  • ✅ Nested subdomains
  • ✅ Empty allowlist behavior

Documentation

Added a new section documenting:

  • Relationship between BrowserChatTools and BrowserChatToolsAllowedDomains
  • Example enterprise configuration
  • Usage guidelines

Notes for Reviewers

Policy Catalog

To regenerate the policy catalog locally, run:

npm run export-policy-data

Note: I manually added the policy entry to maintain repository consistency until the script is run.

Add enterprise policy/setting workbench.browser.chatTools.allowedDomains (BrowserChatToolsAllowedDomains) and enforce it for integrated browser chat tools. Introduces isAllowedDomain helper and matchesDomainPolicyPattern in the domain matcher, wires runtime checks into browser chat tools (open, navigate, click, drag, hover, handle dialog, read, screenshot, type, runPlaywrightCode) to block or verify navigation per the allowlist, and updates configuration/policy metadata and docs. Includes unit tests for matching and allowlist behavior. Behavior: empty array = no extra restriction; file URLs and URIs without a host always pass; supports wildcards and host entries like localhost/127.0.0.1.
Copilot AI review requested due to automatic review settings May 9, 2026 15:49
@vs-code-engineering
Copy link
Copy Markdown
Contributor

vs-code-engineering Bot commented May 9, 2026

📬 CODENOTIFY

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

@kycutler

Matched files:

  • src/vs/workbench/contrib/browserView/common/browserChatToolsAllowedDomains.ts
  • src/vs/workbench/contrib/browserView/electron-browser/features/browserEditorChatFeatures.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/browserToolHelpers.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/clickBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/dragElementTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/handleDialogBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/hoverElementTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/navigateBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/openBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/openBrowserToolNonAgentic.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/readBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/runPlaywrightCodeTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/screenshotBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/typeBrowserTool.ts
  • src/vs/workbench/contrib/browserView/test/common/browserChatToolsAllowedDomains.test.ts

@jruales

Matched files:

  • src/vs/workbench/contrib/browserView/common/browserChatToolsAllowedDomains.ts
  • src/vs/workbench/contrib/browserView/electron-browser/features/browserEditorChatFeatures.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/browserToolHelpers.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/clickBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/dragElementTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/handleDialogBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/hoverElementTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/navigateBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/openBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/openBrowserToolNonAgentic.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/readBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/runPlaywrightCodeTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/screenshotBrowserTool.ts
  • src/vs/workbench/contrib/browserView/electron-browser/tools/typeBrowserTool.ts
  • src/vs/workbench/contrib/browserView/test/common/browserChatToolsAllowedDomains.test.ts

@HyderYash
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces an enterprise-controlled domain allowlist for integrated browser chat tools in the workbench, allowing organizations to enable browser automation while restricting it to trusted hosts/domains (without impacting the fetch tool or the existing agent network filter settings).

Changes:

  • Adds workbench.browser.chatTools.allowedDomains + BrowserChatToolsAllowedDomains policy, and wires enforcement into integrated browser chat tools.
  • Introduces policy-oriented domain matching (matchesDomainPolicyPattern) to support allowlist entries like localhost and 127.0.0.1.
  • Adds unit tests for the new allowlist behavior and the policy matcher.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/vs/workbench/contrib/browserView/test/common/browserChatToolsAllowedDomains.test.ts Adds tests for isAllowedDomain behavior (empty list, wildcard, file URLs).
src/vs/workbench/contrib/browserView/electron-browser/tools/typeBrowserTool.ts Enforces allowlist before typing by verifying the current page URL.
src/vs/workbench/contrib/browserView/electron-browser/tools/screenshotBrowserTool.ts Enforces allowlist before screenshotting by verifying the current page URL.
src/vs/workbench/contrib/browserView/electron-browser/tools/runPlaywrightCodeTool.ts Enforces allowlist before/after code execution (and around deferred results).
src/vs/workbench/contrib/browserView/electron-browser/tools/readBrowserTool.ts Enforces allowlist before reading page summaries.
src/vs/workbench/contrib/browserView/electron-browser/tools/openBrowserToolNonAgentic.ts Enforces allowlist during URL open (non-agentic variant).
src/vs/workbench/contrib/browserView/electron-browser/tools/openBrowserTool.ts Enforces allowlist for open/share flows and verifies final page URL.
src/vs/workbench/contrib/browserView/electron-browser/tools/navigateBrowserTool.ts Enforces allowlist for URL navigation and adds post-navigation verification.
src/vs/workbench/contrib/browserView/electron-browser/tools/hoverElementTool.ts Enforces allowlist before hovering by verifying the current page URL.
src/vs/workbench/contrib/browserView/electron-browser/tools/handleDialogBrowserTool.ts Enforces allowlist before dialog handling by verifying the current page URL.
src/vs/workbench/contrib/browserView/electron-browser/tools/dragElementTool.ts Enforces allowlist before dragging by verifying the current page URL.
src/vs/workbench/contrib/browserView/electron-browser/tools/clickBrowserTool.ts Enforces allowlist before clicking by verifying the current page URL.
src/vs/workbench/contrib/browserView/electron-browser/tools/browserToolHelpers.ts Adds shared allowlist guard + helper to verify the current page URL against policy.
src/vs/workbench/contrib/browserView/electron-browser/features/browserEditorChatFeatures.ts Registers the new setting + policy metadata in configuration.
src/vs/workbench/contrib/browserView/common/browserChatToolsAllowedDomains.ts Implements allowlist evaluation for URLs using existing domain parsing helpers.
src/vs/platform/networkFilter/test/common/domainMatcher.test.ts Adds tests for policy-specific domain pattern matching.
src/vs/platform/networkFilter/common/domainMatcher.ts Adds matchesDomainPolicyPattern (pattern normalization suited for allowlists/policies).
build/lib/policies/policyData.jsonc Adds the policy catalog entry for BrowserChatToolsAllowedDomains.
.github/copilot-instructions.md Documents the new policy/setting relationship for integrated browser chat tools.

}
let url: string;
try {
url = await playwrightService.invokeFunctionRaw(sessionId, pageId, async (page: Page) => page.url());
Comment on lines 116 to +123
if (!params.pageId) {
return errorResult(`No page ID provided. Use '${OpenPageToolId}' first.`);
}

let result: IToolResult;
switch (params.type) {
case 'reload':
return playwrightInvoke(this.playwrightService, sessionId, params.pageId, (page) => page.reload({ waitUntil: 'domcontentloaded' }));
result = await playwrightInvoke(this.playwrightService, sessionId, params.pageId, (page) => page.reload({ waitUntil: 'domcontentloaded' }));
Replace direct playwrightService.invokeFunctionRaw call with the shared playwrightInvokeRaw helper in browserToolHelpers to centralize Playwright invocations. Add a domain policy pre-check in NavigateBrowserTool that calls getBrowserChatToolDomainBlockedToolResult and returns early if the page is blocked, preventing navigation when domain restrictions apply.
@HyderYash
Copy link
Copy Markdown
Author

Thanks for the review! Addressed both points:

• Switched to playwrightInvokeRaw so the function is passed as a string to invokeFunctionRaw, matching existing patterns.
• Added a pre-navigation domain check in navigateBrowserTool.invoke() and kept the post-navigation check to catch redirects.

Happy to make any further changes if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add policy to restrict browser agent tools to specific domains (independent of fetch tool)

3 participants