whitecube / laravel-cookie-consent

Register, configure and ask for cookies consent in a EU-compliant way
MIT License
352 stars 42 forks source link

cookie encryption must be disabled #17

Open gaud2029 opened 1 year ago

gaud2029 commented 1 year ago

this will not work with cookie encryption enabled, you need to add them to your cookieEncrypt middleware exceptions

toonvandenbos commented 1 year ago

Hi @gaud2029,

Thanks for bringing this up. Did you have the opportunity to dig a bit deeper and figure out why the package does not work with cookie encryption enabled? If so, do you mind sharing your findings? If not, I'll try to have a look but I'm not sure I'll be able to do so shortly. Thanks!

rickyjohnston commented 8 months ago

If this helps any - I've just bumped into this issue. Not sure why, because I have two projects using this package and one of them works fine without this.

In the project that's having an issue, inside the CookiesManager, if I spit out the result of json_decode($raw, true) on the encrypted cookie:

    /**
     * Retrieve the eventual existing cookie data.
     */
    protected function getCurrentConsentSettings(Request $request): ?array
    {
        $preferences = ($raw = $request->cookie(config('cookieconsent.cookie.name')))
            ? json_decode($raw, true)
            : null;
+.       dd(json_decode($raw, true));

        if (! $preferences || ! is_int($preferences['consent_at'] ?? null)) {
            return null;
        }

then I see that that's evaluating to null:

Screenshot 2024-03-28 at 20 40 28

And this is what's causing the settings to behave as if they don't exist at all.

tiagocpeixoto commented 1 month ago

this will not work with cookie encryption enabled, you need to add them to your cookieEncrypt middleware exceptions

In AppServiceProvider.php:

$consentCookieName = config('cookieconsent.cookie.name');
EncryptCookies::except([$consentCookieName]);