From 57959d7d7b55dffc71dd1e4a2fb1631f5aba368d Mon Sep 17 00:00:00 2001 From: Colin Mollenhour Date: Mon, 9 Jan 2023 15:44:18 -0500 Subject: [PATCH] Fix session renew timestamp should be updated when customer changes password. Fixes #2826 --- .../core/Mage/Checkout/Model/Type/Onepage.php | 4 +--- .../Core/Model/Session/Abstract/Varien.php | 19 ++++++++++++++++--- .../core/Mage/Customer/Model/Customer.php | 16 +++++++++++++++- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/app/code/core/Mage/Checkout/Model/Type/Onepage.php b/app/code/core/Mage/Checkout/Model/Type/Onepage.php index 99ff55b66db1..62183ab64f4d 100644 --- a/app/code/core/Mage/Checkout/Model/Type/Onepage.php +++ b/app/code/core/Mage/Checkout/Model/Type/Onepage.php @@ -725,9 +725,7 @@ protected function _prepareNewCustomerQuote() Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer); $customer->setPassword($customer->decryptPassword($quote->getPasswordHash())); - $passwordCreatedTime = $this->_checkoutSession->getSessionValidatorData()['session_expire_timestamp'] - - Mage::getSingleton('core/cookie')->getLifetime(); - $customer->setPasswordCreatedAt($passwordCreatedTime); + $customer->setPasswordCreatedAt(time()); $quote->setCustomer($customer) ->setCustomerId(true); $quote->setPasswordHash(''); diff --git a/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php b/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php index 8d66a6be1c25..9b39a079edab 100644 --- a/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php +++ b/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php @@ -429,7 +429,7 @@ public function useValidateSessionExpire() } /** - * Use password creation timestamp in validator key + * Password creation timestamp must be older than session renewal * * @return bool */ @@ -471,8 +471,8 @@ public function validate() } // Refresh expire timestamp - if ($this->useValidateSessionExpire()) { - $_SESSION[self::VALIDATOR_KEY][self::VALIDATOR_SESSION_RENEW_TIMESTAMP] = time(); + if ($this->useValidateSessionExpire() || $this->useValidateSessionPasswordTimestamp()) { + $this->setValidatorSessionRenewTimestamp(time()); $_SESSION[self::VALIDATOR_KEY][self::VALIDATOR_SESSION_LIFETIME] = $this->getCookie()->getLifetime(); } } @@ -480,6 +480,18 @@ public function validate() return $this; } + /** + * Update the session's last legitimate renewal time (call when customer password is updated to avoid + * being logged out) + * + * @param int $timestamp + * @return void + */ + public function setValidatorSessionRenewTimestamp($timestamp) + { + $_SESSION[self::VALIDATOR_KEY][self::VALIDATOR_SESSION_RENEW_TIMESTAMP] = $timestamp; + } + /** * Validate data * @@ -569,6 +581,7 @@ public function getValidatorData() $parts[self::VALIDATOR_HTTP_USER_AGENT_KEY] = (string)$_SERVER['HTTP_USER_AGENT']; } + // get time when password was last changed if (isset($this->_data['visitor_data']['customer_id'])) { $parts[self::VALIDATOR_PASSWORD_CREATE_TIMESTAMP] = Mage::helper('customer')->getPasswordTimestamp($this->_data['visitor_data']['customer_id']); diff --git a/app/code/core/Mage/Customer/Model/Customer.php b/app/code/core/Mage/Customer/Model/Customer.php index 37f780beb746..b83d58edd1f5 100644 --- a/app/code/core/Mage/Customer/Model/Customer.php +++ b/app/code/core/Mage/Customer/Model/Customer.php @@ -85,7 +85,6 @@ * @method string getPasswordConfirmation() * @method $this setPasswordConfirmation(string $value) * @method int getPasswordCreatedAt() - * @method $this setPasswordCreatedAt(int $value) * @method string getPasswordHash() * @method $this setPasswordHash(string $value) * @method string getPrefix() @@ -333,6 +332,21 @@ public function changePassword($newPassword) return $this; } + /** + * Set time when password was changed to invalidate other sessions + * + * @param int $time + * @return $this + */ + public function setPasswordCreatedAt($time) + { + $this->setData('password_created_at', $time); + if (session_status() === PHP_SESSION_ACTIVE) { + Mage::getSingleton('checkout/session')->setValidatorSessionRenewTimestamp($time); + } + return $this; + } + /** * Get full customer name *