Skip to content

id(web/world): /api/world/host-view and /api/world/invite responses shape-trusted — a wrong-shape 200 shows raw TypeErrors or stores a fake 'undefined' capability #7831

Closed

Description

@dezren39

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 }, then world.ts:445 runs Object.entries(result.records) unguarded.
  • Invite: world.ts:566 — const result = (await response.json()) as { capability: string; display_name: string }, then world.ts:567 calls showCapability(result.capability), which writes the value into the capability input and persists it to sessionStorage (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) and records (object) are required; next_after is a string or null.
  • pkgs/id/src/web/world_ws.rs:533 invite_handler returns the invite JSON; the server-side test at world_ws.rs:1218 pins capability as 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-view 200 payloads (null / non-object body, missing or wrong-typed records or records_sequence, wrong-typed next_after) surface as "Host view unavailable" (or an equally clear host-view error), never as a raw TypeError status, and never render partial records.
  • Malformed /api/world/invite 200 payloads (null / non-object body, missing, empty, or non-string capability or display_name) surface as an invite failure; showCapability is never called, the invite output stays hidden, and nothing is written to sessionStorage.
  • 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 new world*.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

  1. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/creatorFiled by the new-issue-creator job
    on Nov 8, 2026
  2. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor
  3. added
    priority/lowNice to have; do when convenient
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 8, 2026
  4. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  5. added
    work/assignedQueue worker lifecycle state
    queue/claimedQueue worker lifecycle state
    and removed on Nov 8, 2026
  6. 6 remaining items

  7. added
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    and removed
    queue/claimedQueue worker lifecycle state
    on Nov 8, 2026
  8. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    agent-note:v1 — task 14007 (lane code-l) — pr_opened

    Fix is up as PR #7858 (branch queue/14007-7831-world-shape): world.ts now validates both HTTP response shapes before use — isHostViewResponse mirroring HostViewResponse in world_ws.rs, and isInviteResponse requiring a non-empty string capability. Wrong-shape 200s fail closed: host view surfaces "Host view unavailable" with no partial render; invite surfaces "Invite failed" with showCapability never 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 in search-panel.test.ts verified pre-existing on clean main; tsc --noEmit and biome clean. PR carries the closing keyword; merging it closes this issue.

  9. removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    work/assignedQueue worker lifecycle state
    on Nov 8, 2026
  10. dezren39 commented on Nov 14, 2026

    @dezren39
    MemberAuthor

    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.

  11. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (already_done) — contract delta decided, closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

app/idPackage/app: id (pkgs/ or apps/ in this repo)effort/sSmall: expected under 2 hours of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/lowNice to have; do when convenientsource/creatorFiled by the new-issue-creator jobstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions