From 9d1e9a8d47230b8f774eebf95cb53c295506ccf3 Mon Sep 17 00:00:00 2001 From: Andrew Welch Date: Mon, 12 Feb 2024 15:42:30 -0500 Subject: [PATCH] fix: Fixed an issue where the `samesite` option defaulted to a `bool` when it should have defaulted to the string `Lax` --- src/services/CookiesService.php | 5 ++--- src/twigextensions/CookiesTwigExtension.php | 6 +++--- src/variables/CookiesVariable.php | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/services/CookiesService.php b/src/services/CookiesService.php index 1f75906..f5f1678 100644 --- a/src/services/CookiesService.php +++ b/src/services/CookiesService.php @@ -79,7 +79,7 @@ public function setSecure( string $domain = '', bool $secure = false, bool $httpOnly = false, - bool $sameSite = false, + string $sameSite = 'Lax', ): void { if (empty($value)) { @@ -131,8 +131,7 @@ public function getSecure(string $name = ''): string } if ( - $cookie - && !empty($cookie->value) + !empty($cookie->value) && $data !== false ) { $result = unserialize(base64_decode($data), ['allowed_classes' => false]); diff --git a/src/twigextensions/CookiesTwigExtension.php b/src/twigextensions/CookiesTwigExtension.php index 1b252e1..10bc372 100644 --- a/src/twigextensions/CookiesTwigExtension.php +++ b/src/twigextensions/CookiesTwigExtension.php @@ -51,9 +51,9 @@ public function getFilters(): array public function getFunctions(): array { return [ - new TwigFunction('setCookie', fn(string $name = "", string $value = "", int $expire = 0, string $path = "/", string $domain = "", bool $secure = false, bool $httpOnly = false, bool $sameSite = false) => $this->setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $sameSite)), + new TwigFunction('setCookie', fn(string $name = "", string $value = "", int $expire = 0, string $path = "/", string $domain = "", bool $secure = false, bool $httpOnly = false, string $sameSite = 'Lax') => $this->setCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $sameSite)), new TwigFunction('getCookie', fn($name) => $this->getCookie($name)), - new TwigFunction('setSecureCookie', fn(string $name = "", string $value = "", int $expire = 0, string $path = "/", string $domain = "", bool $secure = false, bool $httpOnly = false, bool $sameSite = false) => $this->setSecureCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $sameSite)), + new TwigFunction('setSecureCookie', fn(string $name = "", string $value = "", int $expire = 0, string $path = "/", string $domain = "", bool $secure = false, bool $httpOnly = false, string $sameSite = 'Lax') => $this->setSecureCookie($name, $value, $expire, $path, $domain, $secure, $httpOnly, $sameSite)), new TwigFunction('getSecureCookie', fn($name) => $this->getSecureCookie($name)), ]; } @@ -103,7 +103,7 @@ public function setSecureCookie( string $domain = "", bool $secure = false, bool $httpOnly = false, - bool $sameSite = false, + string $sameSite = 'Lax', ): void { Cookies::$plugin->cookies->setSecure( diff --git a/src/variables/CookiesVariable.php b/src/variables/CookiesVariable.php index 3d1c737..0309e75 100755 --- a/src/variables/CookiesVariable.php +++ b/src/variables/CookiesVariable.php @@ -66,7 +66,7 @@ public function setSecure( string $domain = "", bool $secure = false, bool $httpOnly = false, - bool $sameSite = false, + string $sameSite = 'Lax', ): void { Cookies::$plugin->cookies->setSecure(