Skip to content

Commit 2fa11a0

Browse files
BrokenSourceCodenicolas-grekas
authored andcommitted
[HttpFoundation] Fix invalid ID not regenerated with native PHP file sessions
1 parent 9bc83c2 commit 2fa11a0

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Session/Storage/Handler/StrictSessionHandler.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ public function __construct(\SessionHandlerInterface $handler)
3030
$this->handler = $handler;
3131
}
3232

33+
/**
34+
* Returns true if this handler wraps an internal PHP session save handler using \SessionHandler.
35+
*
36+
* @internal
37+
*/
38+
public function isWrapper(): bool
39+
{
40+
return $this->handler instanceof \SessionHandler;
41+
}
42+
3343
/**
3444
* @return bool
3545
*/

Session/Storage/Proxy/SessionHandlerProxy.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\HttpFoundation\Session\Storage\Proxy;
1313

14+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
15+
1416
/**
1517
* @author Drak <[email protected]>
1618
*/
@@ -22,7 +24,7 @@ public function __construct(\SessionHandlerInterface $handler)
2224
{
2325
$this->handler = $handler;
2426
$this->wrapper = $handler instanceof \SessionHandler;
25-
$this->saveHandlerName = $this->wrapper ? \ini_get('session.save_handler') : 'user';
27+
$this->saveHandlerName = $this->wrapper || ($handler instanceof StrictSessionHandler && $handler->isWrapper()) ? \ini_get('session.save_handler') : 'user';
2628
}
2729

2830
/**

Tests/Session/Storage/Proxy/SessionHandlerProxyTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\HttpFoundation\Tests\Session\Storage\Proxy;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\HttpFoundation\Session\Storage\Handler\StrictSessionHandler;
16+
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
1517
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
1618

1719
/**
@@ -159,6 +161,23 @@ public function testUpdateTimestamp()
159161

160162
$this->proxy->updateTimestamp('id', 'data');
161163
}
164+
165+
/**
166+
* @dataProvider provideNativeSessionStorageHandler
167+
*/
168+
public function testNativeSessionStorageSaveHandlerName($handler)
169+
{
170+
$this->assertSame('files', (new NativeSessionStorage([], $handler))->getSaveHandler()->getSaveHandlerName());
171+
}
172+
173+
public function provideNativeSessionStorageHandler()
174+
{
175+
return [
176+
[new \SessionHandler()],
177+
[new StrictSessionHandler(new \SessionHandler())],
178+
[new SessionHandlerProxy(new StrictSessionHandler(new \SessionHandler()))],
179+
];
180+
}
162181
}
163182

164183
abstract class TestSessionHandler implements \SessionHandlerInterface, \SessionUpdateTimestampHandlerInterface

0 commit comments

Comments
 (0)