Docs / SECURITY-REVIEW-GC3

Security Review — Game Composer

Source: docs/SECURITY-REVIEW-GC3.md

Reviewer: security worker (Orca dispatch task_f9122ad15400)
Date: 2026-11-27
Ownership: docs/SECURITY-REVIEW.md is the only file authored in this worktree. No source edits, no push, no merge, no deploy.
Method: read-only static review of the files listed below. No dynamic testing, no exploit execution, no running containers. Line numbers refer to the reviewed checkout (commit 321e188).

Scope

Area Files reviewed
Player server / checkpoint examples/nes/image/serve.py, examples/snes/image/serve.py, examples/nes/image/player.html, examples/snes/image/player.html
Path traversal gamecomposer/core.py, gamecomposer/runtime.py, gamecomposer/api.py
YAML / schema gamecomposer/core.py, specs/game-compose.schema.json, gamecomposer/game-compose.schema.json (symlink), gamecomposer.yml, examples/*/gamecomposer.yml
gamecomposer/ API gamecomposer/__init__.py, api.py, cli.py, sdk.py, desktop.py (plus desktop/src/main.cjs, preload.cjs as adjacent surface)

Summary

No Critical or High findings. Twelve findings are recorded: 3 Medium, 8 Low, 1 Informational. The code is unusually disciplined: YAML uses SafeLoader with duplicate-key rejection, filesystem paths are constrained with resolve() + relative_to(), URL assets are SHA-256 pinned and size-capped, subprocesses use argument lists rather than shells, and the HTTP route tables use exact-match lookups that do not permit traversal. The most material issue is that the NES checkpoint endpoint's cross-origin check derives the trusted origin from the attacker-controlled Host header, so DNS rebinding can read and overwrite save data.

Severity reflects impact in the intended deployment (a loopback-published, single-user local player). Reusing the same images with a network-facing port mapping raises several Low items to Medium/High.

Findings

S1 — Medium — NES checkpoint origin check is trivially defeated by DNS rebinding

examples/nes/image/serve.py:18-19

if (self.path != "/checkpoint" or self.headers.get("X-Game-Composer") != "checkpoint"
        or self.headers.get("Origin") != "http://" + self.headers.get("Host", "")):

The "allowed" origin is constructed from the request's own Host header. A page served from an attacker domain that is rebound to 127.0.0.1 sends Host: evil.example:<port> and Origin: http://evil.example:<port>; both match, so the check passes and the attacker can POST arbitrary save data. The X-Game-Composer header is a static value the attacker's script can set, so it adds no authentication. The sibling GET route is even less protected: /checkpoint is a normal entry in the public route table (examples/nes/image/serve.py:13-14, :36-50) with no origin check at all, so a rebound same-origin page can read the current save state.

Impact: disclosure and integrity loss of checkpoint/save data (game progress), reachable from a malicious web page without user credentials. No host code execution.

Recommendation: compare Origin against a fixed allowlist (http://127.0.0.1:<port>, http://localhost:<port>) and reject unexpected Host values; require a per-session unguessable token or SameSite cookie for /checkpoint; add GET /checkpoint to the same protection; bind to loopback (see S7).

S2 — Medium — Checkpoint writes accept arbitrary bytes with no validation, quota, or rate limit

examples/nes/image/serve.py:22-32

The POST handler enforces only a per-request Content-Length between 1 and 4,000,000 bytes (:23). It does not validate that the body is JSON, that it matches the emulator state shape, or that the mounted save volume has room. Every accepted request performs a NamedTemporaryFile write and an atomic replace into the single fixed path /gamecomposer/saves/checkpoint.json (:13, :30-32). Repeated large POSTs can fill the host-side saves bind mount, and arbitrary bytes can corrupt the save so that player.nes.fromJSON() fails on the next load (examples/nes/image/player.html:22).

Impact: host-volume exhaustion (availability) and persistent save corruption (integrity). Reachable via S1 or by any local/network client that can reach the port.

Recommendation: validate JSON and a bounded state schema before writing; enforce a total size quota and rate limit; flush() + os.fsync() before replace for durability; clean up the temp file with try/finally if replace fails.

S3 — Medium — An untrusted manifest is effectively code: arbitrary container command plus writable host mounts

gamecomposer/runtime.py:288-291, :326-329, :178-186

command and args from the manifest are passed verbatim into the container command vector (:288-291) — only NUL bytes and non-string types are rejected. The host saves and writable directories are bind-mounted read-write (:328-329) after being created with default umask permissions (:184-185). A manifest obtained from an untrusted source therefore controls what runs inside the container and can write arbitrary files into two host directories under the project root. The schema correctly pins the emulator/game assets by SHA-256, but it does not constrain the command.

Impact: host filesystem writes bounded to the project's saves/user directories, plus arbitrary in-container execution, when a user runs up on a manifest they did not author. This is a trust-boundary issue, not a bug in the adapter itself.

Recommendation: document manifests as executable/trusted input; review manifests before up; avoid running up on untrusted repositories; consider read-only mounts for untrusted projects and an explicit allowlist of container entrypoints.

S4 — Low — Kiri executable is resolved from PATH without pinning

gamecomposer/runtime.py:36-48

_kiri() prefers shutil.which("kiri") and only falls back to fixed absolute paths when that fails. Any executable named kiri earlier in a user's PATH is invoked with the user's privileges for every up, logs, stop, and down operation (:51-63).

Impact: local binary planting leads to arbitrary code execution at the invoking user's privilege. Requires local write access to a directory on PATH or a compromised shell environment.

Recommendation: make the Kiri path an explicit configuration value, prefer the pinned absolute candidates over PATH, and optionally verify a known signature/hash.

S5 — Low — SSRF via URL sources; format: uri in the schema is not enforced

gamecomposer/core.py:66-70, gamecomposer/runtime.py:118-134, specs/game-compose.schema.json:51

_normalize_source requires an HTTPS URL without embedded credentials and a SHA-256 pin, but permits any host, including loopback, RFC1918, and link-local addresses (https://127.0.0.1/..., https://169.254.169.254/...). On up, _source_path actually fetches the URL (:129-134). SHA-256 verification prevents substituting the downloaded bytes but does not prevent the request itself. The schema's "format": "uri" is not enforced because Draft202012Validator is constructed without a FormatChecker (gamecomposer/core.py:160-164); only the ^https:// pattern is enforced.

Impact: a manifest from an untrusted source can induce the host to make HTTPS requests to internal services (SSRF). Response bodies are hash-checked and only written on match, limiting data return.

Recommendation: resolve and block loopback/private/link-local destinations, allowlist allowed download hosts, pass format_checker=jsonschema.FormatChecker(), and keep redirects from downgrading or crossing into private ranges.

S6 — Low — Unbounded YAML alias expansion; JSON path skips duplicate-key rejection

gamecomposer/core.py:14-38, :146-150

_yaml_load correctly subclasses yaml.SafeLoader (:20), but PyYAML's loader expands anchors/aliases without a size or depth bound, so a crafted local manifest can exhaust host memory during yaml.load() (:34). Separately, duplicate YAML keys are rejected by the custom mapping constructor (:23-30), but the JSON branch uses plain json.loads (:148), where duplicate keys silently resolve last-wins — an inconsistency that could hide a conflicting field from review.

Impact: local denial of service during manifest load; inconsistent validation depending on file suffix.

Recommendation: reject alias nodes or cap expansion/document size before parsing; apply the same duplicate-key detection to JSON (e.g., object_pairs_hook).

S7 — Low — Player servers bind all interfaces with no authentication

examples/nes/image/serve.py:52, examples/snes/image/serve.py:36

Both servers call ThreadingHTTPServer(("0.0.0.0", 8080), ...) and serve the player, ROM, and (for NES) checkpoint with no authentication. In the supported path this is contained by the host-side loopback publish (gamecomposer/runtime.py:311-312), but running the images directly with -p 8080:8080 exposes an unauthenticated player and checkpoint read/write endpoint on the network.

Impact: exposure increases with S1/S2; default posture is unsafe outside the adapter.

Recommendation: bind 127.0.0.1 by default and only opt into 0.0.0.0 with explicit authentication, or require the adapter's loopback publish.

S8 — Low — Missing response hardening headers on the NES server

examples/nes/image/serve.py:36-50, :46-49 (compare examples/snes/image/serve.py:28-33)

The SNES server sends X-Content-Type-Options: nosniff (examples/snes/image/serve.py:31); the NES server does not. Neither server sets a Content Security Policy, and /checkpoint responses have no Cache-Control: no-store (the player mitigates client-side with cache:'no-store' at examples/nes/image/player.html:20). The NES server also emits Python's default Server header via BaseHTTPRequestHandler.send_error.

Impact: MIME-sniffing and caching edge cases; minor version information disclosure.

Recommendation: add X-Content-Type-Options: nosniff, a restrictive CSP, Cache-Control: no-store on /checkpoint, and suppress/override the Server header.

S9 — Low — No socket timeouts or connection limits on the HTTP servers

examples/nes/image/serve.py:52, examples/snes/image/serve.py:36

ThreadingHTTPServer spawns a thread per connection and BaseHTTPRequestHandler sets no read timeout. A client that opens connections and sends nothing can consume threads and file descriptors indefinitely.

Impact: local or network denial of service.

Recommendation: set a socket timeout, cap concurrent threads, and enable daemon_threads (already true for ThreadingHTTPServer, but not a connection cap).

S10 — Low — Checkpoint temp file can be orphaned and is not fsynced

examples/nes/image/serve.py:30-32

NamedTemporaryFile(..., delete=False) writes the body and immediately calls replace(). If replace fails (disk error, permission change, process kill between the two calls), the temp file remains in the saves directory. There is no flush()/fsync() before the atomic swap, so a crash can lose an acknowledged save.

Impact: disk clutter and durability loss; low severity because acknowledged writes are normally atomic.

Recommendation: wrap creation and replace in try/finally with cleanup, and flush() + os.fsync() the temp file before replace.

S11 — Low — Path normalization has no exploitable traversal, but leaves local TOCTOU / platform-ambiguity residue

gamecomposer/core.py:41-56, gamecomposer/runtime.py:101-111, :114-127

No path-traversal vulnerability was found. _resolve_project_path requires a ./ prefix, rejects absolute paths and .. components (:42-46), then follows with resolve() + relative_to(root) (:47-52). _safe_project_path independently repeats the resolve() + relative_to boundary check (runtime.py:105-110), and URL-derived filenames reject /, \, \0, and ./.. after unquote (:121-123). The HTTP layer is safe by construction: both servers use exact dictionary membership on self.path (serve.py:37-40 NES, :19-22 SNES), so query strings or ../ segments simply 404.

Residual issues: (a) PurePosixPath does not treat \ as a separator, so on a Windows host a value such as ./..\secret survives the component filter and is only caught by the later relative_to check — correct today, but the two-layer defense is platform-dependent; (b) paths are resolved at validation time and re-resolved at mount time, leaving a symlink-swap TOCTOU window for a local attacker with write access to the project directory.

Impact: no direct exploit; hardening gap.

Recommendation: re-validate immediately before mount, use a single canonical boundary check (os.path.commonpath) on all platforms, and avoid following symlinks for project-controlled paths.

S12 — Informational — URL opened via webbrowser.open originates from Kiri output

gamecomposer/cli.py:18-20, gamecomposer/desktop.py:183-186, gamecomposer/runtime.py:200-207

_url() builds http://127.0.0.1:<HostPort>/ from kiri inspect output, and the CLI/desktop hand the first such line to webbrowser.open. The scheme and host are hardcoded, so a crafted HostPort cannot change the scheme, but a compromised or mocked Kiri binary (see S4) controls the port value.

Impact: negligible in the normal path; note as a trust boundary.

Recommendation: validate HostPort as a decimal 1–65535 before use.

Controls observed working

  • No HTTP path traversal: exact-match route lookup — examples/nes/image/serve.py:37-40, examples/snes/image/serve.py:19-22.
  • Safe YAML parsing: SafeLoader subclass plus duplicate-key rejection — gamecomposer/core.py:20-34.
  • Constrained project paths: ./ requirement, component rejection, resolve() + relative_to() — gamecomposer/core.py:41-56; independent re-check — gamecomposer/runtime.py:101-111.
  • Pinned remote assets: HTTPS-only without embedded credentials, SHA-256 required (core.py:66-70), verified with a byte cap (runtime.py:118-157); example manifests follow the practice (gamecomposer.yml:21-23, :32-34).
  • Strict schema: additionalProperties: false throughout, projectPath and 64-hex sha256 patterns, integer port bounds — specs/game-compose.schema.json:7, :35-37, :48-53, :167; schema is loaded through a package-local symlink with error handling — gamecomposer/core.py:156-168.
  • Injection guards: Kiri mount spec rejects ,, CR, LF (runtime.py:168-175); env keys/values regex-checked (:322-325); service names allowlisted (:28, :95-99).
  • No shell execution: subprocess.run with argument lists and timeouts — gamecomposer/runtime.py:51-63.
  • Action allowlist: gamecomposer/api.py:14-15.
  • Hardened Electron shell: contextIsolation: true, nodeIntegration: false — desktop/src/main.cjs:12-16; no privileged APIs exposed by the preload beyond a fixed adapter — desktop/src/preload.cjs:8-12.

Limitations

  • Static review only; no dynamic verification, no Kiri interaction, no HTTP requests, no container execution.
  • Findings assume the intended loopback-published deployment; exposing port 8080 directly to a network changes risk materially.
  • No source files were modified. Recommendations are advisory, not applied.

Back to all docs