Skip to content

Commit 3a33192

Browse files
committed
fix: regenerate CSRF token right after session regeneration
CSRF token is not updated when `security.regenerate = false`, so if same-site attakcers know the CSRF token by session fixation attack, CSRF attack is possible. To prevent it, regenerate CSRF token right after login.
1 parent 47e08d2 commit 3a33192

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/Authentication/Authenticators/Session.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use CodeIgniter\Shield\Models\UserIdentityModel;
2121
use CodeIgniter\Shield\Models\UserModel;
2222
use CodeIgniter\Shield\Result;
23+
use Config\Services;
2324
use stdClass;
2425

2526
class Session implements AuthenticatorInterface
@@ -568,6 +569,9 @@ public function startLogin(User $user): void
568569
// Regenerate the session ID to help protect against session fixation
569570
if (ENVIRONMENT !== 'testing') {
570571
session()->regenerate(true);
572+
573+
// Regenerate CSRF token even if `security.regenerate = false`.
574+
Services::security()->generateHash();
571575
}
572576

573577
// Let the session know we're logged in

0 commit comments

Comments
 (0)