Repository navigation
Description
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 byif (refreshedToken) { currentToken = refreshedToken; onTokenRefresh(refreshedToken); }
— any truthy value is adopted, with no string check. Inmain.ts,
handleTokenRefresh(main.ts:124-127) passes it straight to
saveIdentity(), which writes it tolocalStorageviasetItem— and Web
Storage coerces non-strings withString(value). A numeric token persists
as"12345"; an object token persists as the literal"[object Object]",
overwriting the previously valid stored token, andcurrentTokenmakes
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 toonNewVersion, whosemain.tscallback (main.ts:1033)
doeseditorContainer.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 readsdataset.hashfor 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 tocurrentTokenand 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:
onNewVersionfires only whenhash
(andname) are strings; anything else is logged and dropped, leaving
dataset.hashuntouched. - Regression tests (vitest, in
collab.test.tsstyle, named oracle: the
frame-field validation contract) covering at least: AUTH_OK with a
numeric token and with an object token (assertonTokenRefreshnot
called and the reconnect AUTH frame still carries the previous token),
NEW_VERSION with an object hash (assertonNewVersionnot 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
developing-today commentedon Nov 8, 2026
CODE-2332
dezren39 commentedon Nov 8, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 11, 2026
🤖 Agent note · triaged inline (task 14122, lane code-c)
19 remaining items
dezren39 commentedon Nov 11, 2026
🤖 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.
dezren39 commentedon Nov 11, 2026
🤖 Agent note · picked up (resume)
dezren39 commentedon Nov 11, 2026
🤖 Agent note · done (already_done)