Changeset - 8046d1979674
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 13 years ago 2013-01-08 20:42:48
marcin@python-works.com
fix multiple ips addresses in X_FORWARDER_FOR header
1 file changed with 8 insertions and 3 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/base.py
Show inline comments
 
@@ -34,19 +34,24 @@ log = logging.getLogger(__name__)
 

	
 
def _get_ip_addr(environ):
 
    proxy_key = 'HTTP_X_REAL_IP'
 
    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')
 
    return ip
 

	
 

	
0 comments (0 inline, 0 general)