diff options
author | Marcin Kuzminski <marcin@python-works.com> | 2013-01-08 20:42:48 +0100 |
---|---|---|
committer | Marcin Kuzminski <marcin@python-works.com> | 2013-01-08 20:42:48 +0100 |
commit | 65de90320b72ae41c05adf37926d605d3bfd87a2 (patch) | |
tree | f67e8c0913f2f9fe825de65ed3f98bbdfe20d5dd | |
parent | 380f0657452428d8e12ec632956cd2f10ad07e92 (diff) |
fix multiple ips addresses in X_FORWARDER_FOR header
--HG--
branch : beta
-rw-r--r-- | rhodecode/lib/base.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/rhodecode/lib/base.py b/rhodecode/lib/base.py index f993eb4d..da847754 100644 --- a/rhodecode/lib/base.py +++ b/rhodecode/lib/base.py @@ -37,13 +37,18 @@ def _get_ip_addr(environ): proxy_key2 = 'HTTP_X_FORWARDED_FOR' def_key = 'REMOTE_ADDR' - ip = environ.get(proxy_key2) + ip = environ.get(proxy_key) if ip: return ip - ip = environ.get(proxy_key) - + ip = environ.get(proxy_key2) if ip: + # HTTP_X_FORWARDED_FOR can have mutliple ips inside + # the left-most being the original client, and each successive proxy + # that passed the request adding the IP address where it received the + # request from. + if ',' in ip: + ip = ip.split(',')[0].strip() return ip ip = environ.get(def_key, '0.0.0.0') |