Skip to content

id(web/collab): collab WebSocket has no message-size or step-count cap — a single frame can be 64 MiB and hundreds of thousands of steps, all retained and replayed to every joiner #1965

Closed

Description

@dezren39

Problem

The collaborative-editing WebSocket (/ws/collab/{doc_id}) applies no message-size cap and no per-message step-count cap, even though the repo's own framing standard is 1 MiB:

  • pkgs/id/src/frames.rs:16-19 — MAX_FRAME_BYTES is 1 MiB, documented as: "Both transports enforce it: the Iroh frame reader refuses longer frames and the WebSocket has max_message_size(MAX_FRAME_BYTES)."
  • pkgs/id/src/web/world_ws.rs:279 — the world WebSocket does exactly that: ws.max_message_size(MAX_FRAME_BYTES).
  • pkgs/id/src/web/collab.rs:626-632 — ws_collab_handler calls plain ws.on_upgrade(...) with no max_message_size / max_frame_size, so the upgrade inherits the framework default. Verified in the vendored tungstenite 0.29.0 source (the version axum 0.8.9 uses here): WebSocketConfig::default() is max_message_size: Some(64 << 20), max_frame_size: Some(16 << 20) — 64× the repo's frame standard.

Nothing downstream compensates:

  • CollabMessage::decode (collab.rs:513, Steps attempt at :536-545) deserializes a Vec<serde_json::Value> of steps with no length or byte check.
  • The Steps handler (collab.rs:1016-1029) pushes every step in the message into the document's permanent step history (doc_steps.push(...) at :1019), clones the whole vector for the broadcast Update, and advances the version by steps.len().
  • That history is retained for the life of the document and re-serialized in full as the catch-up Update to every later joiner (collab.rs:784-810), so one oversized message is paid for in server memory and in every subsequent join's bandwidth, not just once.

Any client that can open a collab socket (the first-message auth is optional — anonymous clients proceed, collab.rs auth-timeout path) can therefore send a single ~64 MiB message, or one message carrying hundreds of thousands of steps, and have all of it decoded, cloned several times, stored, broadcast, and replayed to future joiners. The sibling world socket and every length-prefixed transport in the crate refuse anything over 1 MiB unread.

Related but distinct: #1833 covers the collab cursor name path (no length/control filtering); this issue is the message/step-count size bound on the same socket. #1839 is the same bug class in codex-proxy's hand-rolled WS parser.

Evidence (verified this run, main 6a284efd)

Laptop probe ~/git/fleet/probe-2026-10-28-laneA-collabws/ — the Steps decode attempt copied verbatim from collab.rs (file sha256 55e042705c0389140eb2b50aa617cd4cac388806b44e116ecba69af0a7d9f6e0 = main), plus the handler's history-push loop:

CONTROL ok: 33 bytes, version=0 steps=1 client=7
OVERSIZE_FRAME_ACCEPTED: 4194337 bytes (4x the 1 MiB frame cap) decoded to 1 step(s); no size check in decode
MANY_STEPS_ACCEPTED: 200000 steps in one 6937097-byte message; simulated handler history now holds 200000 steps, version would jump by 200000

Framework default verified in the laptop cargo registry: tungstenite-0.29.0/src/protocol/mod.rs:101-102 — max_message_size: Some(64 << 20), max_frame_size: Some(16 << 20).

Dedup: gh issue list --search (all states) for "collab websocket message size", "max_message_size", and "collab steps history unbounded" returned only #1833 (cursor names — different) and closed audit #1075. No existing issue covers a collab message-size or step-count bound.

Why it matters

A long-lived id serve process can be made to allocate and retain hundreds of MiB (decode + history clone + broadcast clone + per-joiner catch-up clones) from a single unauthenticated socket message, and the retained history inflates every later join for that document. The crate already decided this bound: 1 MiB, enforced on the Iroh reader, the SSH/byte-stream readers, and the world WebSocket. The collab socket is the one WebSocket that missed it.

Acceptance criteria

  • ws_collab_handler sets max_message_size (and max_frame_size if triage judges it needed) to the repo standard MAX_FRAME_BYTES, matching world_ws.rs:279; an over-limit message closes/refuses the connection without being decoded into the step history.
  • A per-message step-count bound (a named constant) is enforced on the Steps path — in decode or in the handler before any step is pushed — so a within-size but step-stuffed message cannot grow the history or jump the version by an unbounded count in one frame. (Triage pins the value; it should comfortably cover legitimate ProseMirror step batches.)
  • Regression tests: an over-MAX_FRAME_BYTES collab message is refused; a Steps message past the step-count bound is refused with the document version and history unchanged; ordinary small Steps messages still apply, ack, and broadcast.
  • The frames.rs doc claim ("the WebSocket has max_message_size(MAX_FRAME_BYTES)") is true for every WebSocket the crate serves after the fix — triage also checks tags_ws.rs (its inbound side only drains, so exposure is smaller, but the same one-line bound applies).

🤖 Filed by the new-issue-creator (lane A) after a verified probe; see the agent note below for the queue packet.

Activity

  1. developing-today commented on Oct 28, 2026

    @developing-today
    Contributor
  2. added
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    source/creatorFiled by the new-issue-creator job
    task/triageQueue packet kind: verify, reproduce, and route this item
    priority/normalOrdinary priority (the default)
    app/idPackage/app: id (pkgs/ or apps/ in this repo)
    effort/sSmall: expected under 2 hours of work
    on Oct 28, 2026
  3. dezren39 commented on Oct 28, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · filed

  4. dezren39 commented on Oct 31, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · state: handed off

    Remainder from #2969 not covered by this issue's AC

    This issue pins the per-message bounds (message size + per-message step count). #2969 verified a second, cumulative growth path on current main ed59bc6d that those bounds do not close:

    • Even with a per-message cap, Document.steps (pkgs/id/src/web/collab.rs:217) is only ever appended to (sole push at :1023) — there is no total-history cap and no compaction. A client sending perfectly legal, within-limit Steps messages indefinitely still grows the retained history without bound, and every joiner is sent a clone of all of it (catch-up at :793-796).
    • Saves never fold the history into the base document: notify_new_version (:352-375) only broadcasts and updates the stored hash, and the Init base remains the initial content at version 0 (:765). A document is removed only after its last client has been gone for 1 hour (DOCUMENT_CLEANUP, :185), so one connected or regularly reconnecting client keeps the full history alive indefinitely.

    Suggested addition to this issue's fix scope (triage's call): a named bound on retained history (count and/or bytes) and/or periodic compaction of applied steps into the base document, with a test that a fresh joiner still reconstructs the same document after the bound/compaction is hit. #2799 (Init frame version) interacts with any compaction shape.

  5. added
    work/assignedQueue worker lifecycle state
    and removed on Nov 1, 2026
  6. 77 remaining items

  7. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · parked

  8. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    agent-note:v1 — parked — Lane D

  9. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    agent-note:v1 — parked — Lane D

  10. added
    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 2, 2026
  11. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    Lane B picked up task 5056. OWNERSHIP MISREAD CORRECTED: PR #4051 is on branch queue/5056-1965-collab-ws-size — this task's own queue branch (author dezren39 is the fleet account); not a Drew-owned personal branch, and neither PR #4051 nor #1965 carries held/user/owned/do-not-merge/do-not-auto-edit labels. Resuming from awaiting_ci: verifying diff, CI, and Codex on head cea81a3.

  12. dezren39 commented on Nov 2, 2026

    @dezren39
    MemberAuthor

    Done: PR #4051 merged as 5ae6ee7. Ownership misread corrected this shift (own queue/5056-* branch, not Drew-owned). Codex review on head cea81a3 completed clean; both earlier P2 findings were fixed in-branch and dispositioned on their threads. Targeted tests verified on the laptop: bun test collab.test.ts stepBatch block 6/6 pass; the 3 failing initCollab (#1463) tests fail identically on clean main under bun (vitest-only vi.stubGlobal APIs — pre-existing runner mismatch, not this change). PR checks were queued-only for ~3h (fleet CI congestion pattern); merged under the standing merge authority. Task 5056 completed fixed_merged.

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/normalOrdinary priority (the default)source/creatorFiled by the new-issue-creator jobstatus:in-reviewtask/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