Browser-side isolation for App UIs
Research for Shell + App client guests (see root CONTEXT.md).
Question: how can a Shell host multiple App UIs so one App cannot read another App’s credentials, storage, or Host session cookies, while the Shell can still navigate between Apps?
Claims cite primary sources (MDN, HTML Standard, Sandstorm docs). Directions for later grilling — not a final pick.
Executive recommendation (for grilling)
Prefer Sandstorm-shaped origin isolation: serve each App UI from a distinct origin (per-App or per-instance subdomain / dedicated host), embed it in the Shell via <iframe>, and mediate Shell↔App only through an explicit postMessage (or capability) protocol. Layer sandbox, CSP, and Permissions-Policy as defense-in-depth — not as the only boundary.
Avoid: loading App UI from the same origin as the Shell with sandbox="allow-scripts allow-same-origin" (the frame can remove its own sandbox) (MDN iframe; HTML Standard).
Client-side Wasm is a rendering/compute guest inside that origin boundary; it does not replace origin isolation.
Option matrix
| Approach | Isolates cookies/storage from Shell? | Isolates App A from App B? | Can render full App UI? | Main failure modes |
|---|---|---|---|---|
| Same-origin iframe, no special isolation | No | No | Yes | Shared cookie jar; XSS in one App = Shell session |
Sandboxed iframe, no allow-same-origin |
Yes (opaque origin; no normal cookie/storage access) | Yes (each opaque origin unique) | Limited / awkward (opaque Origin: null, storage broken) |
Hard for real Apps that need their own persistence; UX brittle |
Sandboxed iframe + allow-same-origin on dedicated App origin |
Yes vs Shell (different origin) | Yes if each App has its own origin | Yes | Must not share Shell origin; weak CSP; postMessage spoofing; open-in-new-tab escape |
| Unique hostname per App/instance (Sandstorm pattern) + iframe | Yes | Yes | Yes | DNS/TLS ops; still need CSP + proxy auth |
| Web Worker / Worklet | N/A (no DOM cookies of Shell if careful) | Workers are separate from each other | No (no DOM) | Not a UI host; still message-passing to Shell |
| Client Wasm in page (same origin as Shell) | No by itself | No by itself | Possible | Wasm ≠ browser origin sandbox; DOM/cookie access still via JS host glue |
| Client Wasm inside per-App origin iframe | Yes (origin boundary) | Yes | Yes | Same as iframe model + Wasm toolchain cost |
iframe credentialless |
Ephemeral, no network cookies/storage of origin | Per top-level lifetime context | Constrained | Newer; may not fit Apps that need durable client state (MDN) |
Sandboxed iframes
What sandbox does
The sandbox attribute applies extra restrictions to the nested browsing context (MDN; HTML Standard).
Critical token: allow-same-origin
- Without it: content is treated as a special / opaque origin that fails same-origin checks — blocking normal access to data storage/cookies and some JS APIs (MDN; CSP
sandboxdirective notes the same for opaque origin /Origin: null— MDN CSP sandbox). - With it: content keeps its real origin (so it can use its own cookies/storage), while other sandbox flags still apply. It does not magically become same-origin with a cross-origin parent.
Dangerous combination
If the embedded page is same-origin as the Shell and both allow-scripts and allow-same-origin are set, the embedded page can remove the sandbox attribute and break out (MDN; HTML Standard).
Practical Host pattern
- Shell origin: e.g.
https://cloud.example - App UI origins: e.g.
https://<app-id>.apps.cloud.exampleor random per-install hosts (Sandstorm-style) - Embed with
sandbox="allow-scripts allow-forms …"andallow-same-originonly because the App origin ≠ Shell origin - Shell CSP
frame-srcallowlist to those App hosts; App responses useframe-ancestorslimited to the Shell (MDN frame-ancestors) - Permissions-Policy via iframe
allowto deny camera/mic/etc. unless granted
Cookie jar concern (user’s original worry)
A naive same-site iframe to another App path on the same registrable domain can still participate in cookie scoping surprises. Distinct hostnames (and Host-issued App session cookies scoped to that host) keep Shell session cookies off App documents. Partitioned third-party storage (Firefox State Partitioning) helps when Apps are third-party embeds, but first-party Shell cookies must simply never be readable from App documents — which same-origin policy enforces when origins differ.
Auth to App backends should use App-scoped tokens (or Host-proxied requests), not the Shell’s cookie on App origins.
Storage partitioning (third-party context)
Browsers increasingly partition storage by top-level site so embedded third parties do not share one cross-site bucket (MDN State Partitioning). Affected APIs include localStorage, IndexedDB, Cache, workers, etc.
Implication: if App UIs are cross-origin embeds under the Shell top-level site, their client storage is keyed under that partition — good for tracker isolation, but Apps must not assume “global” third-party cookie behavior. Prefer App-owned first-party-like hosts or Host-mediated storage Grants over relying on shared cookie jars.
Web Workers / Worklets
Workers run scripts off the main thread and communicate via messaging (MDN Using web workers). They do not own a document/DOM, so they cannot replace an App’s interactive UI surface.
Fit: run client Wasm or heavy logic inside a worker within an App’s origin iframe; isolate compute from Shell main thread. Not a substitute for multi-App UI isolation.
Client-side WebAssembly UI
Wasm in the browser still talks to the world through JS (DOM, fetch, cookies). Compiling UI to Wasm (e.g. canvas/DOM frameworks) does not create a new browser origin.
Dual guest mapping:
| Guest | Runs where | Isolation mechanism |
|---|---|---|
| Server App (Wasm) | Host (Wasmtime/…) | Capability imports / Dataset Grants |
| Client App (Wasm or JS) | Browser, inside App origin | Origin + iframe sandbox + CSP; optional worker for compute |
Recommended story for the spec: server Wasm + client UI guest, with client guest always loaded from an App-specific origin under Shell chrome — whether the client guest is JS or Wasm is secondary to origin isolation.
Product prior: Sandstorm
Sandstorm’s model (primary docs):
- Server: per-grain Linux sandbox (How it works).
- Client (planned/partial): apps in a sandboxed iframe with CSP to confine network communication to their own server (How it works; Security practices).
- HTTP APIs on separate hosts with CSP
sandbox/ tight policies so API hosts cannot reach other domains; tokens as capability, not ambient cookies (Exporting HTTP APIs).
Lesson: platform mediates auth and embedding; unique hosts + CSP + iframe beat “trust the App’s JS on the Shell origin.”
Failure modes checklist
- Shared origin with Shell → App XSS steals Shell session.
allow-scripts+allow-same-originon Shell origin → sandbox self-removal.- Trusted
postMessagewithout origin checks → App A impersonates Shell or App B. - Open App URL in top-level tab → sandbox attribute gone; serve App origins that remain safe standalone (limited cookies, CSP) (MDN).
- Shell XSS → game over for all embeds; Shell surface must stay minimal (nav, consent, launcher only).
- Over-broad
frame-src/connect-src→ App phones home or loads sibling Apps’ origins.
Directions for client/server App packaging and Shell isolation
- Lock origin strategy: per-App (or per-install) hostname under the Instance.
- Lock embedding: Shell iframe + sandbox flags safe for cross-origin App hosts.
- Lock bridge: versioned
postMessageprotocol; Shell validatesevent.origin. - Decide client guest format: JS UI vs client Wasm inside that iframe (orthogonal to isolation).
- Decide App auth: Host-issued scoped cookie/token on App host, or Host reverse-proxy with Grant checks — never Shell session cookie on App documents.