@ -598,7 +598,9 @@ class rcube_utils
if (!empty($_SERVER['HTTPS']) & & strtolower($_SERVER['HTTPS']) != 'off') {
if (!empty($_SERVER['HTTPS']) & & strtolower($_SERVER['HTTPS']) != 'off') {
return true;
return true;
}
}
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) & & strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') {
if (!empty($_SERVER['HTTP_X_FORWARDED_PROTO'])
& & strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https'
& & in_array($_SERVER['REMOTE_ADDR'], rcube::get_instance()->config->get('proxy_whitelist', array()))) {
return true;
return true;
}
}
if ($port & & $_SERVER['SERVER_PORT'] == $port) {
if ($port & & $_SERVER['SERVER_PORT'] == $port) {
@ -683,14 +685,23 @@ class rcube_utils
*/
*/
public static function remote_addr()
public static function remote_addr()
{
{
// Check if any of the headers are set first to improve performance
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) || !empty($_SERVER['HTTP_X_REAL_IP'])) {
$proxy_whitelist = rcube::get_instance()->config->get('proxy_whitelist', array());
if (in_array($_SERVER['REMOTE_ADDR'], $proxy_whitelist)) {
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$hosts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2);
foreach(array_reverse(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])) as $forwarded_ip) {
return $hosts[0];
if (!in_array($forwarded_ip, $proxy_whitelist)) {
return $forwarded_ip;
}
}
}
}
if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
return $_SERVER['HTTP_X_REAL_IP'];
return $_SERVER['HTTP_X_REAL_IP'];
}
}
}
}
if (!empty($_SERVER['REMOTE_ADDR'])) {
if (!empty($_SERVER['REMOTE_ADDR'])) {
return $_SERVER['REMOTE_ADDR'];
return $_SERVER['REMOTE_ADDR'];