Skip to content

Commit

Permalink
fix ip whitelisting (#10218) (#10230)
Browse files Browse the repository at this point in the history
Co-authored-by: Giovanni Allegri <giohappy@gmail.com>
  • Loading branch information
github-actions[bot] and giohappy committed Nov 8, 2022
1 parent f67f63e commit 917928d
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions geonode/base/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,12 @@ def visitor_ip_address(request):

def is_ipaddress_in_whitelist(visitor_ip, whitelist):
# Chech if an IP is in the whitelisted IP ranges
in_whitelist = True
if not visitor_ip:
in_whitelist = False
if visitor_ip and whitelist and len(whitelist) > 0:
visitor_ipaddress = ipaddress.ip_address(visitor_ip)
for wip in whitelist:
try:
if visitor_ipaddress not in ipaddress.ip_network(wip):
in_whitelist = False
break
return True
except Exception:
in_whitelist = False
return in_whitelist
pass
return False

0 comments on commit 917928d

Please sign in to comment.