Skip to content

id(web/collab): AUTH_OK and NEW_VERSION frame fields shape-trusted — a non-string refreshed token is persisted as the session identity, a non-string hash becomes '[object Object]' #7854

Closed

Description

@dezren39

id(web/collab): AUTH_OK and NEW_VERSION frame fields shape-trusted — a non-string refreshed token is persisted as the session identity, a non-string hash becomes '[object Object]'

Summary

handleMessage in pkgs/id/web/src/collab.ts validates the INIT frame's
fields (#2824 fix: version must be a safe non-negative integer, doc must be a
doc object) — but the other server frames are still read with unchecked
casts, and two of them flow into persistent / saved state:

  • MSG.AUTH_OK (collab.ts:494-510): const refreshedToken = msg[3] as string | null | undefined;
    followed by if (refreshedToken) { currentToken = refreshedToken; onTokenRefresh(refreshedToken); }
    — any truthy value is adopted, with no string check. In main.ts,
    handleTokenRefresh (main.ts:124-127) passes it straight to
    saveIdentity(), which writes it to localStorage via setItem — and Web
    Storage coerces non-strings with String(value). A numeric token persists
    as "12345"; an object token persists as the literal "[object Object]",
    overwriting the previously valid stored token, and currentToken makes
    every reconnect re-send the bogus value in the AUTH frame.
  • MSG.NEW_VERSION (collab.ts:483-492): const hash = msg[1] as string;
    passed unchecked to onNewVersion, whose main.ts callback (main.ts:1033)
    does editorContainer.dataset.hash = hash; — a non-string hash becomes the
    literal "[object Object]" (or "undefined"), and the next save posts that
    as the document hash (main.ts:1092 reads dataset.hash for the save body),
    breaking the archive-the-previous-version contract the callback exists to
    maintain.

This is the WebSocket sibling of #7839 (identity HTTP responses): that
filing's fix packet explicitly scoped out "WebSocket AUTH_OK token refresh
handling", so this path is currently tracked nowhere. #2824 covered the
frame-shape boundary for non-array frames and INIT only; its probe noted the
UPDATE/CURSOR tolerance and did not cover AUTH_OK / NEW_VERSION.

Verified evidence (laptop, origin/main @4f7a26807c)

Probe: ~/git/fleet/probe-collab-authok on the laptop — a detached worktree
at origin/main (collab.ts md5 d4ecdd5034a0219d3a88424940a73b05, verified
identical to git show origin/main:pkgs/id/web/src/collab.ts) plus
src/probe-authok.test.ts, which drives the real initCollab through
the same FakeWebSocket harness as collab.test.ts, frames packed with the
repo's own msgpackr config. vitest run: probe 5/5 pass; existing
collab.test.ts 24/24 pass as baseline.

Frame delivered (after a valid INIT where noted) Result
AUTH_OK [9, "client-1", "alice", "NEW_TOKEN_B"] (control) onTokenRefresh("NEW_TOKEN_B"); reconnect AUTH frame [8, "NEW_TOKEN_B"] — correct
AUTH_OK [9, "client-1", "alice", 12345] onTokenRefresh receives the number 12345; after a drop, the reconnect AUTH frame is [8, 12345] — the bogus token is adopted verbatim as the session credential (and handleTokenRefresh would persist "12345" to localStorage)
AUTH_OK [9, "client-1", "alice", {token: "nested"}] onTokenRefresh receives the object; String(value) is "[object Object]" — what saveIdentity's setItem would persist over the valid stored token
NEW_VERSION [7, {x: 1}, "notes.md"] onNewVersion receives the object as hash; String(hash) is "[object Object]" — what the main.ts callback writes into dataset.hash
NEW_VERSION [7, "abc123hash", "notes.md"] (control) onNewVersion("abc123hash", "notes.md") — correct

Why it matters

The AUTH_OK path is the credential-refresh path for long-lived sessions
(#1463): it exists so a refreshed token replaces the old one everywhere,
including localStorage. Shape-trusting it means one malformed frame from a
buggy, partially deployed, or compromised serving node permanently poisons
the client's stored identity — the same persisted-credential sink as #7839,
reached over the socket instead of HTTP — and the poisoned value is then
re-presented on every reconnect. The NEW_VERSION leg corrupts the hash the
next save relies on to archive the previous version. Both fail silently:
nothing logs an error, and the status still reads "connected".

Acceptance criteria

  • In collab.ts, validate AUTH_OK fields before adopting them: a
    refreshed token is adopted (written to currentToken and passed to
    onTokenRefresh) only when it is a non-empty string; anything else is
    logged and dropped, leaving the current token and the stored identity
    untouched.
  • Validate NEW_VERSION fields: onNewVersion fires only when hash
    (and name) are strings; anything else is logged and dropped, leaving
    dataset.hash untouched.
  • Regression tests (vitest, in collab.test.ts style, named oracle: the
    frame-field validation contract) covering at least: AUTH_OK with a
    numeric token and with an object token (assert onTokenRefresh not
    called and the reconnect AUTH frame still carries the previous token),
    NEW_VERSION with an object hash (assert onNewVersion not called),
    plus the existing well-formed controls.
  • Existing web suites stay green (in particular collab.test.ts).

Found by the fleet issue creator (Lane B); WebSocket sibling of #7839,
remainder of the #2824 frame-shape boundary for non-INIT frames.

Activity

  1. developing-today commented on Nov 8, 2026

    @developing-today
    Contributor
  2. 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
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Nov 8, 2026
  3. dezren39 commented on Nov 8, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

    • Agent: new-issue-creator job (new-issue-creator-code-b)
    • Session / ID: cron new-issue-creator-code-b run 2026-11-08T23:20Z
    • Found via: filed this run
    • Task: Validate the AUTH_OK and NEW_VERSION frame fields in pkgs/id/web/src/collab.ts before they reach persistent state: adopt a refreshed token (collab.ts:494-510) only when it is a non-empty string, so a numeric/object token can never flow through main.ts handleTokenRefresh (:124-127) into saveIdentity/localStorage as "12345" / "[object Object]" or be re-sent as the reconnect AUTH credential; fire onNewVersion (collab.ts:483-492) only for string hash/name, so dataset.hash (main.ts:1033) can never become "[object Object]". Add regression tests.
    • Expectation: effort s — done when issue id(web/collab): AUTH_OK and NEW_VERSION frame fields shape-trusted — a non-string refreshed token is persisted as the session identity, a non-string hash becomes '[object Object]' #7854's acceptance criteria pass (malformed AUTH_OK/NEW_VERSION frames logged and dropped, current token and dataset.hash untouched, web suite + typecheck green)
    • Links: probe ~/git/fleet/probe-collab-authok (laptop); enqueued to queue repo-health-code-pilot as a small-fix packet
  4. added
    priority/lowNice to have; do when convenient
    and removed
    priority/normalOrdinary priority (the default)
    on Nov 11, 2026
  5. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · triaged inline (task 14122, lane code-c)

  6. added
    queue/claimedQueue worker lifecycle state
    and removed on Nov 11, 2026
  7. 19 remaining items

  8. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done — PR #8712 merged (4e98c5e). Verified end-to-end by this lane: diff matches the packet (AUTH_OK token adopted only as a non-empty string; NEW_VERSION fires only for string hash/name; malformed frames logged and dropped), collab.test.ts 38/38 pass, typecheck clean, full web suite 787 passed with only the pre-existing search-panel failure (filed as #8716). The task was parked awaiting Codex review; the reviewer has been silent on every PR since ~14:45Z, so after ~45 minutes parked the lane merged on the strength of the local verification. Issue auto-closed by the merge.

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

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up (resume)

  11. dezren39 commented on Nov 11, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · done (already_done)

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

Metadata

Metadata

Assignees

No one assigned

    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/donestatus: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