I wrote a package for subdomain localization. But out of nowhere decrypting cookies is not working anymore.
My locale test website was working, but I needed to unsecure it to use Laravel valet share. Now when I changed it to valet secure again, my website does not work anymore. I get the ErrorException:
unserialize(): Error at offset 0 of 2 bytes
in
//Illuminate/Encryption/Encrypter.php
Row 149. return $unserialize ? unserialize($decrypted) : $decrypted;
I don't know why. I did not change my app_key, I deleted all cookies for my page but still, it does not work (and it worked perfectly for the last 3 weeks).
If you have a look here or the shortened code:
return decrypt(request()->cookie('tongue-locale'));
You see that I'm decrypting my content of the cookie. If you are curious why I need to decrypt my cookie, that is because the middleware "\App\Http\Middleware\EncryptCookies::class," is kicking later in.
Does anyone know why it is not working?
I don't know what happened, but I needed to change my code into this:
app('encrypter')->decrypt(request()->cookie(self::COOKIE), false);
With "false" the unserialize is ignored. But still, I would love to know why it is not working.
If you translate this part
return $unserialize ? unserialize($decrypted) : $decrypted;
with variables $unserialize = true and $decrypted = "de" it's clear that it fails, but I wonder why it did not before..
I fixed the issue using this solutions: https://laravel.com/docs/5.6/upgrade#upgrade-5.6.30
Add this line:
protected static $serialize = true;
To app\Http\Middleware\EncryptCookies.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With