diff --git a/docs/DESIGN.md b/docs/DESIGN.md index 35df6dd..4bcf6a8 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -1,6 +1,6 @@ # FFF_vtt design -Status: draft v0.7, 2026-11-10 (owner decisions recorded in section 14; v0.4 records Q4 (tile_size 32 px), the outbox lock invariant (4.2, 4.3), and the follow-ups in 3.4, 8, 11.1, 12, 13; v0.5 records the M2 move-rule decisions in 5.5 and updates 3.4, 4.2, 5.1, 5.4, 6.1, 7.4, 8, 10.3, 12, 13; v0.6 records #14 (characters and player data) in 3.1, 3.4, 4.1, 4.4, 6.1, 8, 9, 10.3, 13, 14; v0.7 records #6 (players and invites) in 3.1, 3.2, 3.4, 4.4, 6.1, 8, 12, 13, 14. All of Q1-Q24 are RESOLVED or DEFERRED; none OPEN). Audience: the owner and coding agents. +Status: draft v0.8, 2026-11-14 (owner decisions recorded in section 14; v0.4 records Q4 (tile_size 32 px), the outbox lock invariant (4.2, 4.3), and the follow-ups in 3.4, 8, 11.1, 12, 13; v0.5 records the M2 move-rule decisions in 5.5 and updates 3.4, 4.2, 5.1, 5.4, 6.1, 7.4, 8, 10.3, 12, 13; v0.6 records #14 (characters and player data) in 3.1, 3.4, 4.1, 4.4, 6.1, 8, 9, 10.3, 13, 14; v0.7 records #6 (players and invites) in 3.1, 3.2, 3.4, 4.4, 6.1, 8, 12, 13, 14; v0.8 records #7 (map tiles) in 3.3, 3.4, 11.1, 13, 14. All of Q1-Q24 are RESOLVED or DEFERRED; none OPEN). Audience: the owner and coding agents. Legend: - **[FIXED]** owner decision, not up for debate here. @@ -139,12 +139,12 @@ Notes: - Rejected: env/config seed (secret leaks via config, repo, backups); auto-print at startup (secrets in logs); first visitor claims GM (takeover); rotate on every lookup (logs out GM devices); live rotation while the server runs (needs an admin channel to the running server). ### 3.3 Tiles -- Browser asks `GET /tiles//_.png` (Nim path). Nim parses strictly (digits only, length-bounded, range-checked against scene size), checks the session's explored grid, and answers `200` with `X-Accel-Redirect: /_tiles/...` or `403`. nginx serves the bytes from an `internal` location; direct hits on `/_tiles/` give 404 [MEASURED: `prototype-server-vision/results/smoke.log`, README "Phase 2a"]. +- Browser asks `GET /tiles//v/_.png` (Nim path). Nim parses strictly (digits only, length-bounded, range-checked against scene size; malformed or out-of-range -> `404`), checks the session's explored grid (the explored-area logic of 5.1), and answers `200` with `X-Accel-Redirect: /_tiles//v/_.png`, or `403` if unexplored [FIXED, owner decision 2026-11-14, #7]. nginx serves the bytes from an `internal` location; direct hits on `/_tiles/` give 404 [MEASURED: `prototype-server-vision/results/smoke.log`, README "Phase 2a"]. - GM is always allowed. - Rule: a tile is allowed iff at least one explored cell of that player overlaps it [MEASURED semantics: leak test (d), 9984 + 7424 requests, 0 failures, `results/leak-A.log`, `results/leak-B.log`]. - **Residual tile-edge leak (accepted for v1, documented) [FIXED, Q4]:** a tile is the unit of disclosure. v1 sets `tile_size` = explored cell = 32 px (section 8), tile grid origin = world origin, so a tile is allowed iff its one cell is explored. The residual is the whole 32 px cell that a vision polygon grazed, including art the LOS did not actually see. Once revealed it is never revoked. No server-side masking is built [FIXED, Q4]. Static art only: door state is never in tiles. Consequences for map authors: do not paint secrets (secret doors, hidden traps, notes) in map art within ~32 px of areas players can reach; keep secrets as GM-only entities. Evidence: `prototype-tile-leak/README.md` (desktop numbers; phone run 2026-11-08). Fallback if the M4 gates fail: `tile_size` 64 px (per-scene config, no code change; leak <= 3 cells per allowed tile, 4x fewer files). - A second consequence: map art itself may depict walls/doors. Art is "what players see once there", walls data is "what physics/vision uses". Authoring must keep them consistent; mismatch is GM error, not a leak. -- Tile URLs include a scene version so that re-imported art does not hit stale caches [PROPOSED]; response `Cache-Control: private`. +- Tile URLs include the scene's `art_version` so that re-imported art does not hit stale caches [FIXED, owner decision 2026-11-14, #7]: from M3 on, always `1` in M3. The gate reads `/tiles//v/` (layout fixed in M3; writing versions and cleanup are M6, 11.1). Response `Cache-Control: private` [FIXED, owner decision 2026-11-14, #7], not the prototype's `no-store`. ### 3.4 Threat list @@ -153,7 +153,7 @@ Notes: | T1 | Player reads hidden token/entity/prop from WS | view builder filters by LOS, `gm_only`, bucket; single egress | leak test + fault classes | | T2 | Player reads wall/door data | walls only in GM view | fault `walls` [MEASURED caught] | | T3 | Player reads other player's vision/explored/ownership | per-player view only | faults `other-*` [MEASURED caught] | -| T4 | Player fetches unexplored tiles | Nim gate + internal nginx location | leak (d), smoke steal check | +| T4 | Player fetches unexplored tiles | Nim gate + internal nginx location | leak (d) against the independent oracle, smoke steal check, direct `/_tiles/` -> 404 (M3 test nginx) | | T5 | Tile-edge over-disclosure: one 32 px cell grazed by vision, never revoked | tile_size = explored cell = 32 px, no server masking, authoring rule ~32 px (Q4 FIXED) | documented, not testable as a leak; M4 timing gates (13) | | T6 | Player key / session theft via logs, referrer, history | key in POST body, never in URL; session != key (hash stored); log redaction; no-referrer on sign-in; HTTPS only | config test (grep logs for secret) [new] | | T7 | Cross-site WS hijack | Origin check + SameSite=Strict | new test | @@ -540,7 +540,7 @@ Principles carried from the prototype: the checker must be independent of the co - Response headers: HSTS, CSP (no inline scripts, `connect-src 'self'` wss), `X-Content-Type-Options`, `Referrer-Policy`. - No `limit_req` on `/join` (owner, #6: no rate limit on key entry; ~100-bit key space). - Prototype nginx config (`prototype-server-vision/nginx/nginx.conf`) is the functional reference; its `listen` has no address (binds all) and its temp/log paths are dev-only. -- Map import: offline CLI that slices an image into `tile_size` PNG/WebP tiles into `/tiles///` and registers/updates the scene (prototype: `tools/genmap.mjs`, deterministic, hand-authored, not reusable as the importer). Browser upload is post-v1; CLI-only import in v1 (Q5 FIXED). +- Map import: offline CLI that slices an image into `tile_size` PNG/WebP tiles into `/tiles//v/` and registers/updates the scene (prototype: `tools/genmap.mjs`, deterministic, hand-authored, not reusable as the importer). Browser upload is post-v1; CLI-only import in v1 (Q5 FIXED). ### 11.2 Backups [PROPOSED] - SQLite: systemd timer running an online backup (`.backup` or `VACUUM INTO`) to a dated file in a backup folder the server creates under its data root (Q21 FIXED), keep N; WAL means a plain file copy is unsafe. @@ -604,8 +604,8 @@ Each is small, ends with a green gate, and no milestone depends on browser UI be - Scope: scanline `cellsTouched`, differential + independent explored oracle tests, radius-bbox wall cull (spatial grid only if the 5k bench misses), capsule/swept move check and token-on-wall escape (5.5), step cap = effective vision radius (5.5), `blocked` flag with circle-overlap trigger and Set/Keep/Clear policy (5.5), GM moves ignore walls and step cap (and set/clear `blocked`), bench harness incl. 5k-wall scene, pure in-process move-rules module with unit tests. The WS/hostile-client harness is M3, not M2. - Accept: `visibilityPolygon` and `cellsTouched` equal the old implementation on the corpus (5.5); `moveBlocked` excluded (its results change on purpose); polygon+cells bench <= prototype (0.451 ms) on the prototype scene and polygon < 1 ms on the 5k-wall scene [targets PROPOSED]; in-process probing test passes; escape and capsule positive and negative unit tests pass; door-push tests pass (each side, centre on the line uses the previous side, other-side fallback for a blocking wall and for out of bounds, both invalid -> blocked and opening frees it, GM-owned token pushed, wall add still sticks); `blocked` tests pass (every Set/Keep/Clear rule of 5.5: overlap trigger, doorway, two overlapping walls, GM drop/move sets and clears, GM clear then escape, unrelated change does not re-block); mutations k (no Keep), l (GM moves do not set blocked), m (push to the wrong side), n (push skips the validity check) and o (previous side ignored) each fail >= 1 test; over-cap move gives the same nack as a blocked move; thresholds documented in the module header; oracle tolerance 0.5 px. The KNOWN LIMITATION test and the Q14 pin test are replaced with positive assertions and `blocked`-policy tests. - **M3 - Server core.** - - Scope: entities with bucketed props, characters with names, name reveal and encountered list (8, #14), players, player keys/sessions, scenes, chunked explored persistence, typed per-recipient views and single egress, per-connection counters, proto versioning, wall/entity CRUD intents, Origin check, plaintext invite secrets and non-expiring sessions (Q10, Q11), SQLite schema + migrations. - - Accept: ported leak test (A and B) + fault test with the extended fault classes: all caught with exact class sets, clean build passes; restart test passes incl. CRUD; auth tests pass; no secrets in logs; character and name tests pass (10.3, #14). + - Scope: entities with bucketed props, characters with names, name reveal and encountered list (8, #14), players, player keys/sessions, scenes, chunked explored persistence, typed per-recipient views and single egress, per-connection counters, proto versioning, wall/entity CRUD intents, Origin check, plaintext invite secrets and non-expiring sessions (Q10, Q11), SQLite schema + migrations. Tile gate `/tiles/` (3.3), fixture tiles at 32 px generated at test time by a helper (not committed), minimal local test nginx with internal `/_tiles/` (production vhost and tile import CLI stay M6) [FIXED, owner decision 2026-11-14, #7]. + - Accept: ported leak test (A and B) + fault test with the extended fault classes: all caught with exact class sets, clean build passes; restart test passes incl. CRUD; auth tests pass; no secrets in logs; character and name tests pass (10.3, #14). Tile gate: leak test (d) and smoke tile-steal checks pass through the test nginx; gate decisions match the independent explored oracle (10.2); direct `/_tiles/` fetch -> 404; malformed or out-of-range path -> 404; unexplored -> 403 [FIXED, owner decision 2026-11-14, #7]. - **M4 - Client v1.** - Scope: new `client/` dir (first real client build): Vite + TS + Pixi v8 client: layers, tiles, grid, tokens (BitmapText), character list, encountered list (greyed), reveal buttons (#14 UI; server side in M3), fog textures, wall/door editor, token drag with prediction/rollback, DOM overlay, reconnect backoff, reducer tests; after the client port, archive `prototype-*` dirs (Q24). - Accept: headless e2e: fog pixel checks, player traffic audit clean, reconnect restores; manual run on laptop and Note 10 at 60 fps with 50 tokens, 16384 px map (tiled; PROPOSED test target, Q2), fog active. @@ -657,3 +657,5 @@ Owner also decided 2026-11-08 (M2): move rules, `blocked` trigger and GM move by Owner also decided 2026-11-10 [FIXED (owner decision), #14]: characters are separate records from tokens (one owner: a player or the GM; a token may link to one character; token controller is independent of the character owner); character holds identity, token holds the state of the figure; descriptive and actual names, revealed per player or to all; per-player encountered list, persisted, removed only by the GM; storage on the server only (SQLite). Character export/import as a file is future, not M3. See 3.1, 4.4, 8. Owner also decided 2026-11-10 [FIXED (owner decision), #6]: one shared site link (alone it shows only the sign-in page); each player has a personal player key, generated by the GM with no name, identifying the player and granting access to their data. The player types their display name at first sign-in; names are unique among players; the GM can rename. The GM signs in the same way with a GM key printed by `fff-vtt gm-key` (replaces `gm-link`, #5; rest of #5 unchanged). The GM can replace a player's key at any time while the server runs: old key invalid, all that player's sessions revoked, live connections closed; identity, characters and encountered list kept; no name re-prompt. Removing a player: key invalid, sessions revoked, connections closed; their characters and controlled tokens pass to the GM; name and slot freed; encountered list deleted. Defaults accepted: one key on many devices; sessions never expire; keys stored plaintext; 20-character key in groups of 4 with dashes, no look-alikes, CSPRNG (~100 bits); 6-player cap counts unused keys; sign-in sets the session cookie as in 3.2. No rate limit or lockout on key entry (owner rejected guessing protection). Rejected: per-person invite links; GM types the name at key creation; delete-and-reinvite only; deleting characters with the player; shared-link visit creates a player; separate GM link path. Terms: "player key" and "GM key"; "token" stays reserved for map figures. Message names: #11. + +Owner also decided 2026-11-14 [FIXED (owner decision), #7]: map tiles in M3. The tile gate (`/tiles/`, Nim, `X-Accel-Redirect`) and a minimal local test nginx with generated 32 px fixture tiles are M3 scope; tile import CLI and the production nginx vhost stay M6. Tile URLs carry `art_version` from M3 (always 1 in M3); responses are `Cache-Control: private`; malformed or out-of-range paths get 404, unexplored tiles 403. The gate reuses the server's explored-area logic, checked against the independent oracle (10.2). On-disk layout `/tiles//v/` fixed in M3. See 3.3, 11.1, 13.