Skip to content

fix(sandbox): undefine the raw fetch host bridge before user code runs - #6761

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/sandbox-fetchref-hardening
Aug 16, 2026
Merged

fix(sandbox): undefine the raw fetch host bridge before user code runs#6761
waleedlatif1 merged 3 commits into
stagingfrom
fix/sandbox-fetchref-hardening

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • executeCode installed the __fetchRef host bridge as an isolate global but omitted it from the bootstrap's undefined_globals, so user code ran with a live raw ivm.Reference in scope
  • Capture the bridge in the fetch closure and add __fetchRef to the hardening list, matching the pattern sim/executeTask already use
  • Add a regression test asserting every ivm.Reference bridge set as an isolate global is undefined before user code runs

Type of Change

  • Bug fix

Testing

Drove the real worker over its IPC protocol before/after: typeof __fetchRef goes "object" -> "undefined", while fetch(), console, and sim.* keep working. Not exploitable on the pinned isolated-vm 6.1.2 (Reference#get does not traverse prototypes) - this is defense-in-depth so a version bump cannot turn it into worker-process code execution.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Aug 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 16, 2026 1:47am

Request Review

@cursor

cursor Bot commented Aug 16, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes sandbox bootstrap and global hardening on the user-code execution path; behavior of fetch must stay correct while removing a host bridge from the isolate global scope.

Overview
Defense-in-depth for the executeCode isolated-vm path: user code could still see a live __fetchRef ivm.Reference global because the bootstrap never removed it after wiring fetch.

The bootstrap now captures __fetchRef in an IIFE closure, installs fetch via Object.defineProperty, and adds __fetchRef to the same undefined_globals hardening list used for __brokerRef and isolated-vm escape globals—aligned with how sim and executeTask already treat host bridges.

A new static regression test (isolated-vm-worker-hardening.test.ts) parses each execution path in the worker and asserts every jail.set('__*Ref', …) bridge is listed in that path’s undefined_globals, plus the standard escape globals.

Reviewed by Cursor Bugbot for commit 99e4a61. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR prevents user code from accessing the raw fetch host reference while preserving the sandboxed fetch API.

  • Captures __fetchRef inside the fetch closure before hardening globals.
  • Adds __fetchRef to the executeCode hardening list.
  • Adds per-execution-path regression coverage for exposed ivm.Reference bridges.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/lib/execution/isolated-vm-worker.cjs Captures the fetch bridge in a closure and removes its raw global binding before user code executes.
apps/sim/lib/execution/isolated-vm-worker-hardening.test.ts Verifies each execution path independently hardens all currently installed raw-reference bridges, resolving the previous global-list matching issue.

Reviews (3): Last reviewed commit: "fix(sandbox): preserve the fetch global'..." | Re-trigger Greptile

Comment thread apps/sim/lib/execution/isolated-vm-worker-hardening.test.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit b763250. Configure here.

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 99e4a61. Configure here.

@waleedlatif1
waleedlatif1 merged commit 6e5c337 into staging Aug 16, 2026
30 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/sandbox-fetchref-hardening branch August 16, 2026 01:54
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