Docs / SECURITY-REVIEW
Security Review — Game Composer (Item 159 / H8)
Source: docs/SECURITY-REVIEW.md
Reviewer: security worker. Date: 2026-11-27.
Ownership: this file is the only file written in this worktree. Read-only review; no source edits, no push, no merge, no deploy.
Scope and method
Reviewed the implementation actually present in integration/2026-11-27-gamecomposer-main, not the earlier contract-only documents:
| Area | Files reviewed |
|---|---|
| Browser player servers | examples/nes/image/serve.py, examples/snes/image/serve.py |
| Player pages / save flow | examples/nes/image/player.html, examples/snes/image/player.html |
| Images and manifests | examples/*/image/Dockerfile, examples/*/gamecomposer.yml, gamecomposer.yml |
| Checkpoint storage | examples/nes/image/serve.py:13-14,17-34, gamecomposer/runtime.py:178-186,315-330 |
| Path traversal / path normalization | gamecomposer/core.py:41-87, gamecomposer/runtime.py:95-111,114-157,249-257 |
| YAML parsing | gamecomposer/core.py:14-38,137-177 |
| Host API | gamecomposer/api.py, gamecomposer/cli.py, gamecomposer/sdk.py, gamecomposer/desktop.py |
| Validation contract | specs/game-compose.schema.json, gamecomposer/game-compose.schema.json (symlink) |
Method: static reading plus read-only Python probes of gamecomposer.core._yaml_load, run from this worktree without writing to it. The probes confirmed the YAML alias and key-handling behaviour reported in S4–S7. No containers were started and no network exploit was attempted.
Threat model used. A manifest is operator-supplied configuration, but the desktop app (gamecomposer/desktop.py:63-72) lets a user open any YAML/JSON file, so parsing must survive hostile input. The reference runtime publishes the player to 127.0.0.1 only (gamecomposer/runtime.py:311-312), but the images bind 0.0.0.0:8080 (examples/*/image/serve.py:52,36) and can be run outside that manifest. Save/checkpoint data is treated as untrusted because it is written by an HTTP endpoint and read back into the emulator.
Bottom line
No High-severity issue reachable from the reference loopback-only deployment was found. Five Medium, six Low and two Informational issues are documented below. The strongest concerns are (1) a checkpoint write endpoint with CSRF-style checks but no authentication, (2) YAML alias expansion that can hang the host parser before schema validation, and (3) unguarded URL fetching in the runtime. Path traversal is handled well: GET routes are exact-match and project paths are resolved and containment-checked with symlinks followed.
Findings
| ID | Severity | File:line | Finding |
|---|---|---|---|
| S1 | Medium | examples/nes/image/serve.py:17-34 |
Checkpoint POST has no authentication; the header/Origin checks stop browsers but not any local or network client. |
| S2 | Medium | examples/nes/image/serve.py:13-14,26-32; examples/nes/image/player.html:20-22 |
Stored checkpoint bytes are never validated; arbitrary content is fed to nes.fromJSON() on load. |
| S3 | Medium | examples/nes/image/serve.py:18-19 |
Origin validation trusts the request-supplied Host header and has no Sec-Fetch-Site or fixed allowlist. |
| S4 | Medium | gamecomposer/core.py:14-38,175; gamecomposer/api.py:13 |
YAML aliases allow cyclic graphs and exponential expansion before schema validation (verified). |
| S5 | Medium | gamecomposer/runtime.py:118-157 |
URL asset download follows redirects to arbitrary hosts; no SSRF guard, digest is manifest-declared. |
| S6 | Low | gamecomposer/core.py:23-30,34; gamecomposer/cli.py:21 |
Unhashable YAML key raises raw TypeError, not ManifestError, and escapes the CLI handler (verified). |
| S7 | Low | gamecomposer/core.py:23-32 |
Custom mapping constructor skips PyYAML flatten_mapping; YAML merge keys fail as "invalid YAML" (verified). |
| S8 | Low | examples/nes/image/serve.py:52, examples/snes/image/serve.py:36 |
Both servers bind 0.0.0.0:8080 with unbounded threads and no request timeout or rate limit. |
| S9 | Low | examples/nes/image/serve.py:46-49 |
NES responses lack X-Content-Type-Options: nosniff (present in the SNES server) and any CSP. |
| S10 | Low | examples/nes/image/serve.py:22-29 |
Excess POST body bytes beyond Content-Length are left unread; safe only while HTTP/1.0 is default. |
| S11 | Low | gamecomposer/core.py:41-56; gamecomposer/runtime.py:101-111,241 |
Path validation and use are separated by a TOCTOU window; runtime re-validates, which narrows but does not close it. |
| S12 | Info | gamecomposer/api.py:13; gamecomposer/cli.py:16; gamecomposer/desktop.py:159,182 |
config output echoes all declared environment.env values to stdout, logs and the desktop UI. |
| S13 | Info | examples/snes/image/player.html:28; examples/snes/gamecomposer.yml:21-23 |
EmulatorJS data/core files load from a CDN at runtime; only loader.js is pinned by sha256. |
S1 — Checkpoint POST has no authentication (Medium)
examples/nes/image/serve.py:17-21 gates writes on three conditions: exact path, X-Game-Composer: checkpoint, and Origin == "http://" + Host. These are browser CSRF defences, not authorization. Any non-browser client can satisfy all three:
curl -X POST -H 'X-Game-Composer: checkpoint' -H "Origin: http://127.0.0.1:PORT" \
--data-binary @payload http://127.0.0.1:PORT/checkpoint
examples/nes/image/serve.py:30-32 then replaces /gamecomposer/saves/checkpoint.json with those bytes. On a shared host any local process/user can do this; if the port is forwarded or the image is run with a LAN publish instead of the manifest's loopback publish, any network client can. Impact: silent destruction or poisoning of persistent save data. Recommendation: treat the write as privileged — authenticate it (per-session token/credential passed to the player), or at minimum bind the server to loopback and enforce OS-level access control; add a dedicated CSRF token and reject unexpected methods explicitly.
S2 — Checkpoint content is stored and replayed without validation (Medium)
examples/nes/image/serve.py:22-26 accepts any 1–4,000,000 byte body and writes it verbatim. examples/nes/image/serve.py:14 exposes the same file at GET /checkpoint as application/json, and examples/nes/image/player.html:20-22 passes the parsed JSON straight into player.nes.fromJSON(). There is no structural check at write time, at read time, or in the browser. Combined with S1 (or direct access to the host save directory), an attacker can plant malformed state that crashes the player or steers emulator deserialization. Recommendation: validate the checkpoint against an explicit schema on POST, bound the file on GET, and defend fromJSON() with a try/catch that discards invalid state rather than applying partially parsed data.
S3 — Origin check trusts attacker-controlled Host (Medium)
examples/nes/image/serve.py:19 builds the allowed origin from the request's own Host header. There is no fixed allowlist and no Sec-Fetch-Site: same-origin check, so a DNS-rebinding page whose name resolves to the player address produces matching Origin and Host values. Cross-origin fetch is currently stopped only because X-Game-Composer triggers a CORS preflight that the server does not implement (examples/nes/image/serve.py:16 defines only do_POST and do_GET, so OPTIONS returns 501) — an incidental barrier, not the stated one. Recommendation: compare Origin to a configured literal origin, require Sec-Fetch-Site: same-origin, and explicitly reject OPTIONS; keep the custom header as defence in depth.
S4 — YAML aliases permit cycles and exponential expansion (Medium)
gamecomposer/core.py:34 calls yaml.load(..., Loader=SafeLoader subclass). SafeLoader prevents arbitrary object construction but does not prevent aliases. Read-only probes confirmed:
a: &x [*x]loads as a self-referential list (d['a'][0] is d['a']→True).- Nested aliases such as
&a [9 items],&b [9 × *a],&c [9 × *b]expand exponentially when serialised (four levels already produced ~34 KB from a ~120-byte document).
gamecomposer/core.py:175 validates the loaded document with jsonschema.iter_errors, and gamecomposer/api.py:13 calls json.dumps on it; either will recurse or expand on such input, producing RecursionError, a hang, or memory exhaustion in the CLI/desktop before ManifestError can be raised. Recommendation: reject alias nodes in the custom loader (track AliasEvent / node anchors), cap document size and nesting depth, and catch RecursionError as a malformed manifest.
S5 — Unrestricted URL fetch / SSRF in the runtime (Medium)
gamecomposer/core.py:66-70 correctly requires https:// with no embedded credentials, but imposes no host restriction. gamecomposer/runtime.py:129-134 calls urllib.request.urlopen(request, timeout=30) on that URL; redirects are followed by default. A hostile or mistyped manifest can therefore target loopback, RFC1918, or link-local addresses (e.g. 169.254.169.254 cloud metadata) and have the response cached (:124-148) and mounted into the container as emulator/game source (:249-257). The sha256 check at :125,145 only verifies bytes against the manifest-declared digest, so it does not constrain where the bytes came from. Impact: SSRF from the developer host; in a cloud/CI context this could expose metadata credentials. Recommendation: resolve and allowlist destination hosts/IPs, reject loopback/link-private ranges, disable redirects (or re-validate each redirect target), and cap redirects and response size before hashing. Rate this High if manifests are ever accepted from untrusted tenants.
S6 — Unhashable YAML key escapes error handling (Low)
The duplicate-key constructor at gamecomposer/core.py:23-30 calls loader.construct_object(key_node) and uses the result as a dict key. A YAML key such as ? [a, b] produces TypeError: cannot use 'list' as a dict key (verified), which _yaml_load does not wrap and gamecomposer/cli.py:21 does not catch (ValueError, OSError, RuntimeError only), yielding an unhandled traceback. Recommendation: require scalar keys, raise ManifestError for anything else, and catch TypeError/RecursionError at the load() boundary.
S7 — Merge keys unsupported by the custom loader (Low)
gamecomposer/core.py:23-32 replaces construct_yaml_map with a loop over node.value and never calls PyYAML's flatten_mapping. A manifest using <<: *anchor fails with ManifestError: invalid YAML: could not determine a constructor for the tag 'tag:yaml.org,2002:merge' (verified). The failure is safe (fail closed), but users may work around it by duplicating keys, which the duplicate detection then rejects. Recommendation: call loader.flatten_mapping(node) before iterating, while keeping the duplicate-key check on the flattened result.
S8 — Public bind and unbounded request threads (Low)
examples/nes/image/serve.py:52 and examples/snes/image/serve.py:36 bind 0.0.0.0:8080. ThreadingHTTPServer creates one thread per connection with no timeout, keep-alive limit, or rate limiting. If the container is run with a broad port publish, a client can hold connections open and exhaust threads/memory. The reference manifest avoids this by publishing to 127.0.0.1 (gamecomposer/runtime.py:311-312). Recommendation: bind the example servers to 127.0.0.1 by default and set a short socket timeout; document that any wider publish exposes an unauthenticated endpoint (S1).
S9 — Missing response hardening on the NES server (Low)
examples/nes/image/serve.py:46-49 sets Content-Type and Content-Length only. The SNES server adds X-Content-Type-Options: nosniff at examples/snes/image/serve.py:31; the NES server does not, even though it serves attacker-writable checkpoint bytes (S2) and a downloaded JS file. Neither server sets a Content Security Policy. Recommendation: add nosniff, Content-Disposition: attachment for /checkpoint, and a restrictive CSP to the player page; make both servers consistent.
S10 — Unread request-body remainder (Low)
examples/nes/image/serve.py:22-29 reads exactly Content-Length bytes. If the client sends more, the remainder stays in the socket buffer. With the default protocol_version = "HTTP/1.0" the connection is closed after the response, so this is not currently request smuggling; it becomes one if HTTP/1.1 keep-alive is ever enabled. Recommendation: drain or explicitly close the connection, and pin protocol_version with a comment explaining the constraint.
S11 — Validation/use TOCTOU on project paths (Low)
gamecomposer/core.py:41-56 resolves paths and checks containment at load() time; gamecomposer/runtime.py:101-111 re-checks at use time (:116,241,250). That is good defence, but an attacker with write access to the project directory can still swap a symlink between the final resolve() and the Kiri --mount at :326-329. Recommendation: open descriptors against the resolved target and mount via /proc/self/fd where possible, or document that the project tree must not be writable by untrusted principals during up.
S12 — Manifest secrets echoed to users (Info)
gamecomposer/api.py:13 serialises the whole selected service, including environment.env, into the config result; gamecomposer/cli.py:16 prints it and gamecomposer/desktop.py:159,182 displays it. Any secret placed in a manifest is copied to terminal scrollback, logs and screenshots. Recommendation: redact env values in config output, or support secret references resolved only at runtime.
S13 — Unpinned runtime CDN assets in the SNES player (Info)
examples/snes/gamecomposer.yml:21-23 pins only loader.js. examples/snes/image/player.html:28 sets EJS_pathtodata to https://cdn.emulatorjs.org/4.2.3/data/, from which the loader fetches core/data files at page load with no checksum enforcement. Recommendation: mirror those assets into the image or pin each file by hash, matching the discipline already applied to the NES emulator source.
What is done well
- No URL path traversal in either server.
examples/nes/image/serve.py:37andexamples/snes/image/serve.py:19use exact dictionary lookups onself.path;.., encoded separators and absolute-form URLs all 404 rather than reaching the filesystem. - Checkpoint writes are atomic and bounded.
examples/nes/image/serve.py:23-32enforces a 1–4 MBContent-Length, usesNamedTemporaryFilein the target directory andos.replace(0600 temp permissions), so readers never see a partial file. - Safe YAML loader with duplicate-key detection.
gamecomposer/core.py:14-38usesSafeLoader(no!!python/object), rejects duplicate keys, and wrapsYAMLErrorinManifestError. - Strong project-path containment.
gamecomposer/core.py:41-56requires./, rejects absolute/parent components, follows symlinks withresolve()and appliesrelative_to(root);gamecomposer/runtime.py:101-111repeats the check, and:168-175rejects commas/newlines in Kiri mount specs. - No shell injection. All Kiri calls use
subprocess.runwith argument lists (gamecomposer/runtime.py:51-63), service names are regex-validated (:28,95-98), and environment keys/values are validated before use (:322-325). - Integrity checks on downloaded assets. Downloaded bytes are SHA-256 verified and size-capped before being cached (
gamecomposer/runtime.py:125-148). - Fail-closed capability checks. Non-Linux guests, unsupported network modes and browser players without a bridge network are rejected before launch (
gamecomposer/runtime.py:210-227).
Suggested gate before a "security-reviewed" claim
- Fix S1–S3 together: authenticate/authorise checkpoint writes, validate checkpoint content, and replace the
Host-derived origin check. - Fix S4 and S5: reject YAML aliases/cyclic graphs before validation; add host allowlists and redirect controls to asset fetches.
- Align the two example servers on
127.0.0.1binding and security headers (S8, S9). - Resolve S6/S7 in the loader and add malformed-manifest regression tests, including a cyclic alias and a merge-key manifest.
This review is static analysis only. It does not assert playability, runtime correctness, or that the Kiri backend enforces the isolation the manifest declares.

