Closed
Description
Symfony version(s) affected: 3.4, 4.0, 4.1
Description
When using a Session Proxy with session management, the proxy methods aren't being triggered.
How to reproduce
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
use Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler;
use Symfony\Component\HttpFoundation\Session\Storage\Proxy\SessionHandlerProxy;
$proxy_called = false;
$callback = function () use (&$proxy_called) {
$proxy_called = true;
};
$session = new Session(
new NativeSessionStorage([],
new class(new NativeFileSessionHandler(), $callback) extends SessionHandlerProxy {
protected $callback;
public function __construct(\SessionHandlerInterface $handler, $callback) {
$this->callback = $callback;
parent::__construct($handler);
}
public function read($id) {
$callback = $this->callback;
$callback(); // never reaches this point
return parent::read($id);
}
public function write($id, $data) {
return parent::write($id, $data);
}
}
)
);
$session->start();
var_dump($proxy_called); // returns false
Possible Solution
In the following commit: symfony/http-foundation@55ca8d8 - the NativeFileSessionHandler:: setSaveHandler
was changed so that session_set_save_handler
uses the proxy's handler, and not the proxy itself. This completely bypasses the proxy class.
- if ($this->saveHandler instanceof \SessionHandlerInterface) {
+ if ($this->saveHandler instanceof SessionHandlerProxy) {
+ session_set_save_handler($this->saveHandler->getHandler(), false);
+ } elseif ($this->saveHandler instanceof \SessionHandlerInterface) {
session_set_save_handler($this->saveHandler, false);
}
}
Using a single session_set_save_handler($this->saveHandler, false);
should fix this problem.
Additional context
n/a
Metadata
Metadata
Assignees
Labels
No labels