Skip to content

Browser: harden remote unlisted view networking - #345149

Merged
Ulugbek Abdullaev (ulugbekna) merged 2 commits into
mainfrom
ulugbekna/agents/remote-browser-proxy-hardening
Oct 30, 2026
Merged

Ulugbek Abdullaev (ulugbekna) merged 2 commits into
mainfrom
ulugbekna/agents/remote-browser-proxy-hardening

Conversation

@ulugbekna

Copy link
Copy Markdown
Contributor

Summary

This closes two generic network-containment gaps for unlisted BrowserViews using a remote Agent Host network:

  1. Forward authenticated plain-HTTP WebSocket Upgrade traffic (ws://) through TunnelProxy, including IPv6 literals and client cancellation while the upstream dial is pending.
  2. Prevent traffic from escaping the selected remote network through non-proxied WebRTC UDP or system-browser popup handling.

The changes are independent of canvas enablement and apply to any remote unlisted BrowserView.

How to review

Review the two commits independently:

1. browser: proxy authenticated WebSocket upgrades

  • TunnelProxy._onUpgrade authenticates the proxy request, validates an absolute HTTP URL, normalizes IPv6 literals, forwards the origin-form request, and bridges the established stream.
  • Client closure is observed while connecting; a late upstream stream is destroyed before forwarding.
  • tunnelProxy.test.ts covers successful Upgrade forwarding, IPv6 normalization, and abandoned connections.

2. browser: contain remote unlisted views

  • BrowserView applies disable_non_proxied_udp when its browser session has a remote network.
  • getBrowserViewPopupAction denies external popup escape for unlisted remote views while preserving listed browser-tab behavior and consuming the initiating gesture.

Security properties

  • Proxy authentication remains mandatory for Upgrade requests.
  • The destination host/port comes only from a valid absolute http: request target.
  • Proxy credentials and hop-by-hop proxy headers are not forwarded upstream.
  • WebRTC can use only proxied routes.
  • An unlisted remote BrowserView cannot open its URL in the client system browser.

Validation

  • npm run build-fast -- --client-only — passed
  • npm run typecheck-client — passed
  • ./scripts/test.sh --run src/vs/platform/tunnel/test/node/tunnelProxy.test.ts --run src/vs/platform/browserView/test/common/browserView.test.ts — 42 passed
  • Changed TypeScript ESLint — passed for 5 files
  • git diff origin/main..HEAD --check — passed

@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

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

Kyle Cutler (@kycutler)

Matched files:

  • src/vs/platform/browserView/common/browserView.ts
  • src/vs/platform/browserView/electron-main/browserView.ts
  • src/vs/platform/browserView/test/common/browserView.test.ts

Joaquín Ruales (@jruales)

Matched files:

  • src/vs/platform/browserView/common/browserView.ts
  • src/vs/platform/browserView/electron-main/browserView.ts
  • src/vs/platform/browserView/test/common/browserView.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.

🟡 Changes recommended

Upgrade sockets lack early error handling and lifecycle tracking, allowing client resets to crash the host process and unauthenticated connections to remain open after proxy disposal.

2 open issues
What changed in this PR

This PR hardens networking for remote unlisted BrowserViews by adding authenticated WebSocket Upgrade forwarding and blocking routes that could bypass the selected remote network.

Changes:

  • Adds HTTP Upgrade forwarding through TunnelProxy, including IPv6 handling and cleanup after client cancellation.
  • Restricts non-proxied WebRTC UDP and denies external popups from remote unlisted views.
  • Adds proxy and popup-policy regression tests, adjusts stream cleanup, and removes URL paths from proxy logs.
File Description
src/​vs/​platform/​tunnel/​test/​node/​tunnelProxy.test.ts Tests Upgrade forwarding, IPv6, cancellation, and direct Duplex connections.
src/​vs/​platform/​tunnel/​node/​tunnelProxy.ts Implements authenticated Upgrade forwarding and adjusts cleanup and logging.
src/​vs/​platform/​browserView/​test/​common/​browserView.test.ts Tests popup denial and gesture consumption for remote unlisted views.
src/​vs/​platform/​browserView/​electron-main/​browserView.ts Applies WebRTC restrictions and passes remote-network state to popup handling.
src/​vs/​platform/​browserView/​common/​browserView.ts Denies external popups for remote unlisted views while preserving listed-tab behavior.

Review effort: Balanced

Forward ws:// Upgrade traffic through TunnelProxy, cancel abandoned upstream connections, and cover authenticated forwarding and teardown behavior.

Co-authored-by: Copilot <[email protected]>
Disable non-proxied WebRTC UDP and prevent remote unlisted BrowserViews from escaping through external popups.

Co-authored-by: Copilot <[email protected]>
@ulugbekna
Ulugbek Abdullaev (ulugbekna) force-pushed the ulugbekna/agents/remote-browser-proxy-hardening branch from dcb21b8 to 69f99fc Compare October 30, 2026 09:34
@ulugbekna
Ulugbek Abdullaev (ulugbekna) merged commit 8046bb1 into main Oct 30, 2026
55 checks passed
@ulugbekna
Ulugbek Abdullaev (ulugbekna) deleted the ulugbekna/agents/remote-browser-proxy-hardening branch October 30, 2026 09:51
@vs-code-engineering vs-code-engineering Bot added this to the 1.145.0 milestone Oct 30, 2026
Ulugbek Abdullaev (ulugbekna) added a commit that referenced this pull request Oct 30, 2026
<!-- Thank you for submitting a Pull Request. Please:
* Read our Pull Request guidelines:

https://github.com/microsoft/vscode/wiki/How-to-Contribute#pull-requests
* Associate an issue with the Pull Request.
* Ensure that the code is up-to-date with the `main` branch.
* Include a description of the proposed changes and how to test them.
-->

## Prerequisite


[#345149](#345149)
merged into `main` and provides the generic WebSocket/WebRTC/popup
hardening used here. This branch is rebased directly onto the merged
commits.

## Summary

This enables desktop canvases published by a remote Agent Host to render
in the existing native BrowserView canvas editor.

Remote canvas URLs retain their original URL, including `127.0.0.1`,
while the BrowserView resolves the network from the exact owning
session/chat. The canvas requires that network, preventing a
disconnected, unsupported, or disabled remote from falling back to the
client or an unrelated workspace remote.

## Architecture

```text
Remote Agent Host publishes CanvasState.url
                    │
                    ▼
AgentHostCanvasCollection projects the exact chat-owned canvas
                    │
                    ▼
CanvasService creates an unlisted BrowserView for the owning chat
                    │
                    ▼
SessionBrowserNetworkContribution resolves chat → session → host authority
                    │
                    ▼
BrowserViewWorkbenchService requires that resolved network
                    │
                    ▼
Existing authenticated Agent Host BrowserView proxy
                    │
                    ▼
Remote Agent Host network, including its loopback canvas server
```

### Fail-closed behavior

- `CanvasService` supplies the exact chat owner and requests strict
network resolution.
- `BrowserViewWorkbenchService` resolves the owner even when remote
proxying is disabled, then rejects if that network cannot be used.
- Ambient remote Editor windows delegate TCP to their Agent Host
connection.
- Non-ambient remote hosts present canvases only in the Agents window,
where owning-session resolution exists.
- Local canvases retain their current behavior.

## How to review

Review the two commits independently:

### 1. `canvases: enable remote Agent Host presentation`

1. Provider policy:
-
[`RemoteAgentHostSessionsProvider`](src/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts)
-
[`AgentHostChatContribution`](src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostChatContribution.ts)
-
[`RemoteAgentHostContribution`](src/vs/workbench/contrib/chat/browser/remoteAgentHost/remoteAgentHostChatContribution.ts)
2. Exact network requirement:
-
[`CanvasService.resolveCanvasModel`](src/vs/workbench/contrib/canvases/electron-browser/canvasService.ts)
-
[`BrowserViewWorkbenchService.createExternalBrowserView`](src/vs/workbench/contrib/browserView/electron-browser/browserViewWorkbenchService.ts)
- focused test: `does not fall back when an external view requires its
resolved network`
3. Ambient remote Editor TCP:
-
[`EditorRemoteAgentHostServiceClient`](src/vs/workbench/services/agentHost/browser/editorRemoteAgentHostServiceClient.ts)

Canvas enablement and strict routing intentionally remain in the same
commit: enabling presentation without fail-closed ownership would create
an unsafe intermediate state.

### 2. `canvases: add native remote network coverage`

-
[`browser.test.ts`](extensions/vscode-api-tests/src/singlefolder-tests/browser.test.ts)
drives a real Electron BrowserView through redirect, SSE, `ws://`, an 8
MiB response, and WebRTC gathering.
- It first disables remote proxying and verifies zero HTTP/WebSocket/UDP
traffic.
- It then enables proxying and verifies all browser protocols succeed
with zero UDP/STUN leakage.

## Validation

- `npm run build-fast -- --client-only` — passed
- `npm run typecheck-client` — passed
- Provider, canvas, chat contribution, and ambient remote client suites
— 1,824 passed
- Changed TypeScript ESLint — passed for 13 files
- `npm run valid-layers-check` — passed
- `npm run gulp compile-extension:vscode-api-tests` — passed with 0
errors
- `./scripts/test-integration.sh --suite api-folder --grep "remote Agent
Host network loads native Chromium protocols and fails closed"` — 1
passed
- `git diff origin/main..HEAD --check` — passed

## Manual dogfood

Verified against a Windows `devbox2` Remote Agent Host through an
authenticated dev tunnel:

- the remote agent discovered and opened the Session timeline canvas;
- the BrowserView rendered while retaining its remote loopback URL;
- that port had no listener on the Mac and direct local `curl` failed,
confirming traffic crossed the Agent Host proxy;
- closing, reopening, and interacting with the canvas succeeded.

## Scope and limitations

- Desktop native BrowserViews only.
- Copilot Agent Host canvas channels only.
- No public extension API changes.
- No relay transport support without negotiated TCP forwarding.
- Non-ambient remote hosts present canvases only in the Agents window.
Kyle Cutler (kycutler) added a commit that referenced this pull request Oct 30, 2026
* Browser: Tighten remote canvas networking

Follow-up to #345102 and #345149:
- Offer canvases on remote agent hosts only while browser remote proxying is enabled and the host can forward TCP; an unknown host, such as a disconnected one, keeps its canvases.
- Require an embedded view's owner network whenever an owner is given, instead of a separate flag.
- Remove the WebSocket upgrade handler from the tunnel proxy: Chromium always tunnels WebSockets, including ws://, through CONNECT.
- Replace the extension test commands with unit coverage for failing closed, gating, and large and WebSocket traffic over agent host streams.

Co-authored-by: Copilot <[email protected]>

* Browser: Address remote canvas review feedback

Resolve an embedded view's owner network before any asynchronous work and reject unknown agent owners instead of falling back to the local network. Gate remote editor-window canvases reactively on remote browser proxying. Cover the browser proxy over real Agent Host TCP and Chromium's remote WebSocket, large-response and WebRTC UDP behavior in the remote API suite.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
Dmitrii F. (lingeniare) pushed a commit to lingeniare/vegaide that referenced this pull request Nov 7, 2026
<!-- Thank you for submitting a Pull Request. Please:
* Read our Pull Request guidelines:

https://github.com/microsoft/vscode/wiki/How-to-Contribute#pull-requests
* Associate an issue with the Pull Request.
* Ensure that the code is up-to-date with the `main` branch.
* Include a description of the proposed changes and how to test them.
-->

## Prerequisite


[microsoft/vscode#345149](microsoft/vscode#345149)
merged into `main` and provides the generic WebSocket/WebRTC/popup
hardening used here. This branch is rebased directly onto the merged
commits.

## Summary

This enables desktop canvases published by a remote Agent Host to render
in the existing native BrowserView canvas editor.

Remote canvas URLs retain their original URL, including `127.0.0.1`,
while the BrowserView resolves the network from the exact owning
session/chat. The canvas requires that network, preventing a
disconnected, unsupported, or disabled remote from falling back to the
client or an unrelated workspace remote.

## Architecture

```text
Remote Agent Host publishes CanvasState.url
                    │
                    ▼
AgentHostCanvasCollection projects the exact chat-owned canvas
                    │
                    ▼
CanvasService creates an unlisted BrowserView for the owning chat
                    │
                    ▼
SessionBrowserNetworkContribution resolves chat → session → host authority
                    │
                    ▼
BrowserViewWorkbenchService requires that resolved network
                    │
                    ▼
Existing authenticated Agent Host BrowserView proxy
                    │
                    ▼
Remote Agent Host network, including its loopback canvas server
```

### Fail-closed behavior

- `CanvasService` supplies the exact chat owner and requests strict
network resolution.
- `BrowserViewWorkbenchService` resolves the owner even when remote
proxying is disabled, then rejects if that network cannot be used.
- Ambient remote Editor windows delegate TCP to their Agent Host
connection.
- Non-ambient remote hosts present canvases only in the Agents window,
where owning-session resolution exists.
- Local canvases retain their current behavior.

## How to review

Review the two commits independently:

### 1. `canvases: enable remote Agent Host presentation`

1. Provider policy:
-
[`RemoteAgentHostSessionsProvider`](src/vs/sessions/contrib/providers/remoteAgentHost/browser/remoteAgentHostSessionsProvider.ts)
-
[`AgentHostChatContribution`](src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostChatContribution.ts)
-
[`RemoteAgentHostContribution`](src/vs/workbench/contrib/chat/browser/remoteAgentHost/remoteAgentHostChatContribution.ts)
2. Exact network requirement:
-
[`CanvasService.resolveCanvasModel`](src/vs/workbench/contrib/canvases/electron-browser/canvasService.ts)
-
[`BrowserViewWorkbenchService.createExternalBrowserView`](src/vs/workbench/contrib/browserView/electron-browser/browserViewWorkbenchService.ts)
- focused test: `does not fall back when an external view requires its
resolved network`
3. Ambient remote Editor TCP:
-
[`EditorRemoteAgentHostServiceClient`](src/vs/workbench/services/agentHost/browser/editorRemoteAgentHostServiceClient.ts)

Canvas enablement and strict routing intentionally remain in the same
commit: enabling presentation without fail-closed ownership would create
an unsafe intermediate state.

### 2. `canvases: add native remote network coverage`

-
[`browser.test.ts`](extensions/vscode-api-tests/src/singlefolder-tests/browser.test.ts)
drives a real Electron BrowserView through redirect, SSE, `ws://`, an 8
MiB response, and WebRTC gathering.
- It first disables remote proxying and verifies zero HTTP/WebSocket/UDP
traffic.
- It then enables proxying and verifies all browser protocols succeed
with zero UDP/STUN leakage.

## Validation

- `npm run build-fast -- --client-only` — passed
- `npm run typecheck-client` — passed
- Provider, canvas, chat contribution, and ambient remote client suites
— 1,824 passed
- Changed TypeScript ESLint — passed for 13 files
- `npm run valid-layers-check` — passed
- `npm run gulp compile-extension:vscode-api-tests` — passed with 0
errors
- `./scripts/test-integration.sh --suite api-folder --grep "remote Agent
Host network loads native Chromium protocols and fails closed"` — 1
passed
- `git diff origin/main..HEAD --check` — passed

## Manual dogfood

Verified against a Windows `devbox2` Remote Agent Host through an
authenticated dev tunnel:

- the remote agent discovered and opened the Session timeline canvas;
- the BrowserView rendered while retaining its remote loopback URL;
- that port had no listener on the Mac and direct local `curl` failed,
confirming traffic crossed the Agent Host proxy;
- closing, reopening, and interacting with the canvas succeeded.

## Scope and limitations

- Desktop native BrowserViews only.
- Copilot Agent Host canvas channels only.
- No public extension API changes.
- No relay transport support without negotiated TCP forwarding.
- Non-ambient remote hosts present canvases only in the Agents window.
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.

3 participants