fix: clear all session entries in SessionStore::purge() regardless of key order - #851
Open
kishore7snehil wants to merge 5 commits into
Open
fix: clear all session entries in SessionStore::purge() regardless of key order#851kishore7snehil wants to merge 5 commits into
kishore7snehil wants to merge 5 commits into
Conversation
… key order Iterate a snapshot of the session keys instead of walking the array with key()/next(), which stopped early when a falsy key (0 or "") appeared before the prefixed entries and left them in place.
nandan-bhat
reviewed
Aug 7, 2026
Restore purge() to not write to $_SESSION, and add coverage for a leading integer key plus assertions that non-Auth0 entries survive.
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.
Changes
SessionStore::purge()walked$_SESSIONwithwhile ($sessionKey = key($session))and advanced withnext(). That loop condition is also falsy when a session key is0or"", so if such a key appeared before the SDK's own prefixed entries, iteration stopped early and left the remainingauth0_*entries in the session. BecauseAuth0::logout()clears state throughpurge(), the leftover entries could persist after logout when the surrounding application had written a falsy-keyed value to$_SESSION.🐛 Bug Fix:
SessionStore::purge()now iterates a snapshot of the session keys viaarray_keys()instead of thekey()/next()cursor, so a falsy key can no longer terminate the loop early and every prefixed entry is removedstr_starts_with()guarded byis_string(). On v9 the previous loop already cast the key withmb_substr((string) $sessionKey, ...), so theis_string()guard here is hardening. The uncastmb_substr()path only exists on8.x, where dropping it is a genuineTypeErrorfix, so the8.xbackport is where that matterspurge()stays read-only and no longer touches$_SESSIONwhen it is unset, matching the prior behaviorReferences
N/A
Testing
Added
purge() clears values when a falsy key precedes them in the session, which seeds an empty-string and an integer0key before the prefixed entry and asserts the prefixed entry is removed while the non-Auth0 entries surviveAdded
purge() clears values when a falsy integer key precedes them in the session, covering thephp_serializeleading-integer-key case with no empty-string key presentReset
$_SESSIONinbeforeEachso the seeded falsy keys do not leak into other tests under randomized orderingThis change adds unit test coverage
This change has been tested on the latest version of the platform/language
Contributor Checklist