Repository navigation
Conversation
kynrek
requested review from
max-nextcloud,
mejo- and
silverkszlo
as code owners
November 23, 2026 19:48
Author
|
/backport to stable35 |
mejo-
reviewed
Nov 26, 2026
mejo-
left a comment
Member
There was a problem hiding this comment.
Thanks for the contribution @kynrek. The changes look good to me and indeed fix the described problem.
The PR needs a manual rebase as the unit test file on main branch changed in the meantime. Unfortunately I lack permissions to push directly into your PR. Can you do the rebase yourself or grant me editing permissions to the PR?
When the editor runs without a logged-in user (direct editing, e.g. from the Android app), push/sync/save activate the text session's user for the request. Using setUser() wrote that user into the shared PHP session. When two requests of the same editor overlapped, the second one found a user_id without an auth token, the server logged the session out and cleared it, and all following requests failed the CSRF check with 412. The client treats a 412 as an outdated document and shows the "file was overwritten" conflict, even with a single editor. A request-scoped user is all these endpoints need. Fixes nextcloud#9684 Assisted-by: ClaudeCode:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q367ozke3eY15mEffZoDEG Signed-off-by: kynrek <35751552+kynrek@users.noreply.github.com>
kynrek
force-pushed
the
fix/direct-editing-csrf-session
branch
from
November 26, 2026 16:09
7ad71e3 to
aa608e7
Compare
Author
This branch has not been deployed
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.
📝 Summary
When the editor runs without a logged-in user (direct editing, e.g. the Nextcloud Android app),
push/sync/saveactivate the text session's user viaIUserSession::setUser(), which writesuser_idinto the shared PHP session. If two requests of the same editor overlap (a push during an autosave), the second one findsuser_idwith no auth token behind it,validateSession()logs out and clears the session, and every following request fails with412 CSRF check failed. The client treats that 412 as an outdated document and shows "The file was overwritten", even with a single editor.The change uses
setVolatileActiveUser()(OCP since 29), so the session user is only active for the current request and the PHP session is not touched. Logged-in requests are unchanged:loginSessionUser()still does nothing for them.How to verify
POST /ocs/v2.php/apps/files/api/v1/directEditing/open,editorId=text) and load the returned URL without credentials.pushandsaverequests (script in Direct editing: overlapping push/save logs the editor's PHP session out (CSRF 412), causing a false "The file was overwritten" conflict #9684).412 {"message":"CSRF check failed"}within 20 s. After: none (0 of ~1,400 on our instance), saves still land and are attributed to the editing user.Tested on a live instance
Nextcloud 35.0.2 / Text 9.0.2 with this patch, two Android phones (Nextcloud Android 35.1.0, direct editing) on a shared note:
Two client-side issues seen during these tests are unrelated to this change and already fixed on
main/stable35: after a reconnect, the file is only written on the next edit (#9630), and changes typed just before the app is killed are not pushed after recovery (likely #9589).🖼️ Screenshots
No UI change. The conflict banner this removes is shown in #9684.
🚧 TODO
🏁 Checklist
npm run lint/npm run stylelint/composer run cs:check)🤖 AI (if applicable)
The root cause analysis, fix, test and this description were drafted with Claude Code. The fix has been running on our 35.0.2 instance (Text 9.0.2) since 2026-11-22, where the race test above went from ~45% failures to 0.
Testing details
tests/unit/Controller/SessionControllerTest.php: without a logged-in user, push/sync/save must callsetVolatileActiveUser()(user, then the previous user) and neversetUser(); with a logged-in user, neither is called. The not-logged-in cases fail on the old code.master(SQLite, PHP 8.3): 179 tests, 3 skipped (Oracle only), 0 failures.composer run cs:checkandcomposer run psalm: no errors.🤖 Generated with Claude Code
https://claude.ai/code/session_01Q367ozke3eY15mEffZoDEG