Skip to content

Harden codemode browser executor#1505

Merged
threepointone merged 2 commits into
mainfrom
fix/codemode-browser-hardening
May 12, 2026
Merged

Harden codemode browser executor#1505
threepointone merged 2 commits into
mainfrom
fix/codemode-browser-hardening

Conversation

@threepointone
Copy link
Copy Markdown
Contributor

@threepointone threepointone commented May 12, 2026

Summary

  • Protect browser iframe codemode execution with per-run nonces on execute, tool-call, tool-result, and execution-result messages so forged sandbox completion messages are ignored and logged once per message type.
  • Fix codemode tool filtering so needsApproval: false remains available across AI, browser, framework-agnostic, and TanStack entry points, while approval-required tools stay excluded.
  • Reject sanitized tool-name collisions, run codemode browser tests in the package test script, and update docs/README/example/changelog copy for the browser export, iframe options, and timeout limitations.

Test plan

  • npm test in packages/codemode (222 unit tests + 33 browser tests before TanStack coverage; later 223 unit tests + 33 browser tests after adding TanStack regression)
  • npm run build in packages/codemode
  • npx vitest run --config vitest.browser.config.ts src/tests/iframe-executor.browser.test.ts
  • ReadLints on touched codemode files and docs

Notes

  • Browser iframe timeouts still cannot preempt tight synchronous loops such as while (true) {} because they block the browser event loop; this PR documents that limitation.
  • The mirrored developers.cloudflare.com MDX update lives in the separate cloudflare-docs checkout and is not part of this PR.

Made with Cursor


Open in Devin Review

Protect iframe execution results and tool calls with per-run nonces so sandbox code cannot spoof completion messages, and surface ignored nonce mismatches as bounded warnings for easier debugging. Also reject sanitized tool name collisions and keep explicitly safe tools marked with needsApproval: false across AI, browser, and TanStack entry points.

Run browser executor tests as part of the codemode package test script and update docs, README, examples, and changeset copy to describe the browser export, iframe options, and remaining timeout limitations.

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 12, 2026

⚠️ No Changeset found

Latest commit: 9d36ddd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes changesets to release 1 package
Name Type
@cloudflare/codemode Patch

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@threepointone threepointone requested a review from mattzcarey May 12, 2026 08:46
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 12, 2026

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1505

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1505

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1505

hono-agents

npm i https://pkg.pr.new/hono-agents@1505

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1505

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1505

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1505

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1505

commit: 9d36ddd

Apply the same sanitized tool-name collision check to DynamicWorkerExecutor that the browser iframe executor already uses, so server-side and browser-side codemode fail consistently instead of silently overwriting colliding tools.

Co-authored-by: Cursor <cursoragent@cursor.com>
@threepointone threepointone merged commit 7f4afc1 into main May 12, 2026
4 checks passed
@threepointone threepointone deleted the fix/codemode-browser-hardening branch May 12, 2026 09:12
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.

1 participant