Skip to main content

Companion origin isolation

Shellui embeds companion micro frontends in a sandboxed iframe (ContentView). This page describes the threat model, what Shellui does today, and the risks that remain.

Current architecture​

ModeShell originCompanion originIsolation mechanism
Dev (shellui start)http://localhost:4000 (typical)http://localhost:5173, :3000, :4200, …Distinct origins + companion frame-ancestors CSP allowing the shell
Prod, own originYour deploy originAnother origin, such as https://app.exampleDistinct origins + companion frame-ancestors CSP allowing the shell
Prod (shellui build)Your deploy originSame origin under /app/ (relative nav URLs)Same-origin companion path; no origin isolation between shell and app

Generated starters wire dev.url to a loopback companion port. The Next.js and Nuxt starters send this header:

Content-Security-Policy: frame-ancestors 'self' http://localhost:4000 http://127.0.0.1:4000

Only the companion's own origin and a shell on port 4000 of localhost or 127.0.0.1 can frame it. If your shell runs on another port or a deployed origin, update this header. The other starters do not set frame-ancestors.

Iframe sandbox​

Valid HTTP(S) companion URLs (cross-origin and same-origin, including /app/ and hash routes) and shell pages use:

allow-same-origin allow-scripts allow-forms allow-popups

Unparseable URLs and non-HTTP(S) schemes omit allow-same-origin (allow-scripts allow-forms allow-popups).

Shellui does not grant allow-popups-to-escape-sandbox, so popups opened by companion content stay sandboxed.

Shellui sets the sandbox attribute only on the content iframe it renders. It does not set a sandbox on nested frames. Frames a companion creates inside its own page, including frames rendered with the SDK frame component, get only the attributes the companion passes.

Implementation: packages/core/src/components/contentIframeSandbox.ts (resolved in ContentView).

Mitigations​

  1. Distinct origins in dev and dedicated prod origins. Shell and companion run on different ports or origins. Navigation url origin checks keep the iframe from drifting to an unexpected origin.
  2. Trusted navigation URLs. Only load companions you configure in navigation[].url or init templates.
  3. Settings message isolation. The shell accepts SHELLUI_SETTINGS and SHELLUI_SETTINGS_UPDATED only from the shell window itself or a shell-owned page (/__settings, /__cookie-preferences, /login, and other shell routes), not from companion frames.

Residual risk: allow-same-origin + allow-scripts​

When the iframe document is same-origin to its configured URL, scripts can remove the sandbox attribute. Companions need allow-same-origin today to load ES module scripts (<script type="module" crossorigin>), use cookies and localStorage, read same-origin parent routes where needed, and run the SDK postMessage handshake with a concrete origin.

Residual risk: same-origin production​

Production companions served from /app/ on the shell origin keep allow-same-origin, so the companion runs with the shell's origin. A script in that frame can read the shell's sessionStorage. Without the host routes, that includes the refresh token at shellui.auth.refresh. When the shell host keeps the refresh token in the HttpOnly shellui_refresh cookie, that key is empty, but a same-origin request to /api/auth still sends the cookie.

Serve untrusted companions on their own origin, and set SHELLUI_APP_URL or navigation url to that origin, when you need origin isolation between the shell and the companion.

Future work​

  • An optional navigation origin allowlist in the config schema.

Companion URL validation for dev.url and --follow lives in the CLI (CLI reference: companion process). Loopback login nonce binding is documented under CLI login.