From 74c2fe882a26b404d1baf21eddfcffacf7756965 Mon Sep 17 00:00:00 2001 From: Dale Davies Date: Tue, 19 Jul 2022 12:27:20 +0100 Subject: [PATCH] Fix session locking issue after refactoring routing --- jumpapp/classes/Main.php | 11 +++-------- jumpapp/classes/Pages/AbstractPage.php | 6 ++++++ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/jumpapp/classes/Main.php b/jumpapp/classes/Main.php index 42b8e34..fab573e 100644 --- a/jumpapp/classes/Main.php +++ b/jumpapp/classes/Main.php @@ -23,6 +23,9 @@ class Main { $this->router = new RouteList; // Set up the routes that Jump expects. + $this->router->addRoute('/', [ + 'class' => 'Jump\Pages\HomePage' + ]); $this->router->addRoute('/tag/', [ 'class' => 'Jump\Pages\TagPage' ]); @@ -46,14 +49,6 @@ class Main { $this->session->setName($this->config->get('sessionname')); $this->session->setExpiration($this->config->get('sessiontimeout')); - // Get a Nette session section for CSRF data. - $csrfsection = $this->session->getSection('csrf'); - - // Create a new CSRF token within the section if one doesn't exist already. - if (!$csrfsection->offsetExists('token')){ - $csrfsection->set('token', bin2hex(random_bytes(32))); - } - // Try to match the correct route based on the HTTP request. $matchedroute = $this->router->match($this->request); diff --git a/jumpapp/classes/Pages/AbstractPage.php b/jumpapp/classes/Pages/AbstractPage.php index c04d591..7bf9bcf 100644 --- a/jumpapp/classes/Pages/AbstractPage.php +++ b/jumpapp/classes/Pages/AbstractPage.php @@ -28,6 +28,12 @@ abstract class AbstractPage { return urlencode($renderer($text)); }), ]); + // Get a Nette session section for CSRF data. + $csrfsection = $this->session->getSection('csrf'); + // Create a new CSRF token within the section if one doesn't exist already. + if (!$csrfsection->offsetExists('token')){ + $csrfsection->set('token', bin2hex(random_bytes(32))); + } } abstract protected function render_content(): string;