Skip to content

fix(id/web): validate INIT doc content entries against the mode schema (#7884) - #8508

Merged
dezren39 merged 2 commits into
mainfrom
queue/14237-7884-init-doc-validation
Nov 11, 2026
Merged

dezren39 merged 2 commits into
mainfrom
queue/14237-7884-init-doc-validation

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Fixes #7884.

Problem

The INIT frame handler in pkgs/id/web/src/collab.ts validated the doc only at the top level (type === "doc", content array if present). Content entries were never checked, so one unknown node/mark type, a non-string text node, or a non-object entry made Node.fromJSON throw inside initEditor, whose catch silently substituted an empty doc — a non-empty server document presented as an empty editable file (data-loss footgun on version skew).

Fix

At the INIT frame boundary, validate the doc against the modes schema: Node.fromJSON(getSchema(mode), doc) in a try/catch. A doc the schema cannot parse is dropped with a log at the boundary (session/socket intact, no editor initialized from it), mirroring the existing malformed-INIT drop path (#2824). Valid docs in every mode parse exactly as initEditor already parsed them, so behavior for valid docs is unchanged.

Tests

  • New regression test in collab.test.ts covering each probed case: unknown node type, unknown mark type, non-string text, numeric content entry — plus a valid rich-doc control asserting the text renders.
  • The shared validInit helper and one inline frame now use a code_block doc for raw mode: the raw schema only allows code_block nodes, and the previous paragraph-in-raw frame only passed because initEditor silently fell back to an empty doc — the exact behavior id(web/collab): INIT doc content entries unchecked — one unknown node/mark or non-string text silently discards the whole document and opens an empty editor #7884 removes.
  • collab.test.ts + editor.test.ts: 147/147 pass. Full pkgs/id web suite: 712 passed, 1 failed — search-panel accessibility test, verified identical on the clean tree (pre-existing, unrelated). Typecheck (tsc --noEmit) green.

Queue task 14237 (repo-health-code-pilot), lane code-e.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 03:53
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8fc252c4-d59e-488a-92d9-1f888d5f5cb6
Commits

Reviewing files that changed from the base of the PR and between 3cad9f8 and e1ed8d3.

Files selected for processing: 2

  • pkgs/id/web/src/collab.test.ts
  • pkgs/id/web/src/collab.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T10:56:05.146592Z e1ed8d3 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…-doc-validation

# Conflicts:
#	pkgs/id/web/src/collab.test.ts
#	pkgs/id/web/src/collab.ts
@dezren39
dezren39 merged commit d4eedc7 into main Nov 11, 2026
1 of 9 checks passed
@dezren39
dezren39 deleted the queue/14237-7884-init-doc-validation branch November 11, 2026 10:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant