Problem/Motivation
In my case, it was the following use case that triggered the issue:
I have a process of two forms in a dialog, the first is a customized login form, that is submitted, the user is logged in, the session regenerated, then my ajax callback of the submit button is called, where I immediately build a new form and return that to the user.
That works perfect well, but the second form then can't be submitted, because it fails on form token. On those ajax requests, the user does not have a csrf token in the session, despite getting one generated when the form was built.
The reason is that session regenerating somehow re-initializes $_SESSION and detaches it from the symfony session meta bag, so an updated there isn't reflected in the session.
See
https://gist.github.com/Berdir/9d8739e5962a227dfdae
Proposed resolution
@znerol said in the link above:
Bags are references on $_SESSION['bag_name'], so maybe those references need to be refreshed after the call to session_id. I guess that SessionManager::startNow() is the culprit, because that tries to transfer session data by copying it. Maybe it is enough to call parent::loadSession() after restoring the session data?
Remaining tasks
None.
User interface changes
None.
API changes
None.
Beta phase evaluation
| Issue category | Bug |
|---|---|
| Issue priority | Critical because it prevents data loss of session data set immediately after login |
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | csrf-2437761-6.patch | 3.62 KB | dom. |
| #2 | csrf-2437761-2--test-only.patch | 3.11 KB | dom. |
| #2 | csrf-2437761-2.patch | 3.55 KB | dom. |
Comments
Comment #1
almaudoh commentedThis issue will be fixed by the patch at #2228393-62: Decouple session from cookie based user authentication
Comment #2
dom. commentedRe-open to relieve #2228393: Decouple session from cookie based user authentication. Patch there corrects to much issues at once. Let's solve this here.
Comment #4
dom. commentedComment #5
znerol commentedFantastic work so far!
I think
testDataPersistence()is not quite the right place for this assertions. One option is to find a place intestSessionSaveRegenerate(), thought that is already quite convoluted. Probably a cleaner and lower risk option would be to add a specific test method which simply performs a login and then checks whether the value added from withinhook_user_loginis present.Perhaps something like this:
Comment #6
dom. commentedChanged as per #5
Comment #7
znerol commentedGreat. This is RTBC if testbot if testbot permits it.
Comment #8
alexpottThis issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed abf2467 and pushed to 8.0.x. Thanks!
Fixed indentation on commit.