0012. Sandboxing user games and content
- Status: Accepted
- Date: 2026-11-26
- Phase: 3 (play page, publish pipeline), 4 (content packs)
Context
Section titled “Context”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.
Decision
Section titled “Decision”- 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’slocalStorage. - Sandboxed iframe:
sandbox="allow-scripts allow-pointer-lock"(noallow-same-origin, noallow-top-navigation, noallow-popups, no forms), plusallow="gamepad; fullscreen; autoplay"as needed. - Strict CSP on game documents:
default-src 'none'; scripts/assets only from the game’s own origin;connect-srconly to the platform’s game API gateway; no inline script except hashed bootstrap;frame-ancestors= platform origins. - Typed
postMessagebridge (@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. - 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.
- 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.
- 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.
Alternatives considered
Section titled “Alternatives considered”- 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.
Consequences
Section titled “Consequences”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.