Skip to content

Commit

Permalink
Merge pull request #47 from gelysis/exceed-cookielength-fix
Browse files Browse the repository at this point in the history
Added data unset to stop data being read from outdated cookie
  • Loading branch information
ScopeyNZ authored Feb 7, 2019
2 parents 5a5c3b0 + ac404c9 commit ec86442
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/Store/CookieStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,27 @@ protected function canWrite()

public function write($session_id, $session_data)
{
$canWrite = $this->canWrite();
$isExceedingCookieLimit = (strlen($session_data) > static::config()->get('max_length'));
$crypto = $this->getCrypto($session_id);

// Check ability to safely encrypt and write content
if (!$this->canWrite()
|| (strlen($session_data) > static::config()->get('max_length'))
|| !($crypto = $this->getCrypto($session_id))
) {
if (!$canWrite || $isExceedingCookieLimit || !$crypto) {
if ($canWrite && $isExceedingCookieLimit) {
$params = session_get_cookie_params();
// Clear stored cookie value and cookie when length exceeds the set limit
$this->currentCookieData = null;
Cookie::set(
$this->cookie,
'',
0,
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
}

return false;
}

Expand Down

0 comments on commit ec86442

Please sign in to comment.