-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(account): Account enumeration timing attack
- Loading branch information
Showing
4 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
from unittest.mock import patch | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.test.utils import override_settings | ||
|
||
import pytest | ||
|
||
from allauth.account import app_settings | ||
from allauth.account.auth_backends import AuthenticationBackend | ||
from allauth.tests import TestCase | ||
|
@@ -71,3 +75,32 @@ def test_auth_by_username_or_email(self): | |
).pk, | ||
user.pk, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"auth_method", | ||
[ | ||
app_settings.AuthenticationMethod.EMAIL, | ||
app_settings.AuthenticationMethod.USERNAME, | ||
app_settings.AuthenticationMethod.USERNAME_EMAIL, | ||
], | ||
) | ||
def test_account_enumeration_timing_attack(user, db, rf, settings, auth_method): | ||
settings.ACCOUNT_AUTHENTICATION_METHOD = auth_method | ||
with ( | ||
patch("django.contrib.auth.models.User.set_password") as set_password_mock, | ||
patch("django.contrib.auth.models.User.check_password", new=set_password_mock), | ||
): | ||
backend = AuthenticationBackend() | ||
backend.authenticate( | ||
rf.get("/"), email="[email protected]", username="not-known", password="secret" | ||
) | ||
set_password_mock.assert_called_once() | ||
set_password_mock.reset_mock() | ||
backend.authenticate(rf.get("/"), username=user.username, password="secret") | ||
set_password_mock.assert_called_once() | ||
set_password_mock.reset_mock() | ||
backend.authenticate( | ||
rf.get("/"), email=user.email, username="not-known", password="secret" | ||
) | ||
set_password_mock.assert_called_once() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters