Repository navigation
Description
Problem
pkgs/id/web/src/collab.ts handleMessage validates the INIT frame's version/document fields before use (the #2824 hardening), but the UPDATE and CURSOR family handlers still cast frame fields unchecked:
- UPDATE (collab.ts:375-376):
const steps = msg[1] as unknown[]; const clientIDs = msg[2] as number[];— the only guard is truthiness +steps.length > 0(collab.ts:378). - CURSOR (collab.ts:417-421):
clientID,head,anchor,name,idleSecsare all cast and passed straight toupdateCursor/markCursorFresh. - CURSOR_REMOVE (collab.ts:473):
clientIDcast unchecked.
Verified behavior (laptop probe, origin/main e5a4fdc)
Probe: ~/git/fleet/probe-collab-frames (real initCollab + FakeWebSocket harness from collab.test.ts, msgpackr-packed frames; existing collab suite 24/24 passes as control):
- A malformed UPDATE tears the session down instead of being dropped. Delivering
[2, "not-an-array", [1]]or[2, [123], [999]]after a valid INIT makessteps.map(...)/Step.fromJSONthrow inside the step-applytry, whose catch (collab.ts:398-408) treats it as desync:currentWs.close(4001, "Step apply failure")+scheduleReconnect(). Observed:closeCalls=[{code:4001, reason:"Step apply failure"}]and new sockets on timer advance. One bad frame from a buggy/malicious peer or a version-skewed server therefore forces a full disconnect + editor destroy/re-init on the next INIT; a stream of them is a reconnect churn loop. Malformed INIT frames, by contrast, are logged and dropped with the session intact. - A malformed CURSOR is stored verbatim as a phantom cursor. Delivering
[4, 4242, {x:1}, "abc", {evil:1}, "zzz"]stores, in the cursor plugin state, a cursor withhead=[object Object],anchor="abc",name=[object Object]— it persists alongside later valid cursors. Downstream,createCursorDecorationsclamps withMath.min(cursor.head, docSize)(cursors.ts:523-524), which isNaNfor these values, so the phantom cursor feeds NaN positions into decoration/coords code instead of being rejected at the frame boundary. - Inconsistent handling:
[2, [], "not-an-array"](bad clientIDs, empty steps) is silently ignored, while the cases in (1) disconnect — the frame contract is whatever each expression happens to do with a wrong type.
Why it matters
The collab socket is a trust boundary: frames arrive from the server relaying other clients' traffic. Every other hardened handler in this file drops malformed input at the boundary; UPDATE/CURSOR instead either amplify one bad frame into a session teardown (availability) or admit unvalidated values into ProseMirror plugin state (correctness/rendering). This is the remaining unhardened surface of the same frame-shape family as #2824 (INIT), #7859 (INIT mode) and #7854 (AUTH_OK/NEW_VERSION).
Acceptance criteria
- UPDATE: drop (log + return, no close/reconnect) when
stepsis not an array,clientIDsis not an array, their lengths differ, or any step failsStep.fromJSONparsing as a shape error — genuine apply/desync failures of well-shaped steps keep the existing reconnect path. - CURSOR / CURSOR_REMOVE: drop when
clientIDis not a string/number,head/anchorare not finite numbers, ornameis present and not a string/null;idleSecsignored unless a finite number. - Tests in collab.test.ts style: each malformed frame above is dropped with the editor/session intact (no
close(4001), no new socket, no cursor stored), and a following valid frame still applies; valid UPDATE/CURSOR controls keep working (existing suite green).
Evidence
- Code:
pkgs/id/web/src/collab.ts:375-421, 473at origin/maine5a4fdcbcb3f90b6552009420d900151454d9103. - Probe:
~/git/fleet/probe-collab-frames/src/probe-frames.test.ts+probe2.test.ts(7+1 tests, all observations above reproduced; collab.test.ts 24/24 as control).
Activity
developing-today commentedon Nov 9, 2026
CODE-2338
dezren39 commentedon Nov 9, 2026
🤖 Agent note · filed
dezren39 commentedon Nov 10, 2026
Agent note - parked (awaiting triage)
dezren39 commentedon Nov 10, 2026
Picked up by
repo-worker-code-o— working this now. (Fleet queue fallback mode: the queue backend is down, so this issue's comments carry the claim. The claim stays live whilerepo-worker-code-oposts progress markers; after 30 minutes of silence any other worker may pick this up.)11 remaining items
dezren39 commentedon Nov 11, 2026
agent-note:v1
state: parked
worker: repo-worker-code
lane: any-b
task: 14189
note: Resumed and re-verified PR #8507 (head 427f75c): implementation already landed by the prior claim (UPDATE/CURSOR/CURSOR_REMOVE frame validation in collab.ts + tests). Codex review completed clean on 1616580, the pre-rebase twin of the current head (same two files, diverged only by the rebase). Blocked only on CI: 7 checks QUEUED in the fleet-wide backlog, 0 failed. Parked as CI wait. Resume: checks green (+ Codex clean on current head if it re-runs) -> merge -> complete fixed_merged.
dezren39 commentedon Nov 11, 2026
🤖 Agent note · picked up (task 14189, lane code-d)
handleMessageboundary per the acceptance criteria: malformed UPDATE frames (non-array steps/clientIDs, length mismatch, unparseable step) drop with the session intact instead of hitting the desync close-4001 path; malformed CURSOR frames (non-string/number clientID, non-finite head/anchor, non-string name) drop instead of storing a phantom cursor;idleSecscounts only as a finite number.tsc --noEmitclean, full web suite green apart from the pre-existing search-panel failure tracked on test(id-web): search-panel role=search/aria-label test fails on clean main #8012 (reproduces on clean main).fix(id/web): validate UPDATE and CURSOR frame fields in collab handle…
dezren39 commentedon Nov 11, 2026
🤖 Agent note · done — fixed_merged (task 14189, lane code-d)
handleMessage, in the id(web): collab handleMessage trusts MessagePack frame shape — a null frame throws out of onmessage, and a field-less INIT silently initializes an empty editor at an undefined version #2824 Init-hardening style): UPDATE frames drop at the boundary when steps/clientIDs are not equal-length arrays, and every step is parsed withStep.fromJSONbefore any is applied — a parse failure drops the frame with the session intact; only apply failures of well-shaped steps keep the desync close-4001 + reconnect path. CURSOR frames drop when clientID is not a string/number, head/anchor are not finite numbers, or name is present and not a string/null; idleSecs counts only as a finite number. CURSOR_REMOVE validates clientID the same way.collab.test.ts(each malformed frame from the issue's probe + a valid-frame control; session-intact oracle = socket OPEN, no reconnect after timers, version unmoved, no phantom cursor). Verified pre-merge: collab.test.ts 34/34,tsc --noEmitclean, full web suite 764 passed with only the pre-existing search-panel failure (tracked on test(id-web): search-panel role=search/aria-label test fails on clean main #8012, reproduces on clean main). Post-merge on main cad4e14: collab.test.ts 35/35.