Skip to content

Commit 0184261

Browse files
committed
refactor: generateHash() always generate new hash
1 parent e056312 commit 0184261

1 file changed

Lines changed: 2 additions & 21 deletions

File tree

system/Security/Security.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ public function __construct(App $config)
200200
$this->request = Services::request();
201201
$this->hashInCookie = $this->request->getCookie($this->cookieName);
202202

203+
$this->restoreHash();
203204
if ($this->hash === null) {
204205
$this->generateHash();
205206
}
@@ -314,16 +315,6 @@ public function verify(RequestInterface $request)
314315
}
315316

316317
if ($this->regenerate) {
317-
$this->hash = null;
318-
if ($this->isCSRFCookie()) {
319-
$this->hashInCookie = null;
320-
} else {
321-
// Session based CSRF protection
322-
$this->session->remove($this->tokenName);
323-
}
324-
}
325-
326-
if ($this->hash === null) {
327318
$this->generateHash();
328319
}
329320

@@ -518,20 +509,10 @@ private function restoreHash(): void
518509
}
519510

520511
/**
521-
* Generates the CSRF Hash.
512+
* Generates (Regenerate) the CSRF Hash.
522513
*/
523514
protected function generateHash(): string
524515
{
525-
// If the cookie exists we will use its value.
526-
// We don't necessarily want to regenerate it with
527-
// each page load since a page could contain embedded
528-
// sub-pages causing this feature to fail
529-
$this->restoreHash();
530-
531-
if ($this->hash !== null) {
532-
return $this->hash;
533-
}
534-
535516
$this->hash = bin2hex(random_bytes(static::CSRF_HASH_BYTES));
536517

537518
if ($this->isCSRFCookie()) {

0 commit comments

Comments
 (0)