/**
  * Register form key in session from cookie value
  *
  * @param Varien_Event_Observer $observer
  */
 public function registerCachedFormKey(Varien_Event_Observer $observer)
 {
     if (!$this->isCacheEnabled()) {
         return;
     }
     /** @var $session Mage_Core_Model_Session  */
     $session = Mage::getSingleton('core/session');
     $cachedFrontFormKey = Enterprise_PageCache_Model_Cookie::getFormKeyCookieValue();
     if ($cachedFrontFormKey) {
         $session->setData('_form_key', $cachedFrontFormKey);
     }
 }
Beispiel #2
0
 /**
  * Determine and process all defined containers.
  * Direct request to pagecache/request/process action if necessary for additional processing
  *
  * @param string $content
  * @return string|false
  */
 protected function _processContent($content)
 {
     $containers = $this->_processContainers($content);
     $isProcessed = empty($containers);
     // renew session cookie
     $sessionInfo = Enterprise_PageCache_Model_Cache::getCacheInstance()->load($this->getSessionInfoCacheId());
     if ($sessionInfo) {
         $sessionInfo = unserialize($sessionInfo);
         foreach ($sessionInfo as $cookieName => $cookieInfo) {
             if (isset($_COOKIE[$cookieName]) && isset($cookieInfo['lifetime']) && isset($cookieInfo['path']) && isset($cookieInfo['domain']) && isset($cookieInfo['secure']) && isset($cookieInfo['httponly'])) {
                 $lifeTime = 0 == $cookieInfo['lifetime'] ? 0 : time() + $cookieInfo['lifetime'];
                 setcookie($cookieName, $_COOKIE[$cookieName], $lifeTime, $cookieInfo['path'], $cookieInfo['domain'], $cookieInfo['secure'], $cookieInfo['httponly']);
             }
         }
     } else {
         $isProcessed = false;
     }
     $formKey = Enterprise_PageCache_Model_Cookie::getFormKeyCookieValue();
     if (!$formKey) {
         $formKey = Enterprise_PageCache_Helper_Data::getRandomString(16);
         Enterprise_PageCache_Model_Cookie::setFormKeyCookieValue($formKey);
     }
     Enterprise_PageCache_Helper_Form_Key::restoreFormKey($content, $formKey);
     /**
      * restore session_id in content whether content is completely processed or not
      */
     $sidCookieName = $this->getMetadata('sid_cookie_name');
     $sidCookieValue = $sidCookieName && isset($_COOKIE[$sidCookieName]) ? $_COOKIE[$sidCookieName] : '';
     // XSS vulnerability protection provided by htmlspcialchars call - escape & " ' < > chars
     Enterprise_PageCache_Helper_Url::restoreSid($content, htmlspecialchars($sidCookieValue, ENT_QUOTES));
     if ($isProcessed) {
         return $content;
     } else {
         Mage::register('cached_page_content', $content);
         Mage::register('cached_page_containers', $containers);
         Mage::app()->getRequest()->setModuleName('pagecache')->setControllerName('request')->setActionName('process')->isStraight(true);
         // restore original routing info
         $routingInfo = array('aliases' => $this->getMetadata('routing_aliases'), 'requested_route' => $this->getMetadata('routing_requested_route'), 'requested_controller' => $this->getMetadata('routing_requested_controller'), 'requested_action' => $this->getMetadata('routing_requested_action'));
         Mage::app()->getRequest()->setRoutingInfo($routingInfo);
         return false;
     }
 }