Repository navigation
Description
Problem
The world page (pkgs/id/web/src/world.ts) shape-trusts both of its HTTP
responses with bare casts, while the WebSocket frames in the same file are
carefully guarded (isWorldSnapshot / isWorldEvent / isRecord):
- Host view:
world.ts:433—const result = (await response.json()) as { … records_sequence: number; records: Record<string, unknown>; next_after: string | null }, thenworld.ts:445runsObject.entries(result.records)unguarded. - Invite:
world.ts:566—const result = (await response.json()) as { capability: string; display_name: string }, thenworld.ts:567callsshowCapability(result.capability), which writes the value into the capability input and persists it tosessionStorage(world.ts:181-185).
A wrong-shape 200 (deploy skew, a future contract change, a proxy error page
served as JSON) therefore fails in two bad ways instead of through the
handlers' own error vocabulary ("Host view unavailable" / "Invite failed").
Verified (this run, laptop, origin/main 8728f5c)
Probe ~/git/fleet/probe-world-shape — a vitest/happy-dom test against the
real world.ts from a clean git archive snapshot, using the same page
harness as world-rejoin.test.ts (real template markup, stubbed fetch).
Controls pass: a well-formed host-view payload renders "Read-only host view"
with its records; a well-formed invite stores cap-123.
Malformed payloads, observed:
| Case | Host view (/api/world/host-view) |
Invite (/api/world/invite) |
|---|---|---|
null |
status = raw Cannot read properties of null (reading 'records_sequence') |
status = raw Cannot read properties of null (reading 'capability') |
{} |
status = raw Cannot convert undefined or null to object |
fake success "Invite created…" — capability input and sessionStorage both persist the literal string "undefined" |
"abc" |
raw Cannot convert undefined or null to object |
fake success, "undefined" persisted |
[] |
raw Cannot convert undefined or null to object |
fake success, "undefined" persisted |
{records_sequence:0, records:null, next_after:null} / records missing |
raw Cannot convert undefined or null to object |
— |
{capability:123, display_name:"ada"} |
— | fake success, capability coerced and persisted as "123" |
{capability:"cap-x"} (no display_name) |
— | success, log line reads "Invite created for undefined" |
The invite case is the worse one: the persisted "undefined" capability is
read back on the next page load (world.ts:125) and used as the join
credential, so one wrong-shape response poisons the browser's stored
credential while telling the user the invite was created. The host-view case
surfaces a raw engine TypeError as the status line instead of the handler's
own "Host view unavailable".
Server contracts (what validation should enforce)
pkgs/id/src/web/world_ws.rs:90-97—HostViewResponse { snapshot: Option<…>, view: Option<String>, surface: Option<…>, records_sequence: u64, records: Records, next_after: Option<String> }:records_sequence(number) andrecords(object) are required;next_afteris a string or null.pkgs/id/src/web/world_ws.rs:533invite_handlerreturns the invite JSON; the server-side test atworld_ws.rs:1218pinscapabilityas a non-empty string. The client contract is{ capability: string, display_name: string }.
Why it matters
Same class as #7811 (home feed), #7812 (image-browser), and #7823 (upload,
fixed by validating at the fetch boundary): a malformed 200 must fail closed
through the existing error path. Here it additionally corrupts persistent
state — the stored capability — with a fake success message on top.
Acceptance criteria
- Malformed
/api/world/host-view200 payloads (null / non-object body, missing or wrong-typedrecordsorrecords_sequence, wrong-typednext_after) surface as "Host view unavailable" (or an equally clear host-view error), never as a rawTypeErrorstatus, and never render partial records. - Malformed
/api/world/invite200 payloads (null / non-object body, missing, empty, or non-stringcapabilityordisplay_name) surface as an invite failure;showCapabilityis never called, the invite output stays hidden, and nothing is written tosessionStorage. - Well-formed payloads behave exactly as today (existing world tests unchanged and green, including the host-view and rejoin suites).
- New regression tests in the web suite (e.g. alongside
world-rejoin.test.ts/ a newworld*.test.ts) cover the malformed cases above and fail pre-fix. - Web suite + typecheck green.
Scope: pkgs/id/web/src/world.ts response validation at the two fetch
boundaries only. Do not change the Rust handlers or the WebSocket frame
handling (already guarded). Sibling HTTP shape-trust items in other modules
(#7811, #7812) are separate issues.
Activity
developing-today commentedon Nov 8, 2026
CODE-2329
dezren39 commentedon Nov 8, 2026
🤖 Agent note · filed
6 remaining items
dezren39 commentedon Nov 8, 2026
agent-note:v1 — task 14007 (lane code-l) — pr_opened
Fix is up as PR #7858 (branch
queue/14007-7831-world-shape):world.tsnow validates both HTTP response shapes before use —isHostViewResponsemirroringHostViewResponseinworld_ws.rs, andisInviteResponserequiring a non-empty stringcapability. Wrong-shape 200s fail closed: host view surfaces "Host view unavailable" with no partial render; invite surfaces "Invite failed" withshowCapabilitynever called and nothing written to sessionStorage.Evidence: new
world-shape.test.ts(17 tests) — malformed cases fail pre-fix (all 7 invite cases + host-view null/{}/string/array verified on the unpatched file), 17/17 pass post-fix; world suites 51/51; full web suite 702 passed with 1 failure insearch-panel.test.tsverified pre-existing on clean main;tsc --noEmitand biome clean. PR carries the closing keyword; merging it closes this issue.fix(id/web): reject empty invite display_name and cover merged shape …
dezren39 commentedon Nov 14, 2026
agent-note:v1
state: superseded-with-one-delta
task: 17284
lane: code-a
worker: repo-worker-code
What: PR #7858 (this issues PR) is closed as superseded by PR #8532 (#7833, commit d894722), which landed fetch-boundary validation for the host-view and invite responses in pkgs/id/web/src/world-http.ts. The one piece of #7858 not landed is a contract conflict, recorded here so this issue can carry it: #7858 requires invite display_name to be a non-empty string (missing/empty/wrong-type fail closed), while the landed #7833 contract deliberately falls back to null display_name for absent/wrong-typed values (asserted in world-http.test.ts). Deciding which contract governs the invite response — and, if strictness wins, changing parseWorldInviteResponse plus its test — is the remaining work on this issue.
dezren39 commentedon Nov 17, 2026
🤖 Agent note · done (already_done) — contract delta decided, closing