diff --git a/module/VuFind/src/VuFind/Service/Factory.php b/module/VuFind/src/VuFind/Service/Factory.php index 27f6e2239dbc26bcdfcfa4ecde15a13991661564..6593137e45e7fc47d4a1d3e4d9f0f81c8d5bbb23 100644 --- a/module/VuFind/src/VuFind/Service/Factory.php +++ b/module/VuFind/src/VuFind/Service/Factory.php @@ -205,6 +205,9 @@ class Factory && $config->Cookies->limit_by_path ) { $path = $sm->get('Request')->getBasePath(); + if (empty($path)) { + $path = '/'; + } } $secure = isset($config->Cookies->only_secure) ? $config->Cookies->only_secure diff --git a/module/VuFind/src/VuFind/Session/AbstractBase.php b/module/VuFind/src/VuFind/Session/AbstractBase.php index 26b545dab8c7ae946283fa37a1ad3cd4d02cf1fa..748a7491287911c701302297e953b6f075ccfd16 100644 --- a/module/VuFind/src/VuFind/Session/AbstractBase.php +++ b/module/VuFind/src/VuFind/Session/AbstractBase.php @@ -66,6 +66,16 @@ abstract class AbstractBase implements SaveHandlerInterface, */ protected $writesDisabled = false; + /** + * Enable session writing (default) + * + * @return void + */ + public function enableWrites() + { + $this->writesDisabled = false; + } + /** * Disable session writing, i.e. make it read-only * diff --git a/module/VuFind/src/VuFind/Session/ManagerFactory.php b/module/VuFind/src/VuFind/Session/ManagerFactory.php index f779d974a39c35e26cf8e7c01724934f083eb05f..4210d729bd32c02c2e7b46f29c256cec98f865a2 100644 --- a/module/VuFind/src/VuFind/Session/ManagerFactory.php +++ b/module/VuFind/src/VuFind/Session/ManagerFactory.php @@ -128,6 +128,23 @@ class ManagerFactory implements \Zend\ServiceManager\FactoryInterface // Start up the session: $sessionManager->start(); + // Verify that any existing session has the correct path to avoid using + // a cookie from a service higher up in the path hierarchy. + $storage = new \Zend\Session\Container('SessionState', $sessionManager); + if (null !== $storage->cookiePath) { + if ($storage->cookiePath != $sessionConfig->getCookiePath()) { + // Disable writes temporarily to keep the existing session intact + $sessionManager->getSaveHandler()->disableWrites(); + // Regenerate session ID and reset the session data + $sessionManager->regenerateId(false); + session_unset(); + $sessionManager->getSaveHandler()->enableWrites(); + $storage->cookiePath = $sessionConfig->getCookiePath(); + } + } else { + $storage->cookiePath = $sessionConfig->getCookiePath(); + } + // Check if we need to immediately stop it based on the settings object // (which may have been informed by a controller that sessions should not // be written as part of the current process):