diff --git a/components/Session.php b/components/Session.php index a5b4e531..277517d9 100644 --- a/components/Session.php +++ b/components/Session.php @@ -373,7 +373,7 @@ protected function authenticateSession() ]); } - if (Request::session()->get("password_hash_{$driver}") !== $user->getAuthPassword()) { + if (!$this->isValidSessionPasswordHash($user->getAuthPassword(), Request::session()->get("password_hash_{$driver}"))) { $logoutFunc(); return; } @@ -386,4 +386,25 @@ protected function authenticateSession() } }); } + + /** + * isValidSessionPasswordHash accepts the raw password hash stored by this component + * and the HMAC hash stored by SessionGuard::login() since Laravel 12.69.3 + * + * @see \Illuminate\Session\Middleware\AuthenticateSession::validatePasswordHash + */ + protected function isValidSessionPasswordHash($passwordHash, $storedHash): bool + { + if (!is_string($passwordHash) || !is_string($storedHash)) { + return false; + } + + if (hash_equals($passwordHash, $storedHash)) { + return true; + } + + return method_exists(Auth::guard(), 'hashPasswordForCookie') + && hash_equals(Auth::hashPasswordForCookie($passwordHash), $storedHash); + } + }