From fb726c3613347e3c5b38c6bf00d08e0cb27de9dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Sessing=C3=B8?= Date: Thu, 18 Mar 2021 02:50:06 +0100 Subject: [PATCH] Issue #437: Fixed CSRF-token returning null on first refresh after cookies are removed. --- .idea/simple-php-router.iml | 2 ++ .idea/workspace.xml | 31 ++++++++++++++++--- .../Http/Security/CookieTokenProvider.php | 4 +-- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/.idea/simple-php-router.iml b/.idea/simple-php-router.iml index e5bc18a..f342345 100644 --- a/.idea/simple-php-router.iml +++ b/.idea/simple-php-router.iml @@ -2,7 +2,9 @@ + + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 84f9914..f60b995 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -5,8 +5,9 @@ + - + - diff --git a/src/Pecee/Http/Security/CookieTokenProvider.php b/src/Pecee/Http/Security/CookieTokenProvider.php index c078faa..35f1021 100644 --- a/src/Pecee/Http/Security/CookieTokenProvider.php +++ b/src/Pecee/Http/Security/CookieTokenProvider.php @@ -17,7 +17,7 @@ class CookieTokenProvider implements ITokenProvider */ public function __construct() { - $this->token = $this->getToken(); + $this->token = ($this->hasToken() === true) ? $_COOKIE[static::CSRF_KEY] : null; if ($this->token === null) { $this->token = $this->generateToken(); @@ -73,8 +73,6 @@ class CookieTokenProvider implements ITokenProvider */ public function getToken(?string $defaultValue = null): ?string { - $this->token = ($this->hasToken() === true) ? $_COOKIE[static::CSRF_KEY] : null; - return $this->token ?? $defaultValue; }