plan: <tonk-portal> sandboxed artifact rendering#460
Conversation
Design doc for a custom element that renders untrusted HTML artifacts inside a nested-iframe sandbox. Outer iframe holds a fixed bootstrap under sandbox="allow-scripts" with no allow-same-origin; inner iframe inherits the outer's opaque origin via srcdoc so the artifact's scripts can reach parent.tonk synchronously. The outer constructs a MessageChannel and posts port2 up to the host; subscriptions return transferred ReadableStreams so the host keeps no subscription-lifecycle state.
|
Wrangler output for this change: ⛅️ wrangler 4.64.0 (update available 4.93.0) Uploaded tonk-access-service (3.32 sec) To deploy this version to production traffic use the command wrangler versions deploy Changes to non-versioned settings (config properties 'logpush' or 'tail_consumers') take effect after your next deployment using the command wrangler versions deploy Changes to triggers (routes, custom domains, cron schedules, etc) must be applied with the command wrangler triggers deploy |
The niri-strip view's embedded-script approach is a stopgap. The destination architecture (PR #460) has <tonk-display> as a pure declarative {field}-substitution template and routes arbitrary HTML+CSS+JS through <tonk-portal> — a sandboxed nested-iframe element with parent.tonk.{query,subscribe,transact} as the data surface. Three pieces of plumbing exist only to keep the stopgap working: <tonk-display>'s script-activation pass, the <script>/<style> carve-out in tonk-concept's binding walker, and the outer <template> wrapper around the niri view body. plan/ niri-portal-migration.md records the rollback for when portals land: - Move the niri view body to an artifact-content claim - Swap <tonk-display view=niri-strip> for <tonk-portal source=...> - Replace the hidden <tonk-concept> + MutationObserver hack with parent.tonk.subscribe(...) reading a real ReadableStream - Replace tonk-layout/* CustomEvents with parent.tonk.transact(notation) (or PR #461 transients) - Delete <tonk-display>'s script-activation helper - Optionally remove the binding-walker carve-out Adds a doc-comment header on tonk-ui::niri pointing at the plan.
Rough plan of how sandboxed iframe could be manifested
PR-Codex overview
This PR introduces the
<tonk-portal>element, which allows for the rendering of untrusted HTML artifacts in a secure manner using nested iframes. It outlines the structure, functionality, and lifecycle of the component, ensuring safe data access while isolating the host page.Detailed summary
<tonk-portal>element.<tonk-portal>.sourceattribute as a DID for content claims.