Fix cookie login token mismatch error #33769
Closed
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.
Either because of concurrency or due to a malicious actor, it is possible that Nextcloud receives a request with set, but invalid cookies. Those are
nc_username,nc_tokenandnc_session_id.\OC::handleLogintriggers this logic.The verification logic works as expected. We don't let a request pass that doesn't have valid values for those three cookies.
However, the error handling is bogus. If a legitimate user runs into the situation where the
nc_tokendoes no longer exist in the stored user keys, they are sent to the login page in an infinite loop.How to test
In the browser
This scenario is hard to trigger inside a browser, but not impossible.
masteror this branchDELETE FROM oc_preferences WHERE appid = 'login_token';to clear login tokens from the databaseOn master: endless login loop. This doesn't happen every time. But if it happens the user is doomed until the clear cookies.
On this branch: login works at the second attempt. That is because the first login detects the invalid token and restarts the session. That generates new tokens and the second login works. This isn't great either, but the users have a way out of the login loop.
With Curl
On master: the failed login request does not clear
nc_*cookies.On this branch the (possibly invalid but certainly useless) cookies are cleared.