AI Focus

csp & iframe sandbox studio

Why this matters

Arguments about browser sandboxing often rely on assumptions about double-nested iframes, <meta> CSP tags, <iframe csp> (CSPEE), and blob: Workers without testing them across two separate web origins. Client APIs such as navigator.sendBeacon() can even return true when CSP silently cancelled the request. This studio mounts a separate companion origin (csp-sandbox-buffer-origin) and a SQLite Durable Object canary so every header, framing pattern, MessagePort bridge, and Worker setup is measured against real browser enforcement.

What this opens up

Clear architectural decisions for plugin hosts, untrusted HTML previews, and generated UI panels in standard browser tabs: use a faster single cross-origin iframe with strict HTTP headers when you control the origin, a double-iframe buffer when wrapping uncontrolled third-party pages, and a narrowed revocable MessagePort for safe host calls.

How the tests work

  1. In 1. Policy & Sandbox Builder, choose one of the six presets (or customize all 9 <iframe sandbox> flags, CSP directives, Connection-Allowlist, and <iframe csp>) and click Run Active Preset in 14-Vector Test.
  2. In 2. 14-Vector Leak Test, run all 14 network, subframe, navigation, storage, and DOM breakout probes and click Compare Single vs Double Latency; zero hits in DO Canary confirms the boundary held outside the tab.
  3. Switch to 3. Capability Bridge (Hawser) to fire allowed reads, disallowed write() calls, constructor prototype walks, AbortSignal cancellations, and instant port revocation across a narrowed Hawser MessagePort, an unfiltered proxy, and raw window.postMessage.
  4. Open 4. Web Worker Matrix (4 Setups) and click Run All 4 Worker Topologies to compare fetch(), WebSocket, indexedDB, OPFS, BroadcastChannel, and importScripts() across same-origin HTTP, same-origin blob:, opaque-iframe blob:, and cross-origin buffer Workers.
Dual-origin sandbox workbench comparing all 9 iframe sandbox flags, single vs. double iframes, CSPEE, Connection-Allowlist, revocable MessagePort bridges, and four Web Worker setups against a live server canary. Open csp & iframe sandbox studio full screen ↗

Hypothesis

Pairing a distinct buffer origin (csp-sandbox-buffer-origin), strict HTTP CSP (sandbox + frame-src 'none' + connect-src 'none'), and a prototype-locked, method-allowlisted, revocable MessagePort (hawser.js pattern) provides verifiable network and capability containment across both single-frame and double-iframe topologies, whereas blob: Workers inherit parent network policy unless isolated behind an opaque origin or separate Worker HTTP CSP.

What confirms it: Locked configurations record zero hits in the ContainmentTelemetry Durable Object across all 14 breakout and leak probes; the Hawser MessagePort bridge blocks __proto__/constructor/prototype traversal and stops immediately on port.close(); and the 4-topology Worker matrix clearly separates HTTP-CSP and cross-origin isolation from same-origin blob: inheritance.

What bounds or disproves it: Double-iframe <meta> CSP injection fails to tighten restrictions already stripped by an outer sandbox, <iframe csp> CSPEE is ignored in non-Chromium engines, or an unfiltered MessagePort proxy permits prototype/method escape across the buffer boundary.

Under the hood

CSP & Iframe Sandbox Studio (GitHub) runs across two separate Cloudflare Worker origins—the primary host Worker (csp-iframe-sandbox-studio) and a companion cross-origin buffer Worker (csp-sandbox-buffer-origin, defined in src/buffer-worker.ts and wrangler.buffer.jsonc)—paired with a SQLite Durable Object (ContainmentTelemetry) that records real canary hits and Reporting-Endpoints violation posts.

The four workbench benches exercise distinct parts of the browser security model: (1) a live compiler for all 9 HTML sandbox flags, HTTP CSP directives (including CSP: sandbox and Trusted Types), <iframe csp> CSPEE, Connection-Allowlist, COOP/COEP/CORP, and 6 pushback presets; (2) a 14-vector breakout harness with single-frame vs. double-iframe mount latency timing; (3) a cross-origin DemoVault bridge pitting a prototype-locked, method-allowlisted, revocable MessagePort (allow: ["read", "slowRead"], FORBIDDEN = new Set(["__proto__", "constructor", "prototype"]), AbortSignal, instant port.close()) against an unfiltered proxy and raw window.postMessage; and (4) a 4-topology Worker matrix comparing same-origin HTTP Workers (/workers/locked-worker.js), same-origin blob: Workers, opaque-iframe blob: Workers, and cross-origin buffer Workers (/buffer-worker.js).

Key terms & further reading

<iframe sandbox> flags ↗
Nine opt-in tokens that lock an embedded iframe into a throwaway origin unless relaxed (avoid pairing allow-scripts with allow-same-origin on your own origin).
Content Security Policy (CSP Level 3) ↗
An immutable HTTP response header controlling which scripts, nested frames (frame-src), images, and network connections a document or Worker may perform.
CSP Embedded Enforcement (CSPEE) ↗
The Chromium-only <iframe csp="..."> attribute that asks an embedded third-party page to agree to a minimum CSP before rendering.
Connection-Allowlist (WICG) ↗
A single deny-by-default HTTP header that blocks outbound connections—including redirects, prefetches, and WebRTC—unless their URL matches an explicit allowlist.
MessagePort capability bridge (Hawser) ↗
A private two-way channel transferred into a sandboxed frame that exposes only allowlisted methods, blocks prototype-chain escapes, and revokes access immediately via port.close().
Cloudflare Durable Object canary ↗
A server-side SQLite state store recording real arriving HTTP/WebSocket requests and CSP violation reports so containment is verified outside the browser.

Open questions

  • When does a single cross-origin frame plus a narrowed hawser.js MessagePort beat a double-iframe topology on mount latency and operational simplicity?
  • Which Connection-Allowlist directives supersede connect-src 'none' for non-fetch channels like prefetch and WebRTC across Chromium milestones?

Iteration log

  • — Deployed dual-origin Cloudflare Worker studio (csp-iframe-sandbox-studio + csp-sandbox-buffer-origin) with 9-flag sandbox & CSPEE configurator, 6 pushback presets, 14-vector ContainmentTelemetry DO harness, hawser.js-pattern vs. unfiltered MessagePort comparator, and 4-topology Worker Isolation Matrix.

Primitives tested: <iframe sandbox>, CSP Level 3, CSP Embedded Enforcement (<iframe csp>), Connection-Allowlist, MessagePort, Dedicated Worker CSP, Reporting-Endpoints, Durable Object SQLite.

This is an active lab under /labs/ and stays off the main RSS feed until graduated into a full essay.

More in browser containment & sandbox boundaries

Connected labs

← browser containment & sandbox boundaries · All labs