mindshape-GmbH / mindshape_cookie_consent

This extension provides functionality to create a customizable cookie consent for your website. It is developed for flexibility to be customized in accordance to your data security guidelines.
10 stars 13 forks source link

Error: Return value of Mindshape\MindshapeCookieConsent\Utility\CookieUtility::getCookieValue() must be of the type array or null, bool returned #43

Closed klodeckl closed 11 months ago

klodeckl commented 1 year ago

Hi,

my TYPO3 log gets floodes with messages like:

Core: Exception handler (WEB): Uncaught TYPO3 Exception: Return value of Mindshape\MindshapeCookieConsent\Utility\CookieUtility::getCookieValue() must be of the type array or null, bool returned | TypeError thrown in file /xyz/typo3conf/ext/mindshape_cookie_consent/Classes/Utility/CookieUtility.php in line 34. Requested URL: https://www.tld.com/path/

Currently I don’t know how to reproduce the issue myself.

TYPO3 10, mindshape_cookie_consent 2.2.5

featdd commented 1 year ago

Hi @klodeckl,

the only explenation I currently have in mind that some users have a mess in their cookie value and the json_decode just returns a boolean.

Anyway, I will try to adjust this to prevent this exception.

Greetings Daniel

klodeckl commented 1 year ago

Thank you! :) But how could get mess in the cookie value?

klodeckl commented 1 year ago

I changed the function now to the following:

if (false === self::hasCookie($name) || is_bool(json_decode($_COOKIE[$name], true)) === true) { return null; }

return json_decode($_COOKIE[$name], true);

I will check if the error won’t occur anymore now. Maybe instead of is_bool === true it would be better to check for is_array || is_null === false.

featdd commented 11 months ago

Hi @klodeckl,

I solved this here: 22bfbf2fa313ee5378da679b3d850805f0e0d6c2

This shouldn't happen except a user/script/adblocker tries to manipulate the consent cookie somehow, but this should make it safe now. (Broken cookies will also be ignored by the JavaScript prompting the modal and save it properly)

Greetings Daniel

featdd commented 10 months ago

Hi @klodeckl,

an update with this fix is now released in TER.

Greetings Daniel

klodeckl commented 10 months ago

Thank you!