Repository navigation
fix(authz): refuse malformed collab updates before they apply; same rules over HTTP (wiki-v2 #781) - #84
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 synchronousbeforeHandleMessageguard.Y.Docreplica of the live document and inspects what Yjs integrated, before GC and merge.ccc:collab-update-refused:<rule>orccc:collab-update-unresolved. Refusal rules:fromYdocthrow;'default';updateevents, rebuilt from live plus in-flight frames after a refusal, and audits stored content once at load in report-only mode.COLLAB_UPDATE_GUARD=enforce|report.content-rules.ts: the schema-drivencheckElement/checkTree, which mirror y-tiptap'screateNodeFromYElement/createTextNodesFromYTextthrough the public PM API. It also holdsSTRING_ATTRS, the iterativecheckValue, andassertCollabSafeContentfor HTTP JSON (400 content_not_allowed;422 content_too_complexpast element depth 128).authz/request-controls/400 invalid_charactersfor a NUL or lone surrogate in a JSON body, query or params, before the handler runs.PostgresErrorfilter maps 22P05, 22021 and json/unicode 22P02 to 400.authz/page-write/storeSafeJsonandstableStringifystop at depth 512.buildPrelimContentrunsassertCollabSafeContent.Seams
parseProsemirrorContentrunsassertCollabSafeContent, andupdate()parses before its row write.page-editor.tsxpasses the CLOSE reason andsync-acked, and renders the refusal notice.Client
editor-ux/collab-access.ts.collab-refusal-notice.tsxoffers 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:
/v1idempotency ledger;/v1that browsers silently deleted on open;Scope
authz/collab-ingress/,authz/request-controls/,authz/page-write/andapps/client/src/features/editor-ux/.check-upstream-boundary.shpasses.Tests
The commits are ordered red-first:
a9e0066fholds only the specs, and the fix comes ina6af3d9aand8c2c1ef3.FORK_SPEC_ROOTSlaneAUTHZ_REQUIRE_PG=1)editor-ux)/v1returns the new 400s.🤖 Generated with Claude Code