Missing limits on Django login attempts

Missing limits on Django login attempts

Description

Django’s authenticate checks credentials and login establishes a session. On their own, these functions do not limit repeated login attempts.

Potential impact

Someone can keep guessing passwords, and suspicious attempts are difficult to detect or block if failures go unrecorded.

Remediation

  • Track failed logins by account, IP address, and device. Add a delay or temporary lockout when failures reach the threshold.
  • Integrate a tool such as django-ratelimit or django-axes with the login flow. Verify that recorded failures affect the decision to allow the next request.

Examples

These are excerpts from inside a login function. check_login_attempts must be implemented by the application or connected to a verified defense layer; adding the call alone does not create a limit. Record authentication failures and use them when deciding whether to allow subsequent attempts.

Before

python
user = authenticate(username=username, password=password)
if user is not None:
    login(request, user)

After

python
if not check_login_attempts(request):
    return None
user = authenticate(username=username, password=password)
if user is not None:
    login(request, user)

Explanation:

  • Before: The login flow checks credentials without checking the attempt limit.
  • After: If check_login_attempts rejects the request, the flow stops before authentication. The application must connect that check to the logic that records failures and enforces limits.

References