Commit 000db11
authored
fix: clear all session entries in SessionStore::purge() regardless of key order (#851)
### 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
- [x] This change adds unit test coverage
- [x] This change has been tested on the latest version of the
platform/language
### Contributor Checklist
- [x] I have read the [Auth0 general contribution
guidelines](https://github.com/auth0/open-source-template/blob/master/GENERAL-CONTRIBUTING.md)
- [x] I have read the [Auth0 code of
conduct](https://github.com/auth0/open-source-template/blob/master/CODE-OF-CONDUCT.md)1 parent 74d502c commit 000db11
2 files changed
Lines changed: 50 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
99 | | - | |
100 | | - | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
101 | 103 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
| 104 | + | |
107 | 105 | | |
108 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
16 | 19 | | |
17 | 20 | | |
18 | 21 | | |
| |||
75 | 78 | | |
76 | 79 | | |
77 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
78 | 119 | | |
79 | 120 | | |
80 | 121 | | |
| |||
0 commit comments