From 12ad0e0510a716e46b59889c5d24b03d211c0f64 Mon Sep 17 00:00:00 2001 From: Agent Date: Sun, 14 Jun 2026 09:03:53 -0400 Subject: [PATCH] fix: cache CSRF token in View to prevent mismatch on multiple renders --- src/Core/View.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Core/View.php b/src/Core/View.php index 1736420..9b9d8a6 100755 --- a/src/Core/View.php +++ b/src/Core/View.php @@ -10,6 +10,7 @@ class View private string $layout = 'main'; private array $data = []; private Security $security; + private ?string $csrfTokenCache = null; public function __construct(Security $security) { @@ -80,7 +81,10 @@ class View public function csrfToken(): string { - return $this->security->generateCSRFToken(); + if ($this->csrfTokenCache === null) { + $this->csrfTokenCache = $this->security->generateCSRFToken(); + } + return $this->csrfTokenCache; } public function csrfField(): string