Mercurial > kallithea
changeset 3153:8046d1979674 beta
fix multiple ips addresses in X_FORWARDER_FOR header
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 08 Jan 2013 20:42:48 +0100 |
parents | 46234d2d388f |
children | 0226b6d6b2b5 |
files | rhodecode/lib/base.py |
diffstat | 1 files changed, 8 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/lib/base.py Tue Jan 08 15:47:37 2013 +0100 +++ b/rhodecode/lib/base.py Tue Jan 08 20:42:48 2013 +0100 @@ -37,13 +37,18 @@ 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')