Skip to content

Commit

Permalink
add a fix so that we don't block an empty IP or username
Browse files Browse the repository at this point in the history
  • Loading branch information
kencochrane committed Feb 1, 2015
1 parent 8ee8f3c commit 88c388e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion defender/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

# Django >= 1.7 compatibility
try:
LOGIN_FORM_KEY = '<form action="/admin/login/" method="post" id="login-form">'
LOGIN_FORM_KEY = '<form action="/admin/login/" method="post"'
' id="login-form">'
ADMIN_LOGIN_URL = reverse('admin:login')
except NoReverseMatch:
ADMIN_LOGIN_URL = reverse('admin:index')
Expand Down
6 changes: 6 additions & 0 deletions defender/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ def get_user_attempts(request):

def block_ip(ip):
""" given the ip, block it """
if not ip:
# no reason to continue when there is no ip
return
key = get_ip_blocked_cache_key(ip)
if config.COOLOFF_TIME:
redis_server.set(key, 'blocked', config.COOLOFF_TIME)
Expand All @@ -171,6 +174,9 @@ def block_ip(ip):

def block_username(username):
""" given the username block it. """
if not username:
# no reason to continue when there is no username
return
key = get_username_blocked_cache_key(username)
if config.COOLOFF_TIME:
redis_server.set(key, 'blocked', config.COOLOFF_TIME)
Expand Down

0 comments on commit 88c388e

Please sign in to comment.