Repository navigation
Conversation
reGenerateID() only changed the session cookie value and left every per-key row (application keys, _meta, _user) orphaned under the old ID. In the session-fixation login flow (reGenerateID() then setUser() with no close()), the new ID ended up with only _user; on the next request start() saw no _meta, treated the new ID as brand-new, and lost the user and all session data. reGenerateID() now migrates the full session state to the new ID: snapshot all rows under the old ID (decrypting with the old ID; _meta is a plain array copied as-is), switch the cookie to the new ID, re-write every key re-encrypted under the new ID (encryption is keyed by session ID), then destroy the old ID's rows. Adds a regression test covering the user and multiple custom keys surviving reGenerateID() without an intervening close().
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #423 +/- ##
============================================
+ Coverage 81.75% 81.94% +0.19%
- Complexity 3288 3293 +5
============================================
Files 106 106
Lines 9721 9735 +14
============================================
+ Hits 7947 7977 +30
+ Misses 1774 1758 -16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Migrate the full per-key session state to the new ID inside
reGenerateID()so regenerating the session ID during a request no longer orphans data.Motivation
reGenerateID()only changed the session cookie value; it did not migrate any per-key rows to the new ID. In the standard session-fixation login flow —reGenerateID()thensetUser()without aclose()before the request ends (the start-session middleware'safterSend()only callsvalidateStorage()) — the new ID ended up with only the eagerly-written_userkey, while_meta, the user's companion state and all previously stored application keys stayed under the old ID. On the next request,start()reads_metafor the new ID, findsnull, treats it as a brand-new session and loses the authenticated user and all session data. Fixes #422 (follow-up to the #418 user-persistence fix).Changes
Session::reGenerateID()now migrates the entire session state to the new ID:readAll(), decrypting each value with the old ID (_metais a plain array and is copied as-is).destroy()the old ID's rows so no orphaned/duplicate state remains.UI Changes
Not applicable.
How to Test / Verify
New regression test in
tests/WebFiori/Framework/Tests/Session/SessionTest.php:testSessionStateSurvivesRegenerateIdWithoutClose— sets custom keys (csrf,cart,lang_pref), runsreGenerateID()thensetUser()with noclose(), resumes the new ID, and asserts the user AND all custom keys survive, and thatgetVars()excludes reserved keys.Verified the related session tests together (user persistence, reserved-key guards, and this regression): 4 tests / 32 assertions passing. The regression test fails on the pre-fix code and passes after.
Breaking Changes and Migration Steps
None. This only changes internal behavior of
reGenerateID()to preserve state that previously would have been lost.Checklist
Related issues
Closes #422