Skip to content

Commit

Permalink
Fixed session cookie is being set twice in the HTTP header [#2745]
Browse files Browse the repository at this point in the history
  • Loading branch information
mahagr committed Dec 10, 2019
1 parent 842dc0d commit 3a8775f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# v1.6.20
## 12/04/2019
## mm/dd/2019

1. [](#bugfix)
* Incorrect routing caused by `str_replace()` in `Uri::init()` [#2754](https://github.com/getgrav/grav/issues/2754)
* Fixed incorrect routing caused by `str_replace()` in `Uri::init()` [#2754](https://github.com/getgrav/grav/issues/2754)
* Fixed session cookie is being set twice in the HTTP header [#2745](https://github.com/getgrav/grav/issues/2745)

# v1.6.19
## 12/04/2019
Expand Down
33 changes: 20 additions & 13 deletions system/src/Grav/Framework/Session/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,13 @@ public function start($readonly = false)
return $this;
}

$sessionName = session_name();
$sessionExists = isset($_COOKIE[$sessionName]);

// Protection against invalid session cookie names throwing exception: http://php.net/manual/en/function.session-id.php#116836
if (isset($_COOKIE[session_name()]) && !preg_match('/^[-,a-zA-Z0-9]{1,128}$/', $_COOKIE[session_name()])) {
unset($_COOKIE[session_name()]);
if ($sessionExists && !preg_match('/^[-,a-zA-Z0-9]{1,128}$/', $_COOKIE[$sessionName])) {
unset($_COOKIE[$sessionName]);
$sessionExists = false;
}

$options = $this->options;
Expand All @@ -202,17 +206,20 @@ public function start($readonly = false)
throw new SessionException('User Invalid', 500);
}

$params = session_get_cookie_params();

setcookie(
session_name(),
session_id(),
time() + $params['lifetime'],
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
// Extend the lifetime of the session.
if ($sessionExists) {
$params = session_get_cookie_params();

setcookie(
$sessionName,
session_id(),
time() + $params['lifetime'],
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
}

$this->started = true;

Expand Down

0 comments on commit 3a8775f

Please sign in to comment.