Skip to content

Hostile player games review (ENG-1499) ​

This review covers player-authored game source running in the browser, authoritative room workers, and settings discovery during publishing. The fixtures deliberately violate the normal game-authoring rules. Never execute them as trusted direct-mode games or import their modules on the Node main thread.

Status (2026-11-02): every hostile test below passes on the host; the defences hold for the attacks listed. What this review does not prove is under "Open risks": chiefly real-browser enforcement and a strict CSP allow-list.

Attacks and evidence ​

All paths below are relative to the repository root. Test names identify individual assertions within the test files.

AttackDefense and ownerProof
Infinite loop inside a room tickpackages/rooms/src/server/host/WorkerRoomGame.ts:225 arms the parent watchdog on worker begin; failure terminates the worker. Production default is 3000 ms; the regression uses 250 ms.tests/security/room-guests.test.ts, contains loop and keeps an unrelated room alive: real compiled wasm, real room transport, victim closes with the deadline error; a separate worker room continues ticking and delivering frames.
Unbounded retained, touched allocations in a room tickpackages/wasm-host/src/sandbox.ts:307 clamps core wasm memory before compilation using packages/wasm-host/src/limitMemory.ts:13. The byte loader is required by packages/rooms/src/server/host/WorkerRoomGame.ts:58. Worker V8 heap limits (WorkerRoomGame.ts:92) supplement the wasm cap; V8 heap limits alone do not cap ArrayBuffers.tests/security/room-guests.test.ts, contains memory and keeps an unrelated room alive: 16 MiB blocks retained until the 64 MiB test guest cap refuses growth. Requires a memory/allocation error and a healthy unrelated room.
Flood of outbound messages in one tickpackages/rooms/src/server/host/authorityWorker.ts:166 now counts encoded bytes before copying and posting packets, throwing above the existing 8 MiB queue ceiling. packages/rooms/src/server/host/WorkerRoomGame.ts:253 separately caps packets pending main-thread consumption.tests/security/room-guests.test.ts, contains flood and keeps an unrelated room alive: guest sends 6000 individually valid messages, victim ends with the output queue error, unrelated room survives.
Oversized outbound message, including multibyte JSONpackages/sdk/src/net/NetFacade.ts:158 refuses payloads above 2048 UTF-8 bytes. Independently, packages/rooms/src/server/GameableWire.ts:95 refuses them even if a guest bypasses the SDK.tests/security/room-guests.test.ts, the compiled hostile game cannot send oversized messages to a client expects only the subsequent proof message; refuses oversized UTF-8 messages at the wire boundary even if a guest bypasses the SDK checks UTF-8 and exact JSON-size boundaries.
Infinite loop while evaluating settings declarationsAuthored evaluation is deferred until QuickJS init by packages/cli/src/lib/guestBuild.ts:305. deploy/game-api/worker.mjs:181 runs discovery with a 30000 ms process deadline; worker.mjs:57 kills the process group on Unix.tests/security/discovery.test.ts, refuses hostile settings evaluation: loop: builds the describe-only wasm guest and bundles the actual production discover-entry.mjs, runs it through runNode, requires timeout and absence of a result file.
Unbounded allocation while evaluating settings declarationsdeploy/game-api/discover-entry.mjs:12 supplies a 512 MiB memory cap and raw core bytes; the same wasm limiter applies inside a non-returning call. discover-entry.mjs:34 separately bounds completed settings JSON to 64 KiB.tests/security/discovery.test.ts, refuses hostile settings evaluation: memory: real describe-only wasm, touched retained allocations, requires memory/allocation failure rather than merely timeout, no result file. Both settings tests use production's 30-second execution deadline.
Node builtins, remote imports and requiredeploy/game-api/source-rules.mjs:231 rejects disallowed imports; source-rules.mjs:250 rejects require. Dynamic imports and escaped identifiers remain rejected. These are build admission rules.tests/security/source-rules.test.ts:8 covers the six import/require/escaped-identifier attacks in tests/security/fixtures/source-attacks.json. source-rules.test.ts:27 explicitly admits benign bindings and runtime calls named fetch, eval, Function and process.
Network, process exit, stdout and file writes from settings, including dynamic codeAuthored code runs in QuickJS inside the wasm guest, reached only through init (packages/cli/src/lib/guestBuild.ts:305, deploy/game-api/discover-entry.mjs:30). No Node process or fetch capability is provided. eval and Function remain confined to that guest. The fetch/eval/Function/process token ban has been removed; runtime isolation is the defense.tests/security/discovery.test.ts:56 builds tests/security/fixtures/settings-capabilities/src/game.ts:4 and runs the production discovery entry. Twelve direct/eval/Function attempts must report blocked; an HTTP listener must observe no connection, no marker file may exist, and the discovery child must complete without exit or host stdout effects. deploy/game-api/sandbox.test.mjs:473 retains the original harmless exit/write publish expectations.
Uploaded build configuration, lifecycle script, arbitrary dependencydeploy/build-service/policy.mjs:17 rejects package hooks and unapproved/nonexact dependencies; policy.mjs:162 refuses executable configuration. deploy/build-service/build.mjs:27 disables networking, limits memory/CPU/pids and drops privileges; build.mjs:81 bounds the build and build.mjs:100 forcibly removes its container.tests/security/build-policy.test.ts submits malicious file maps and asserts generated container flags. This checks policy, not an actual Docker sandbox. Existing deploy/build-service/policy.test.mjs additionally covers traversal, links and tar metadata.
Page-side reads of the play parent's cookies/localStorageexamples/play/src/iframeParent.ts:22 refuses same-origin frames and mounts the storage-origin frame; iframeParent.ts:26 sets the exact sandbox allow-list. Browser same-origin policy prevents cross-origin parent DOM/storage reads. allow-same-origin intentionally preserves the frame's own origin; it does not give the frame the parent's origin.tests/security/browser-isolation.test.ts, isolates page-side parent cookie/storage reads and top navigation by origin and sandbox policy, checks the mounted iframe and rejects same-origin embedding. The page-side attack corpus is tests/security/fixtures/parent-attacks.js. This is a policy assertion, not a browser execution test.
Top navigation or arbitrary parent instructionsThe sandbox at examples/play/src/iframeParent.ts:26 has no allow-top-navigation, allow-top-navigation-by-user-activation, popups or forms permission. iframeParent.ts:77 checks the exact sending window, origin and protocol using examples/play/src/frameProtocol.ts:29. Room route values have a restricted alphabet.tests/security/browser-isolation.test.ts checks the exact sandbox tokens and refuses forged parent protocol messages from another origin/window and unsafe room routes. window.parent itself and approved postMessage requests remain available.
Plugin embedding and hostile base URL changesNew baseline CSP in deploy/play/default.conf:32 and deploy/loader/default.conf:8: object-src 'none'; base-uri 'self', with always and nosniff. Play locations repeat CSP because local nginx add_header directives suppress inherited headers.tests/security/browser-isolation.test.ts, parameterized nginx policy tests read the actual configs and check every declared policy plus the play header override count. This does not verify proxy/CDN behavior or the storage service's response headers.

Changes made ​

  • Count room output inside the worker before packets cross the thread boundary. Reuses the existing 8 MiB limit; previously a single large frame could already have been transferred before the parent noticed queue overflow.
  • Remove the round 1 source-token ban and restore the original publish regression expectations. Legitimate games may define process() or loader.fetch. The runtime boundary is the defense: new compiled-guest tests exercise direct, eval and Function attempts at host capabilities without rejecting those identifiers.
  • Use platform temp directories and file URL imports in discovery/room tests; the browser test reads its fixture and the nginx configs from the repository root (under jsdom import.meta.url is not a file URL). Room regressions poll for observed termination and advancing frames with generous deadlines. The healthy and flood test workers get 30-second scheduling headroom; the loop test retains its 250 ms watchdog. Production deadlines are unchanged.
  • Add minimal CSP and nosniff to the loader, and repeat baseline CSP beside all play nginx header overrides. No host allow-list has been invented.

Validation in this environment ​

Host run, Windows, Node 22, 2026-11-02:

  • npx vitest run tests/security: 23 passed (5 files), including the compiled wasm room fixtures, the discovery loop/memory/capability fixtures and the browser policy checks.
  • npx vitest run tests/security packages/rooms: everything passes except packages/rooms/src/features.solo.test.ts > loads @gameable/net/client only, which passes alone and fails the same way on main under full-suite load (timing, not this change).
  • node --test deploy/game-api/sandbox.test.mjs deploy/game-api/source-rules.test.mjs: 92 passed, 0 failed. The boundary-mode publish tests need GAMEABLE_BOUNDARY=1 and are skipped by the plain suite.
  • Jenkins (Linux) runs the same suites on the push to main.

Open risks and required follow-up ​

  • Real-browser same-origin, cookie, storage and sandbox navigation enforcement has only been checked through configuration contracts. Execute the page attack corpus in a real browser against the deployed loader and storage origins. Neither jsdom nor these config checks proves enforcement by deployed servers.
  • The storage-origin frame.html is outside these nginx response paths. Verify its final response headers, redirects, MIME types and public hosting policy. The two origins must remain distinct after redirects. Same-origin frames are rejected at initial construction, but these tests do not exercise redirects.
  • The baseline CSP does not restrict scripts, connections, images, fonts, forms or frame ancestors. It does not stop fetch or prevent network exfiltration by arbitrary page JavaScript. A full policy requires a decision on approved storage, room, API, character, font and media endpoints, plus compatibility testing with wasm/WebGPU. Play pages load wasm, splats and characters from storage hosts; a wrong strict allow-list breaks every game. Keep the baseline headers for now and leave that allow-list as an explicit open risk. Source admission is not a replacement for that policy.
  • Cross-origin isolation protects parent storage, not the frame's own cookies or storage. All games sharing one storage origin share that origin's capabilities. Keep credentials and sensitive state off that origin. Parent-domain cookies require special scrutiny: a broad cookie Domain can expose them to sibling hosts.
  • Runtime isolation is the defense against host effects, including dynamic code. The new fixture checks a finite set of direct, eval and Function attacks in the discovery wasm guest, not a general sandbox-escape proof or dependency audit. It does not validate arbitrary page JavaScript or browser networking restrictions.
  • Room output below 8 MiB per frame can still consume substantial bandwidth and fan-out resources; there is no new per-game messages-per-second quota. Single packet encoding and guest-output decoding allocate before the byte counter. A huge individual message name or non-message command may cause worker memory pressure before that check; worker termination is the fallback. The test proves one finite flood, not sustainable process-RSS or aggregate capacity bounds.
  • Wasm caps apply per core memory before compilation, with aggregate accounting after calls. These fixtures stress the QuickJS heap, not every multi-memory or native/Jolt allocation path. V8 heap limits do not bound total process RSS.
  • Browser games run synchronously on their frame's main thread. A page watchdog cannot interrupt an infinite loop (examples/play/src/pageWatchdog.ts:1). The parent heartbeat timeout (iframeParent.ts:169) depends on parent scheduling; separate origins do not by themselves guarantee separate OS processes. Actual hostile browser CPU/GPU/memory exhaustion remains unverified.
  • Settings process-group termination was written for Unix; the Windows fallback kills the immediate child. Neither Docker enforcement nor Windows termination was executed here. The API build subprocess permits build-time workers/addons and child processes; reviewed source/config admission is essential, and those permissions are not equivalent to the build-service container's no-network namespace. No claim of a universal OS sandbox is made.