Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Session Proxy does not proxy #27674

Copy link
Copy link
Closed
Closed
Copy link
@dustinsorensen

Description

@dustinsorensen
Issue body actions

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.