Fix editor save handling for expired sessions#1412
Open
TeaTinyTool wants to merge 1 commit into
Open
Conversation
Prevent the editor from showing `Saved Successfully` when the session has expired or the CSRF token is stale. Expired save requests now return an explicit error response instead of the login page. Stale CSRF tokens are refreshed without auto-saving, so the user has to click save again intentionally before the file is written.
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
This fixes a misleading success message in the editor save flow when the session has expired or when the editor still uses an outdated CSRF token.
Problem
Currently, JSON/AJAX save requests are handled only after the login check. If the session has expired, the login page can be returned with HTTP 200. The JavaScript success handler may then show
Saved Successfully, although the file was not saved.This is not only a cosmetic issue. I have personally lost editor changes several times because the UI reported a successful save while the file was not actually written.
There is a second related case: after logging in again in another tab, an already open editor can still contain an outdated CSRF token.
Changes
application/jsonAJAX save requests before the normal login check.X-CSRF-Tokenresponse header.text/plainwithCache-Control: no-store.X-TFM-Save-Success: 1as a clear server-side confirmation for successful saves.Saved Successfullyonly when this success header is present, or as a compatibility fallback when the trimmed server response is exactly1.Expected behavior
Notes
This change is limited to the editor save flow and should not affect normal form posts or uploads.