Skip to content

fix(notes): turn a panic while applying a step into ErrCannotApply - #5159

Open
shepilov wants to merge 1 commit into
masterfrom
fix/notes-step-apply-panic
Open

shepilov wants to merge 1 commit into
masterfrom
fix/notes-step-apply-panic

Conversation

@shepilov

@shepilov shepilov commented Nov 3, 2026

Copy link
Copy Markdown
Member

Fixes #5130

Problem

prosemirror-go does not fully validate the steps sent by clients. A replaceAround step whose insert is outside its slice (e.g. insert: -1 with openStart: 1) panics with an index out of range in model.replace, so PATCH /notes/:id answers with a 500. Any client that can edit a note can send it, including the recipient of a shared note.

Solution

apply now calls each step through applyStep, which turns a panic into a failed step. The client gets ErrCannotApply (409) and the note is not modified, as for any step that cannot be applied. The notes lock is still released by its defer.

Validating the steps in prosemirror-go itself would be a larger change in another repository; the recover also guards against the other unchecked indexes of the library. StepFromJSON was probed with malformed steps (wrong types, missing fields, unknown step types): it returns errors and does not panic, so it is left as is.

The Markdown import panic of the same fuzzing campaign (#5129) is fixed by #5152; this PR does not conflict with it.

Test plan

prosemirror-go does not fully validate the steps sent by clients. A
replaceAround step whose insert is outside its slice panics with an
index out of range in model.replace, so PATCH /notes/:id answered with
a 500. A panic while applying a step is now turned into a failed step:
the client gets ErrCannotApply (409) and the note is not modified.

Fixes #5130
@shepilov
shepilov requested a review from taratatach as a code owner November 3, 2026 15:17

This branch has not been deployed

No deployments
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.

Notes: PATCH /notes/:id with a replaceAround step whose insert is out of the slice panics in prosemirror-go (index out of range, 500)

1 participant