Repository navigation
Conversation
The per-key session migration stopped persisting the session user: it was kept only as an in-memory property, so setUser() did not survive a close()+resume round-trip (persistMeta() writes only _meta, and start() reset the user to null). - Store the SessionUser under a new reserved '_user' key, serialized and encrypted via encryptValue() (honors encryption-at-rest with SESSION_KEY). Written on setUser() and close(); restored in start() via restoreUser(). - Add Session::RESERVED_KEYS = ['_meta','_user'] and assertNotReserved(). Mutating ops (set/remove/pull) now throw SessionException on a reserved key; read ops (get/has) remain allowed. - getVars(), refresh() and start()'s snapshot loop now skip all reserved keys, not just _meta, so _user never leaks into user-visible variables. Tests: user now survives resume (incl. info modified after setUser); and reserved keys reject mutation while allowing reads. Session group: 135 tests / 342 assertions passing.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #419 +/- ##
============================================
+ Coverage 81.68% 81.73% +0.05%
- Complexity 3279 3287 +8
============================================
Files 106 106
Lines 9685 9714 +29
============================================
+ Hits 7911 7940 +29
Misses 1774 1774
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
Persist the session user across resume and protect internal session keys from being modified through the public variable API.
Motivation
The per-key session migration stopped persisting the session user. It was kept only as an in-memory property, so
setUser()did not survive aclose()+ resume round-trip:persistMeta()writes only the_metakey, andstart()reset the user tonull. This was also untested (the onlygetUser()assertions were on brand-new sessions, two of them commented out).Changes
SessionUserunder a new reserved_userkey, serialized and encrypted viaencryptValue()so it honors encryption-at-rest whenSESSION_KEYis defined.setUser()and onclose()(to capture info modified aftersetUser()); removed when the user isnull.start()via a newrestoreUser()helper.Session::RESERVED_KEYS = ['_meta', '_user']and anassertNotReserved()guard.set(),remove(),pull()) now throwSessionExceptionon a reserved key.get(),has()) remain allowed.getVars(),refresh()andstart()'s snapshot loop now skip all reserved keys (not just_meta), so_usernever leaks into user-visible variables.UI Changes
Not applicable.
How to Test / Verify
Unit tests in
tests/WebFiori/Framework/Tests/Session/SessionTest.php:testUserIsPersistedAcrossResume— sets a user, modifies its email/display name, closes, resumes with the same session ID, and asserts id/username/email/displayName all survive.testReservedKeysRejectMutation—set/remove/pullon_meta/_userthrowSessionException.testReservedKeysAllowRead—get/hason reserved keys do not throw.Session test group: 135 tests / 342 assertions passing (19 pre-existing skips).
Breaking Changes and Migration Steps
None.
_metaand_userwere never valid application variable names in practice; using them now surfaces an explicitSessionExceptioninstead of silently colliding with internal state.Checklist
composer fix-cs)Related issues
Closes #418