Skip to content

0012. Sandboxing user games and content

  • Status: Accepted
  • Date: 2026-11-26
  • Phase: 3 (play page, publish pipeline), 4 (content packs)

Games contain user- and AI-written code. Content packs are user data. Both are untrusted. Threats: stealing platform sessions/tokens, phishing inside games, crypto-mining, malicious assets, schema-bomb payloads, abuse of the build service.

  1. Separate registrable domain for user content (e.g. [platform]usercontent.example), never a subdomain of the platform domain, so cookies and storage can never be shared. Each game gets its own subdomain (<game-id>.play.…) so games cannot read each other’s localStorage.
  2. Sandboxed iframe: sandbox="allow-scripts allow-pointer-lock" (no allow-same-origin, no allow-top-navigation, no allow-popups, no forms), plus allow="gamepad; fullscreen; autoplay" as needed.
  3. Strict CSP on game documents: default-src 'none'; scripts/assets only from the game’s own origin; connect-src only to the platform’s game API gateway; no inline script except hashed bootstrap; frame-ancestors = platform origins.
  4. Typed postMessage bridge (@ludrel/play-bridge): the only channel between game and platform (save, leaderboard, achievements, purchase intents, analytics). Platform validates origin and message schemas. Games never see user tokens; the platform makes authenticated calls on their behalf with per-game scopes and rate limits.
  5. Builds run in an isolated, network-less container with CPU/memory/time limits; output is static files only. Dependencies are restricted to an allowlist (our framework + vetted packages) in early phases.
  6. Content packs are data only (ADR 0015): schema validation (size limits, depth limits, allowed MIME types, image re-encoding to strip payloads), then publisher approval before going live.
  7. Moderation: report button on every game and pack, admin takedown, automated scanning (AI-assisted review of code diffs and assets) as a signal, not a gate, in early phases.
  • Same-origin hosting with CSP only: one XSS away from account takeover.
  • Running games in Web Workers/ShadowRealm only: no DOM/WebGL access for rendering; too restrictive.
  • Server-side static analysis as the main defence: unsound for JavaScript; useful only as a signal.

Cross-origin iframes complicate some features (fullscreen, gamepad focus, pointer lock), which must be tested in each browser. Cost of a wildcard certificate and second CDN distribution.