summaryrefslogtreecommitdiff
path: root/program/lib
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2014-04-25 18:26:21 +0200
committerThomas Bruederli <thomas@roundcube.net>2014-04-25 18:26:21 +0200
commitb867bb81e1ebcff701b5352edd10a143c1ec6996 (patch)
tree742906c53fa27ab152a9223ca49d6abae997ee72 /program/lib
parent95c59146b8fdc8d727beaf617890cc1cbbcb6df3 (diff)
parent30e6b980a6a4f528f79407203761823b7b2c5683 (diff)
Merge branch 'x-forwarded-whitelist' of github.com:tribut/roundcubemail into tribut-x-forwarded-whitelist
Diffstat (limited to 'program/lib')
-rw-r--r--program/lib/Roundcube/rcube_utils.php29
1 files changed, 19 insertions, 10 deletions
diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php
index 46d53ac91..c2009cee0 100644
--- a/program/lib/Roundcube/rcube_utils.php
+++ b/program/lib/Roundcube/rcube_utils.php
@@ -593,18 +593,18 @@ class rcube_utils
*/
public static function https_check($port=null, $use_https=true)
{
- global $RCMAIL;
-
if (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) != 'off') {
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;
}
if ($port && $_SERVER['SERVER_PORT'] == $port) {
return true;
}
- if ($use_https && isset($RCMAIL) && $RCMAIL->config->get('use_https')) {
+ if ($use_https && rcube::get_instance()->config->get('use_https')) {
return true;
}
@@ -683,13 +683,22 @@ class rcube_utils
*/
public static function remote_addr()
{
- if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- $hosts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'], 2);
- return $hosts[0];
- }
+ // 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'])) {
+ foreach(array_reverse(explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])) as $forwarded_ip) {
+ if (!in_array($forwarded_ip, $proxy_whitelist)) {
+ return $forwarded_ip;
+ }
+ }
+ }
- if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
- return $_SERVER['HTTP_X_REAL_IP'];
+ if (!empty($_SERVER['HTTP_X_REAL_IP'])) {
+ return $_SERVER['HTTP_X_REAL_IP'];
+ }
+ }
}
if (!empty($_SERVER['REMOTE_ADDR'])) {