Skip to content

Commit 6c0f7da

Browse files
bug #47130 [HttpFoundation] Fix invalid ID not regenerated with native PHP file sessions (BrokenSourceCode)
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [HttpFoundation] Fix invalid ID not regenerated with native PHP file sessions | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #46993, #47126 | License | MIT Inside the [`SessionHandlerProxy`](https://github.com/symfony/symfony/blob/818d4dda7de778726123bc6bd49488959d4186e7/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php) class, the code defines `$this->saveHandlerName` to `\ini_get('session.save_handler')` when `$handler` is an instance of [`\SessionHandler`](https://www.php.net/manual/en/class.sessionhandler.php). https://github.com/symfony/symfony/blob/818d4dda7de778726123bc6bd49488959d4186e7/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php#L24-L25 But inside the [`NativeSessionStorage`](https://github.com/symfony/symfony/blob/818d4dda7de778726123bc6bd49488959d4186e7/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php) class, the code create an instance of [`StrictSessionHandler`](https://github.com/symfony/symfony/blob/818d4dda7de778726123bc6bd49488959d4186e7/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/StrictSessionHandler.php) that doesn't inherit from [`\SessionHandler`](https://www.php.net/manual/en/class.sessionhandler.php) and is passed to the [`SessionHandlerProxy`](https://github.com/symfony/symfony/blob/818d4dda7de778726123bc6bd49488959d4186e7/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/SessionHandlerProxy.php) constructor. https://github.com/symfony/symfony/blob/818d4dda7de778726123bc6bd49488959d4186e7/src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php#L422-L424 Therefore, we could create a `isWrapper()` method inside the [`StrictSessionHandler`](https://github.com/symfony/symfony/blob/818d4dda7de778726123bc6bd49488959d4186e7/src/Symfony/Component/HttpFoundation/Session/Storage/Handler/StrictSessionHandler.php) class to check if the wrapped handler is an internal PHP session handler ([`\SessionHandler`](https://www.php.net/manual/en/class.sessionhandler.php)), just like [`AbstractProxy::isWrapper()`](https://github.com/symfony/symfony/blob/818d4dda7de778726123bc6bd49488959d4186e7/src/Symfony/Component/HttpFoundation/Session/Storage/Proxy/AbstractProxy.php#L50). That's the only solution I have in mind right now. Commits ------- 4775c88 [HttpFoundation] Fix invalid ID not regenerated with native PHP file sessions
2 parents 42938ef + 4775c88 commit 6c0f7da

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

src/Symfony/Component/HttpFoundation/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
*/

src/Symfony/Component/HttpFoundation/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 <drak@zikula.org>
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
/**

src/Symfony/Component/HttpFoundation/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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy