Skip to content

Instantly share code, notes, and snippets.

@halaei
Created August 2, 2020 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save halaei/1821183f7e3a2975b067b7985aaa9fec to your computer and use it in GitHub Desktop.
Save halaei/1821183f7e3a2975b067b7985aaa9fec to your computer and use it in GitHub Desktop.
AllowMissingPrefixForEncryptCookies
<?php
/**
* The name of the cookies that are safe not to be protected by value prefix.
*
* @see https://blog.laravel.com/laravel-cookie-security-releases
*
* @var string[]
*/
protected $allowMissingPrefix = [
'put name of remember me cookie here',
];
protected function decrypt(Request $request)
{
foreach ($request->cookies as $key => $cookie) {
if ($this->isDisabled($key)) {
continue;
}
try {
$value = $this->decryptCookie($key, $cookie);
$hasValidPrefix = strpos($value, CookieValuePrefix::create($key, $this->encrypter->getKey())) === 0;
if ($hasValidPrefix) {
$value = CookieValuePrefix::remove($value);
} elseif (! in_array($key, $this->allowMissingPrefix, true)) {
$value = null;
}
$request->cookies->set($key, $value);
} catch (DecryptException $e) {
$request->cookies->set($key, null);
}
}
return $request;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment