Skip to content

fix(authz): refuse malformed collab updates before they apply; same rules over HTTP (wiki-v2 #781) - #84

Merged
PMQ9 merged 6 commits into
wiki-v2from
fix/781-collab-ingress
Nov 9, 2026
Merged

PMQ9 merged 6 commits into
wiki-v2from
fix/781-collab-ingress

Conversation

@PMQ9

@PMQ9 PMQ9 commented Nov 9, 2026 •

Copy link
Copy Markdown

What

This change refuses malformed collab updates before they apply, and holds HTTP JSON content to the same rules. It fixes https://github.com/cccvu/wiki-v2/issues/781 and is paired with the super PR https://github.com/cccvu/wiki-v2/pull/791. The design record is ADR 0036 in the super PR.

authz/collab-ingress/ (fork-owned)

  • update-guard.ts + collab-update-guard.extension.ts: a synchronous beforeHandleMessage guard.
    • It applies each client sync frame to a shadow Y.Doc replica of the live document and inspects what Yjs integrated, before GC and merge.
    • It refuses the frame with a document CLOSE, code 4422 and reason ccc:collab-update-refused:<rule> or ccc:collab-update-unresolved. Refusal rules:
      • the frame would make y-tiptap delete content or fromYdoc throw;
      • it writes outside 'default';
      • a string-read attribute is not a string;
      • a value or element is too deep;
      • a dependency is unresolved;
      • it uses a clientID bound to another user;
      • it is a client Stateless or BroadcastStateless frame.
    • The shadow is mirrored from live update events, rebuilt from live plus in-flight frames after a refusal, and audits stored content once at load in report-only mode.
    • Kill switch: COLLAB_UPDATE_GUARD=enforce|report.
  • content-rules.ts: the schema-driven checkElement / checkTree, which mirror y-tiptap's createNodeFromYElement / createTextNodesFromYText through the public PM API. It also holds STRING_ATTRS, the iterative checkValue, and assertCollabSafeContent for HTTP JSON (400 content_not_allowed; 422 content_too_complex past element depth 128).

authz/request-controls/

  • The storable-text interceptor answers 400 invalid_characters for a NUL or lone surrogate in a JSON body, query or params, before the handler runs.
  • The PostgresError filter maps 22P05, 22021 and json/unicode 22P02 to 400.

authz/page-write/

  • storeSafeJson and stableStringify stop at depth 512.
  • buildPrelimContent runs assertCollabSafeContent.

Seams

  • §3: the gateway registers the guard first.
  • §121: parseProsemirrorContent runs assertCollabSafeContent, and update() parses before its row write.
  • §169: page-editor.tsx passes the CLOSE reason and sync-acked, and renders the refusal notice.

Client editor-ux/

  • The refusal state in collab-access.ts.
  • collab-refusal-notice.tsx offers Reload, and "Discard this browser's copy" behind a confirmation.
  • collab-local-copy.ts.

Why

A user with edit rights could use a raw Hocuspocus client to send content that crashed every viewer's page, wedged every store (the issue 773 class), made every peer's y-tiptap delete text, or used a nested value to break encoding.

Related holes this also closes:

  • client writes or deletes in the /v1 idempotency ledger;
  • extra roots;
  • forged-clock edit drops;
  • broadcasting arbitrary Stateless frames to peers;
  • invalid JSON structure over /v1 that browsers silently deleted on open;
  • a NUL over HTTP returning 500.

Scope

  • The fork-owned code is authz/collab-ingress/, authz/request-controls/, authz/page-write/ and apps/client/src/features/editor-ux/.
  • Upstream files touched: only the documented seams §3, §121 and §169.
  • check-upstream-boundary.sh passes.

Tests

The commits are ordered red-first: a9e0066f holds only the specs, and the fix comes in a6af3d9a and 8c2c1ef3.

Suite Result
CI FORK_SPEC_ROOTS lane 233 suites, 3779 passed
pg lane (AUTHZ_REQUIRE_PG=1) 43 suites, 603 passed
client vitest (editor-ux) 388 passed
full client suite 930 passed
  • Every attack spec has a guard-off control arm (proving the damage) and a treatment arm.
  • The guard and filters are mutation-proven: about 50 mutants, all killed.
  • The live stack check:
    • honest editing, including two concurrent browsers, is never refused;
    • seven crafted attacks are each refused with the right rule, with peers unaffected;
    • /v1 returns the new 400s.

🤖 Generated with Claude Code

PMQ9 and others added 6 commits November 9, 2026 00:51
…re modes (red before the fix)

Specs for wiki-v2 issue 781, committed ahead of the fix so each one is shown
failing first:
- collab-ingress: crafted Yjs frames (non-string href/src, non-element children,
  embeds, unknown and hashed marks, schema violations, deep values, ledger and
  extra-root writes, Stateless frames, forged clientIDs, ordering races,
  y-indexeddb replay) each with a guard-off control arm, plus false-positive,
  drift and wiring specs;
- request-controls: NUL / lone surrogate bodies and Postgres 22P05/22021/22P02;
- page-write: depth-bounded storeSafeJson and stableStringify;
- client editor-ux: refusal handling, notice, local-copy discard, schema parity.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vwm9j7BaeNNR8eEN7G7kJP
…ules over HTTP (docmost#781)

Wiki-v2 issue 781 / ADR 0036. A crafted collab client could send Yjs content
that crashes every viewer, wedges every store, or makes every peer's y-tiptap
delete text.

- authz/collab-ingress: a synchronous Hocuspocus beforeHandleMessage guard
  applies each client frame to a shadow replica of the live document and
  refuses it (document CLOSE, reason ccc:collab-update-*) when the integrated
  result would make y-tiptap delete or fromYdoc throw (schema-driven, mirroring
  createNodeFromYElement / createTextNodesFromYText), writes outside 'default',
  carries non-string string attributes or too-deep values, leaves unresolved
  dependencies, or uses a clientID bound to another user.
- HTTP JSON content goes through the same rules (assertCollabSafeContent) in
  parseProsemirrorContent (seam docmost#121) and buildPrelimContent.
- request-controls: NUL / lone surrogates in JSON requests are 400
  invalid_characters before any apply; a PostgresError filter maps the same
  storage errors to 400.
- page-write: storeSafeJson and stableStringify bound depth at 512.
- client editor-ux: a refused session detaches and shows Reload / Discard this
  browser's copy; an unresolved one reconnects once (seam docmost#169).
- gateway seam #3 registers the guard first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vwm9j7BaeNNR8eEN7G7kJP
Native /api/pages/update (which /v1 PATCH relays to) wrote the page row (title,
updatedAt, lastUpdatedById, so the page ETag) before parsing the content, so a
content refusal answered 400 "not applied" while the title had changed and the
next If-Match 412'd. PageService.update now parses (and refuses) the content
before any write, next to the docmost#716 cap check, and updatePageContent applies
that one parse.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vwm9j7BaeNNR8eEN7G7kJP
…ost#781)

- Table colspan/rowspan must be integers within HTML's limits (number-attr): colspan 1e9 hung every viewer.
- embed.provider joins STRING_ATTRS; in a Yjs element null passes only where the schema default is null.
- An awareness entry at a clock the server already holds is an echo and binds nothing, so a writer echoing a
  reader's state no longer binds the reader's id.
- The build audit follows y-tiptap's delete cascade over legacy content, so opening such a page is not refused.
- assertCollabSafeContent refuses a root that is not doc.
- Guard log tokens are UPPER_SNAKE (COLLAB_UPDATE_REFUSED, ...) for the infra-config inventory.
- Specs: the stale-shadow flush, __proto__ attributes, spans, null defaults, the cascade, the echo, non-doc roots.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vwm9j7BaeNNR8eEN7G7kJP
…ost#781)

- table-size: a table is refused past 1000 columns or 1M columns x rows (width as prosemirror-tables' findWidth,
  rowspans carried). In-range spans still added up to a 1M-wide map. Checked on the enclosing table of any touched
  table, row or cell, on the HTTP twin for every format, and reported (not refused) for a legacy table.
- Table spans must be at least 1: a span of 0 is a cell prosemirror-tables makes every browser repair.
- editor-ext: withSafeCellSpans gives colspan/rowspan a browser-like parseHTML (parseInt, 1 when missing or below 1,
  clamped), so an honest paste of colspan="100%" or "5000" stays inside number-attr instead of locking the editor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vwm9j7BaeNNR8eEN7G7kJP
…ost#781)

- table-size counts a null or absent span as the default 1, as the stored table holds it (toYdoc drops a null
  attribute); a JSON "colspan": null no longer reads as width 0. A spec holds the HTTP verdict equal to the stored
  table's.
- Tighter table bounds: at most 2500 rows and 50,000 columns x rows (width stays 1000). fixTables pads short rows to
  the full width and findWidth is quadratic in rows once a cell spans rows; a spec runs fixTables on the largest
  accepted shapes as the oracle.
- A spec pins the rowspan expiry (a merge stops counting once its rows end).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vwm9j7BaeNNR8eEN7G7kJP
@PMQ9
PMQ9 merged commit 74b47d4 into wiki-v2 Nov 9, 2026
@PMQ9
PMQ9 deleted the fix/781-collab-ingress branch November 9, 2026 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant