Skip to content

fix: clear all session entries in SessionStore::purge() regardless of key order - #851

Open
kishore7snehil wants to merge 5 commits into
mainfrom
fix/session-store-purge-falsy-key
Open

fix: clear all session entries in SessionStore::purge() regardless of key order#851
kishore7snehil wants to merge 5 commits into
mainfrom
fix/session-store-purge-falsy-key

Conversation

@kishore7snehil

@kishore7snehil kishore7snehil commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Changes

SessionStore::purge() walked $_SESSION with while ($sessionKey = key($session)) and advanced with next(). That loop condition is also falsy when a session key is 0 or "", so if such a key appeared before the SDK's own prefixed entries, iteration stopped early and left the remaining auth0_* entries in the session. Because Auth0::logout() clears state through purge(), 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 via array_keys() instead of the key()/next() cursor, so a falsy key can no longer terminate the loop early and every prefixed entry is removed
  • The prefix check uses str_starts_with() guarded by is_string(). On v9 the previous loop already cast the key with mb_substr((string) $sessionKey, ...), so the is_string() guard here is hardening. The uncast mb_substr() path only exists on 8.x, where dropping it is a genuine TypeError fix, so the 8.x backport is where that matters
  • purge() stays read-only and no longer touches $_SESSION when it is unset, matching the prior behavior

References

N/A

Testing

  • Added purge() clears values when a falsy key precedes them in the session, which seeds an empty-string and an integer 0 key before the prefixed entry and asserts the prefixed entry is removed while the non-Auth0 entries survive

  • Added purge() clears values when a falsy integer key precedes them in the session, covering the php_serialize leading-integer-key case with no empty-string key present

  • Reset $_SESSION in beforeEach so the seeded falsy keys do not leak into other tests under randomized ordering

  • This change adds unit test coverage

  • This change has been tested on the latest version of the platform/language

Contributor Checklist

… 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.
@kishore7snehil
kishore7snehil requested a review from a team as a code owner August 6, 2026 14:10
Comment thread src/Store/SessionStore.php Outdated
Comment thread src/Store/SessionStore.php
Comment thread tests/Unit/Store/SessionStoreTest.php
Comment thread tests/Unit/Store/SessionStoreTest.php
Comment thread tests/Unit/Store/SessionStoreTest.php
@kishore7snehil
kishore7snehil changed the base branch from v9 to main August 12, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants