Skip to content

Commit

Permalink
Migrate to new frontend cookie name (session namespace). Refs #990
Browse files Browse the repository at this point in the history
  • Loading branch information
colinmollenhour committed May 20, 2020
1 parent a946552 commit 4e9ba86
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/code/core/Mage/Core/Controller/Front/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Mage_Core_Controller_Front_Action extends Mage_Core_Controller_Varien_Acti
/**
* Session namespace to refer in other places
*/
const SESSION_NAMESPACE = 'frontend';
const SESSION_NAMESPACE = 'om_session';

/**
* Add secret key to url config path
Expand Down
24 changes: 23 additions & 1 deletion app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,18 @@ public function start($sessionName=null)

if (!empty($sessionName)) {
$this->setSessionName($sessionName);
}

// Migrate old cookie from 'frontend'
if ($sessionName === \Mage_Core_Controller_Front_Action::SESSION_NAMESPACE
&& $cookie->get('frontend')
&& ! $cookie->get(\Mage_Core_Controller_Front_Action::SESSION_NAMESPACE)
) {
$frontendValue = $cookie->get('frontend');
$_COOKIE[\Mage_Core_Controller_Front_Action::SESSION_NAMESPACE] = $frontendValue;
$cookie->set(Mage_Core_Controller_Front_Action::SESSION_NAMESPACE, $frontendValue);
$cookie->delete('frontend');
}
}
// potential custom logic for session id (ex. switching between hosts)
$this->setSessionId();

Expand All @@ -141,6 +151,18 @@ public function start($sessionName=null)
$secureCookieName = $sessionName . '_cid';
if (isset($_SESSION[self::SECURE_COOKIE_CHECK_KEY])) {
$cookieValue = $cookie->get($secureCookieName);

// Migrate old cookie from 'frontend'
if ( ! $cookieValue
&& $sessionName === \Mage_Core_Controller_Front_Action::SESSION_NAMESPACE
&& $cookie->get('frontend_cid')
) {
$frontendValue = $cookie->get('frontend_cid');
$_COOKIE[\Mage_Core_Controller_Front_Action::SESSION_NAMESPACE] = $frontendValue;
$cookie->set(Mage_Core_Controller_Front_Action::SESSION_NAMESPACE, $frontendValue);
$cookie->delete('frontend_cid');
}

if (!is_string($cookieValue) || $_SESSION[self::SECURE_COOKIE_CHECK_KEY] !== md5($cookieValue)) {
session_regenerate_id(false);
$sessionHosts = $this->getSessionHosts();
Expand Down

0 comments on commit 4e9ba86

Please sign in to comment.