##// END OF EJS Templates
auth: don't trust clients too much - only trust the *last* IP in the X-Forwarded-For header...
Mads Kiilerich -
r8678:f08fbf42 default
parent child Browse files
Show More
@@ -64,15 +64,17 b' def render(template_path):'
64
64
65 def _filter_proxy(ip):
65 def _filter_proxy(ip):
66 """
66 """
67 HEADERS can have multiple ips inside the left-most being the original
67 HTTP_X_FORWARDED_FOR headers can have multiple IP addresses, with the
68 client, and each successive proxy that passed the request adding the IP
68 leftmost being the original client. Each proxy that is forwarding the
69 address where it received the request from.
69 request will usually add the IP address it sees the request coming from.
70
70
71 :param ip:
71 The client might have provided a fake leftmost value before hitting the
72 first proxy, so if we have a proxy that is adding one IP address, we can
73 only trust the rightmost address.
72 """
74 """
73 if ',' in ip:
75 if ',' in ip:
74 _ips = ip.split(',')
76 _ips = ip.split(',')
75 _first_ip = _ips[0].strip()
77 _first_ip = _ips[-1].strip()
76 log.debug('Got multiple IPs %s, using %s', ','.join(_ips), _first_ip)
78 log.debug('Got multiple IPs %s, using %s', ','.join(_ips), _first_ip)
77 return _first_ip
79 return _first_ip
78 return ip
80 return ip
General Comments 0
You need to be logged in to leave comments. Login now