Skip to content

MCP App: Uncaught SecurityError thrown when communicating with (trusted) nested iframes #289386

Description

Does this issue occur when all extensions are disabled?: Yes

VSCode Insiders

Version: 1.109.0-insider
Commit: f60f946
Date: 2026-01-21T05:54:27.524Z
Electron: 39.2.7
ElectronBuildId: 13098910
Chromium: 142.0.7444.235
Node.js: 22.21.1
V8: 14.2.231.21-electron.0
OS: Darwin arm64 24.5.0

The Bug

VS Code patches addEventListener in MCP App iframes and tries to read event.source.origin to filter messages. However, reading event.source.origin on a cross-origin source throws a SecurityError:

Uncaught SecurityError: Failed to read a named property 'origin' from 'Window': 
Blocked a frame with origin "vscode-webview://..." from accessing a cross-origin frame.

Source: chatMcpAppModel.ts#L313

The Problem

The patched code does something like:

if (event.source.origin === document.location.origin) { ... }

But reading event.source.origin on a cross-origin frame throws! The fix should either:

  1. Wrap this in a try/catch block
  2. Use event.origin instead of event.source.origin

Why This Matters

MCP Apps may need to embed cross-origin iframes and communicate with them via postMessage. This is a common pattern for:

  • Embedding third-party widgets
  • Loading content from CDNs
  • Communicating with sandboxed content

Reproduction Steps

See comprehensive reproduction at https://github.com/JReinhold/vscode-iframe-reproduction/tree/main

1. Clone and Install

git clone git@github.com:JReinhold/vscode-iframe-reproduction.git
cd vscode-iframe-reproduction
npm install

2. Start the MCP Server

npm start

The server will start on http://localhost:3000/mcp

3. Open in VS Code Insiders

Open this folder in VS Code Insiders. The .vscode/mcp.json file is already configured to connect to the local MCP server.

4. Call the MCP Tool

In VS Code's GitHub Copilot Chat, ask:

Call the show-example tool with message "test"

5. Trigger the Bug

  1. The MCP App loads with a nested iframe from http://localhost:3000
  2. Click the red "Send Message to Parent (triggers bug)" button in the nested iframe
  3. Observe the SecurityError appear in the error box and in DevTools console

cc Connor Peet (@connor4312), as discussed in the MCP UI Discord

Metadata

Metadata

Labels

bugIssue identified by VS Code Team member as probable bugchat-mcpinsiders-releasedPatch has been released in VS Code InsidersverifiedVerification succeeded

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions