Skip to content

Commit

Permalink
fix cookie issues
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jul 27, 2020
1 parent 4c7d118 commit bb9db21
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Cookie/Middleware/EncryptCookies.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function decrypt(Request $request)
$value = $this->decryptCookie($key, $cookie);

$request->cookies->set(
$key, strpos($value, sha1($key).'|') !== 0 ? null : substr($value, 41)
$key, strpos($value, sha1($key.'v2').'|') !== 0 ? null : substr($value, 41)
);
} catch (DecryptException $e) {
$request->cookies->set($key, null);
Expand Down Expand Up @@ -142,7 +142,7 @@ protected function encrypt(Response $response)
$response->headers->setCookie($this->duplicate(
$cookie,
$this->encrypter->encrypt(
sha1($cookie->getName()).'|'.$cookie->getValue(),
sha1($cookie->getName().'v2').'|'.$cookie->getValue(),
static::serialized($cookie->getName())
)
));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function getTokenFromRequest($request)
$token = $request->input('_token') ?: $request->header('X-CSRF-TOKEN');

if (! $token && $header = $request->header('X-XSRF-TOKEN')) {
$token = $this->encrypter->decrypt($header, static::serialized());
$token = substr($this->encrypter->decrypt($header, static::serialized()), 41);
}

return $token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ protected function prepareCookiesForRequest()
return array_merge($this->defaultCookies, $this->unencryptedCookies);
}

return collect($this->defaultCookies)->map(function ($value) {
return encrypt($value, false);
return collect($this->defaultCookies)->map(function ($value, $key) {
return encrypt(sha1($key.'v2').'|'.$value, false);
})->merge($this->unencryptedCookies)->all();
}

Expand Down

0 comments on commit bb9db21

Please sign in to comment.