Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3765d8a

Browse files
committed
bug #15799 [HttpFoundation] NativeSessionStorage regenerate method wrongly sets storage as started (iambrosi)
This PR was squashed before being merged into the 2.3 branch (closes #15799). Discussion ---------- [HttpFoundation] NativeSessionStorage `regenerate` method wrongly sets storage as started | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | This PR fixes an error when regenerating session IDs for non-active sessions. Right now, the session is flagged as _started_, no matter if the session ID was successfully regenerated or not, making the storage [unable to _start the session_](https://github.com/symfony/symfony/blob/6393ec31690a3ecc73e5f1f7ea2185cda7aba203/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php#L130-L132) later on. This also fixes a future error with PHP 7, which throws an error if a regeneration is attempted for non-active sessions. ``` session_regenerate_id(): Cannot regenerate session id - session is not active ``` Commits ------- 8e6ef9c [HttpFoundation] NativeSessionStorage method wrongly sets storage as started
2 parents 6600aef + 8e6ef9c commit 3765d8a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ public function setName($name)
195195
*/
196196
public function regenerate($destroy = false, $lifetime = null)
197197
{
198+
// Cannot regenerate the session ID for non-active sessions.
199+
if (PHP_VERSION_ID >= 50400 && \PHP_SESSION_ACTIVE !== session_status()) {
200+
return false;
201+
}
202+
203+
// Check if session ID exists in PHP 5.3
204+
if (PHP_VERSION_ID < 50400 && '' === session_id()) {
205+
return false;
206+
}
207+
198208
if (null !== $lifetime) {
199209
ini_set('session.cookie_lifetime', $lifetime);
200210
}

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ public function testSessionGlobalIsUpToDateAfterIdRegeneration()
130130
$this->assertEquals(42, $_SESSION['_sf2_attributes']['lucky']);
131131
}
132132

133+
public function testRegenerationFailureDoesNotFlagStorageAsStarted()
134+
{
135+
$storage = $this->getStorage();
136+
$this->assertFalse($storage->regenerate());
137+
$this->assertFalse($storage->isStarted());
138+
}
139+
133140
public function testDefaultSessionCacheLimiter()
134141
{
135142
$this->iniSet('session.cache_limiter', 'nocache');

0 commit comments

Comments
 (0)