use x-real-ip headers
This commit is contained in:
parent
8594e604fc
commit
4e460726dd
1 changed files with 10 additions and 6 deletions
|
@ -24,12 +24,16 @@ def block_ipv4(get_response):
|
||||||
return get_response(request)
|
return get_response(request)
|
||||||
|
|
||||||
path = request.path_info.lstrip('/')
|
path = request.path_info.lstrip('/')
|
||||||
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
|
|
||||||
if x_forwarded_for:
|
real_ip_headers = ['HTTP_X_REAL_IP', 'REMOTE_ADDR', 'HTTP_X_FORWARDED_FOR']
|
||||||
client_ip = x_forwarded_for
|
client_ip = None
|
||||||
else:
|
|
||||||
client_ip = request.META.get('REMOTE_ADDR')
|
for header in real_ip_headers:
|
||||||
print(is_ipv6_exempt(path), is_valid_ipv6(client_ip))
|
client_ip = request.META.get(header)
|
||||||
|
|
||||||
|
if client_ip:
|
||||||
|
break
|
||||||
|
|
||||||
if is_valid_ipv6(client_ip) or is_ipv6_exempt(path):
|
if is_valid_ipv6(client_ip) or is_ipv6_exempt(path):
|
||||||
return get_response(request)
|
return get_response(request)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue