Skip to content

feat(caplet-sandbox-prototype): Sandboxed iframe caplet UI prototype#804

Draft
sirtimid wants to merge 1 commit intomainfrom
sirtimid/caplet-sandbox-prototype
Draft

feat(caplet-sandbox-prototype): Sandboxed iframe caplet UI prototype#804
sirtimid wants to merge 1 commit intomainfrom
sirtimid/caplet-sandbox-prototype

Conversation

@sirtimid
Copy link
Contributor

@sirtimid sirtimid commented Feb 3, 2026

Summary

Proof-of-concept prototype for caplet UIs running in sandboxed iframes with Preact. This explores an architecture where:

  • Host manages caplet backends (state + method handlers) and routes messages by capletId
  • Caplets run in sandboxed iframes, communicate via postMessage to window.top
  • Widgets can be nested in caplets via <Slot> component, each with their own backend

Key components:

  • CapletManager - Host-side message router for multiple caplets/widgets
  • CapletBridge - Iframe-side communication bridge
  • Slot - Component for embedding nested widget iframes
  • SDK hooks (useBackendState, useBackendMethods) - React-style state subscription

To try it:

yarn workspace @ocap/caplet-sandbox-prototype dev

Security notes (prototype limitations):

  • Uses allow-same-origin sandbox attribute (required for Vite dev server)
  • Uses wildcard * for postMessage origin
  • No origin validation on incoming messages

These would need to be addressed for production (cross-origin serving, explicit origins, etc.)

Test plan

  • Manual testing: main caplet counter/items work
  • Manual testing: nested Color Widget renders and updates host state
  • Lint passes

🤖 Generated with Claude Code

Implements a proof-of-concept for caplet UIs running in sandboxed iframes
with Preact. Demonstrates:

- Host-managed caplet backends with state and method handlers
- postMessage-based communication protocol with capletId routing
- Nested widget iframes (Slot component) for widget composition
- State subscription pattern for reactive UI updates

All caplets/widgets communicate directly with window.top, enabling
arbitrary nesting depth while maintaining simple message routing.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@socket-security
Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​preact/​preset-vite@​2.10.39910010092100
Addedpreact@​10.28.310010010098100

View full report

@socket-security
Copy link

Caution

MetaMask internal reviewing guidelines:

  • Do not ignore-all
  • Each alert has instructions on how to review if you don't know what it means. If lost, ask your Security Liaison or the supply-chain group
  • Copy-paste ignore lines for specific packages or a group of one kind with a note on what research you did to deem it safe.
    @SocketSecurity ignore npm/PACKAGE@VERSION
Action Severity Alert  (click "▶" to expand/collapse)
Block Medium
Network access: npm source-map in module globalThis["fetch"]

Module: globalThis["fetch"]

Location: Package overview

From: ?npm/@preact/preset-vite@2.10.3npm/source-map@0.7.6

ℹ Read more on: This package | This alert | What is network access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should remove all network access that is functionally unnecessary. Consumers should audit network access to ensure legitimate use.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/source-map@0.7.6. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Block Medium
Network access: npm vite-prerender-plugin in module globalThis["fetch"]

Module: globalThis["fetch"]

Location: Package overview

From: ?npm/@preact/preset-vite@2.10.3npm/vite-prerender-plugin@0.5.12

ℹ Read more on: This package | This alert | What is network access?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: Packages should remove all network access that is functionally unnecessary. Consumers should audit network access to ensure legitimate use.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/vite-prerender-plugin@0.5.12. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

Warn Low
Potential code anomaly (AI signal): npm @babel/core is 100.0% likely to have a medium risk anomaly

Notes: The examined code is a standard, benign helper for constructing and wrapping configuration items from descriptors within Babel’s tooling. There is no evidence of data leakage, exfiltration, backdoors, or other malicious activity in this fragment. The combination of immutability, brand-based identity, and non-enumerable descriptor storage indicates a well-scoped internal utility rather than anything suspicious.

Confidence: 1.00

Severity: 0.60

From: ?npm/@vitejs/plugin-react@5.1.2npm/@metamask/snaps-utils@11.7.1npm/@preact/preset-vite@2.10.3npm/@babel/core@7.29.0

ℹ Read more on: This package | This alert | What is an AI-detected potential code anomaly?

Next steps: Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support@socket.dev.

Suggestion: An AI system found a low-risk anomaly in this package. It may still be fine to use, but you should check that it is safe before proceeding.

Mark the package as acceptable risk. To ignore this alert only in this pull request, reply with the comment @SocketSecurity ignore npm/@babel/core@7.29.0. You can also ignore all packages with @SocketSecurity ignore-all. To ignore an alert for all future pull requests, use Socket's Dashboard to change the triage state of this alert.

View full report

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