diff --git a/apps/pc_backend/lib/myUser.class.php b/apps/pc_backend/lib/myUser.class.php index 5f528fe..528de7b 100644 --- a/apps/pc_backend/lib/myUser.class.php +++ b/apps/pc_backend/lib/myUser.class.php @@ -8,7 +8,7 @@ * file and the NOTICE file that were distributed with this source code. */ -class myUser extends sfBasicSecurityUser +class myUser extends opBaseSecurityUser { public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array()) { diff --git a/config/ProjectConfiguration.class.php.sample b/config/ProjectConfiguration.class.php.sample index 78e7b83..1064ca3 100644 --- a/config/ProjectConfiguration.class.php.sample +++ b/config/ProjectConfiguration.class.php.sample @@ -15,8 +15,16 @@ class ProjectConfiguration extends sfProjectConfiguration $this->enableAllPluginsExcept(array('sfCompat10Plugin')); $this->setIncludePath(); - //HTTP proxy to use when downloading plugin packages + // HTTP proxy to use when downloading plugin packages sfConfig::set('op_http_proxy', null); + + // セッションデータにサイト特有の識別子を含めるかどうか + // Configuration of using site_identifier in session data + sfConfig::set('op_check_session_site_identifier', true); + + // In default, OpenPNE saves session data file to default session.save_path. + // But in some cases, you may need to change the session save path: + // session_save_path('/tmp'); } public function setIncludePath() diff --git a/data/version.php b/data/version.php index 30b5ff5..1d992a5 100644 --- a/data/version.php +++ b/data/version.php @@ -10,5 +10,5 @@ if (!defined('OPENPNE_VERSION')) { - define('OPENPNE_VERSION', '3.0.8.1'); + define('OPENPNE_VERSION', '3.0.8.2'); } diff --git a/lib/user/opBaseSecurityUser.class.php b/lib/user/opBaseSecurityUser.class.php new file mode 100644 index 0000000..0eee520 --- /dev/null +++ b/lib/user/opBaseSecurityUser.class.php @@ -0,0 +1,88 @@ + + */ +abstract class opBaseSecurityUser extends sfBasicSecurityUser +{ + const SITE_IDENTIFIER_NAMESPACE = 'OpenPNE/user/opSecurityUser/site_identifier'; + + public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array()) + { + if (!isset($options['session_namespaces'])) + { + $options['session_namespaces'] = array( + self::SITE_IDENTIFIER_NAMESPACE, + self::LAST_REQUEST_NAMESPACE, + self::AUTH_NAMESPACE, + self::CREDENTIAL_NAMESPACE, + self::ATTRIBUTE_NAMESPACE, + ); + } + + parent::initialize($dispatcher, $storage, $options); + + if (!$this->isValidSiteIdentifier()) + { + // This session is not for this site. + $this->logout(); + + // So we need to clear all data of the current session because they might be tainted by attacker. + // If OpenPNE uses that tainted data, it may cause limited session fixation attack. + $this->clearSessionData(); + + return null; + } + } + + abstract public function logout(); + + public function clearSessionData() + { + // remove data in storage + foreach ($this->options['session_namespaces'] as $v) + { + $this->storage->remove($v); + } + + // remove attribtues + $this->attributeHolder->clear(); + } + + public function isValidSiteIdentifier() + { + if (!sfConfig::get('op_check_session_site_identifier', true)) + { + return true; + } + + return ($this->generateSiteIdentifier() === $this->storage->read(self::SITE_IDENTIFIER_NAMESPACE)); + } + + public function generateSiteIdentifier() + { + $request = sfContext::getInstance()->getRequest(); + $identifier = $request->getUriPrefix().$request->getRelativeUrlRoot(); + + return $identifier; + } + + public function shutdown() + { + $this->storage->write(self::SITE_IDENTIFIER_NAMESPACE, $this->generateSiteIdentifier()); + + parent::shutdown(); + } +} diff --git a/lib/user/sfOpenPNESecurityUser.class.php b/lib/user/sfOpenPNESecurityUser.class.php index 02d884f..961eee4 100644 --- a/lib/user/sfOpenPNESecurityUser.class.php +++ b/lib/user/sfOpenPNESecurityUser.class.php @@ -15,7 +15,7 @@ * @subpackage user * @author Kousuke Ebihara */ -class sfOpenPNESecurityUser extends sfBasicSecurityUser +class sfOpenPNESecurityUser extends opBaseSecurityUser { protected $authAdapter = null;