diff options
Diffstat (limited to 'phpBB/phpbb/session.php')
| -rw-r--r-- | phpBB/phpbb/session.php | 70 | 
1 files changed, 48 insertions, 22 deletions
diff --git a/phpBB/phpbb/session.php b/phpBB/phpbb/session.php index 45e82df591..6b5b8f2625 100644 --- a/phpBB/phpbb/session.php +++ b/phpBB/phpbb/session.php @@ -91,9 +91,18 @@ class session  			$page_name .= str_replace('%2F', '/', urlencode($symfony_request_path));  		} -		// current directory within the phpBB root (for example: adm) -		$root_dirs = explode('/', str_replace('\\', '/', phpbb_realpath($root_path))); -		$page_dirs = explode('/', str_replace('\\', '/', phpbb_realpath('./'))); +		if (substr($root_path, 0, 2) === './' && strpos($root_path, '..') === false) +		{ +			$root_dirs = explode('/', str_replace('\\', '/', rtrim($root_path, '/'))); +			$page_dirs = explode('/', str_replace('\\', '/', '.')); +		} +		else +		{ +			// current directory within the phpBB root (for example: adm) +			$root_dirs = explode('/', str_replace('\\', '/', $phpbb_filesystem->realpath($root_path))); +			$page_dirs = explode('/', str_replace('\\', '/', $phpbb_filesystem->realpath('./'))); +		} +  		$intersection = array_intersect_assoc($root_dirs, $page_dirs);  		$root_dirs = array_diff_assoc($root_dirs, $intersection); @@ -219,7 +228,7 @@ class session  	function session_begin($update_session_page = true)  	{  		global $phpEx, $SID, $_SID, $_EXTRA_URL, $db, $config, $phpbb_root_path; -		global $request, $phpbb_container, $phpbb_dispatcher; +		global $request, $phpbb_container, $user, $phpbb_log, $phpbb_dispatcher;  		// Give us some basic information  		$this->time_now				= time(); @@ -257,23 +266,23 @@ class session  		if ($request->is_set($config['cookie_name'] . '_sid', \phpbb\request\request_interface::COOKIE) || $request->is_set($config['cookie_name'] . '_u', \phpbb\request\request_interface::COOKIE))  		{ -			$this->cookie_data['u'] = request_var($config['cookie_name'] . '_u', 0, false, true); -			$this->cookie_data['k'] = request_var($config['cookie_name'] . '_k', '', false, true); -			$this->session_id 		= request_var($config['cookie_name'] . '_sid', '', false, true); +			$this->cookie_data['u'] = $request->variable($config['cookie_name'] . '_u', 0, false, \phpbb\request\request_interface::COOKIE); +			$this->cookie_data['k'] = $request->variable($config['cookie_name'] . '_k', '', false, \phpbb\request\request_interface::COOKIE); +			$this->session_id 		= $request->variable($config['cookie_name'] . '_sid', '', false, \phpbb\request\request_interface::COOKIE);  			$SID = (defined('NEED_SID')) ? '?sid=' . $this->session_id : '?sid=';  			$_SID = (defined('NEED_SID')) ? $this->session_id : '';  			if (empty($this->session_id))  			{ -				$this->session_id = $_SID = request_var('sid', ''); +				$this->session_id = $_SID = $request->variable('sid', '');  				$SID = '?sid=' . $this->session_id;  				$this->cookie_data = array('u' => 0, 'k' => '');  			}  		}  		else  		{ -			$this->session_id = $_SID = request_var('sid', ''); +			$this->session_id = $_SID = $request->variable('sid', '');  			$SID = '?sid=' . $this->session_id;  		} @@ -359,8 +368,8 @@ class session  			}  			else  			{ -				set_config('limit_load', '0'); -				set_config('limit_search_load', '0'); +				$config->set('limit_load', '0'); +				$config->set('limit_search_load', '0');  			}  		} @@ -423,6 +432,7 @@ class session  					$session_expired = false;  					// Check whether the session is still valid if we have one +					/* @var $provider_collection \phpbb\auth\provider_collection */  					$provider_collection = $phpbb_container->get('auth.provider_collection');  					$provider = $provider_collection->get_provider(); @@ -473,11 +483,18 @@ class session  					{  						if ($referer_valid)  						{ -							add_log('critical', 'LOG_IP_BROWSER_FORWARDED_CHECK', $u_ip, $s_ip, $u_browser, $s_browser, htmlspecialchars($u_forwarded_for), htmlspecialchars($s_forwarded_for)); +							$phpbb_log->add('critical', $user->data['user_id'], $user->ip, 'LOG_IP_BROWSER_FORWARDED_CHECK', false, array( +								$u_ip, +								$s_ip, +								$u_browser, +								$s_browser, +								htmlspecialchars($u_forwarded_for), +								htmlspecialchars($s_forwarded_for) +							));  						}  						else  						{ -							add_log('critical', 'LOG_REFERER_INVALID', $this->referer); +							$phpbb_log->add('critical', $user->data['user_id'], $user->ip, 'LOG_REFERER_INVALID', false, array($this->referer));  						}  					}  				} @@ -499,7 +516,7 @@ class session  	*/  	function session_create($user_id = false, $set_admin = false, $persist_login = false, $viewonline = true)  	{ -		global $SID, $_SID, $db, $config, $cache, $phpbb_root_path, $phpEx, $phpbb_container, $phpbb_dispatcher; +		global $SID, $_SID, $db, $config, $cache, $phpbb_container, $phpbb_dispatcher;  		$this->data = array(); @@ -562,6 +579,7 @@ class session  			}  		} +		/* @var $provider_collection \phpbb\auth\provider_collection */  		$provider_collection = $phpbb_container->get('auth.provider_collection');  		$provider = $provider_collection->get_provider();  		$this->data = $provider->autologin(); @@ -820,7 +838,7 @@ class session  			$sql = 'SELECT COUNT(session_id) AS sessions  					FROM ' . SESSIONS_TABLE . '  					WHERE session_user_id = ' . (int) $this->data['user_id'] . ' -					AND session_time >= ' . (int) ($this->time_now - (max($config['session_length'], $config['form_token_lifetime']))); +					AND session_time >= ' . (int) ($this->time_now - (max((int) $config['session_length'], (int) $config['form_token_lifetime'])));  			$result = $db->sql_query($sql);  			$row = $db->sql_fetchrow($result);  			$db->sql_freeresult($result); @@ -875,7 +893,7 @@ class session  	*/  	function session_kill($new_session = true)  	{ -		global $SID, $_SID, $db, $config, $phpbb_root_path, $phpEx, $phpbb_container, $phpbb_dispatcher; +		global $SID, $_SID, $db, $phpbb_container, $phpbb_dispatcher;  		$sql = 'DELETE FROM ' . SESSIONS_TABLE . "  			WHERE session_id = '" . $db->sql_escape($this->session_id) . "' @@ -900,6 +918,7 @@ class session  		unset($session_id);  		// Allow connecting logout with external auth method logout +		/* @var $provider_collection \phpbb\auth\provider_collection */  		$provider_collection = $phpbb_container->get('auth.provider_collection');  		$provider = $provider_collection->get_provider();  		$provider->logout($this->data, $new_session); @@ -966,7 +985,7 @@ class session  	*/  	function session_gc()  	{ -		global $db, $config, $phpbb_root_path, $phpEx, $phpbb_container, $phpbb_dispatcher; +		global $db, $config, $phpbb_container, $phpbb_dispatcher;  		$batch_size = 10; @@ -1016,7 +1035,7 @@ class session  		{  			// Less than 10 users, update gc timer ... else we want gc  			// called again to delete other sessions -			set_config('session_last_gc', $this->time_now, true); +			$config->set('session_last_gc', $this->time_now, false);  			if ($config['max_autologin_time'])  			{ @@ -1026,6 +1045,7 @@ class session  			}  			// only called from CRON; should be a safe workaround until the infrastructure gets going +			/* @var $captcha_factory \phpbb\captcha\factory */  			$captcha_factory = $phpbb_container->get('captcha.factory');  			$captcha_factory->garbage_collect($config['captcha_plugin']); @@ -1059,6 +1079,12 @@ class session  	{  		global $config; +		// If headers are already set, we just return +		if (headers_sent()) +		{ +			return; +		} +  		$name_data = rawurlencode($config['cookie_name'] . '_' . $name) . '=' . rawurlencode($cookiedata);  		$expire = gmdate('D, d-M-Y H:i:s \\G\\M\\T', $cookietime);  		$domain = (!$config['cookie_domain'] || $config['cookie_domain'] == '127.0.0.1' || strpos($config['cookie_domain'], '.') === false) ? '' : '; domain=' . $config['cookie_domain']; @@ -1210,7 +1236,7 @@ class session  		if ($banned && !$return)  		{ -			global $template, $phpbb_root_path, $phpEx; +			global $phpbb_root_path, $phpEx;  			// If the session is empty we need to create a valid one...  			if (empty($this->session_id)) @@ -1409,7 +1435,7 @@ class session  	*/  	function set_login_key($user_id = false, $key = false, $user_ip = false)  	{ -		global $config, $db; +		global $db;  		$user_id = ($user_id === false) ? $this->data['user_id'] : $user_id;  		$user_ip = ($user_ip === false) ? $this->ip : $user_ip; @@ -1419,7 +1445,7 @@ class session  		$sql_ary = array(  			'key_id'		=> (string) md5($key_id), -			'last_ip'		=> (string) $this->ip, +			'last_ip'		=> (string) $user_ip,  			'last_login'	=> (int) time()  		); @@ -1456,7 +1482,7 @@ class session  	*/  	function reset_login_keys($user_id = false)  	{ -		global $config, $db; +		global $db;  		$user_id = ($user_id === false) ? (int) $this->data['user_id'] : (int) $user_id;  | 
