Merge pull request #10022 from xini/fix-session-destroy

take current request protocol into account when deleting session cookie
This commit is contained in:
Daniel Hensby 2021-08-06 10:06:08 +01:00 committed by GitHub
commit 83b458ff59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -245,7 +245,7 @@ class Session
*/
public function restart(HTTPRequest $request)
{
$this->destroy();
$this->destroy(true, $request);
$this->start($request);
}
@ -358,14 +358,18 @@ class Session
* Destroy this session
*
* @param bool $removeCookie
* @param HTTPRequest $request The request for which to destroy a session
*/
public function destroy($removeCookie = true)
public function destroy($removeCookie = true, HTTPRequest $request = null)
{
if (session_id()) {
if ($removeCookie) {
if (!$request) {
$request = Controller::curr()->getRequest();
}
$path = $this->config()->get('cookie_path') ?: Director::baseURL();
$domain = $this->config()->get('cookie_domain');
$secure = $this->config()->get('cookie_secure');
$secure = Director::is_https($request) && $this->config()->get('cookie_secure');
Cookie::force_expiry(session_name(), $path, $domain, $secure, true);
}
session_destroy();

View File

@ -112,6 +112,6 @@ class SessionAuthenticationHandler implements AuthenticationHandler
public function logOut(HTTPRequest $request = null)
{
$request = $request ?: Controller::curr()->getRequest();
$request->getSession()->destroy();
$request->getSession()->destroy(true, $request);
}
}