-
-
Notifications
You must be signed in to change notification settings - Fork 989
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
security: fix CVE-2023-39522 (#6665)
* stages/email: don't disclose whether a user exists or not when recovering Signed-off-by: Jens Langhammer <[email protected]> * update website Signed-off-by: Jens Langhammer <[email protected]> --------- Signed-off-by: Jens Langhammer <[email protected]> # Conflicts: # website/docs/releases/2023/v2023.5.md # website/docs/releases/2023/v2023.6.md
- Loading branch information
Showing
7 changed files
with
139 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,18 +5,20 @@ | |
from django.core import mail | ||
from django.core.mail.backends.locmem import EmailBackend | ||
from django.urls import reverse | ||
from rest_framework.test import APITestCase | ||
|
||
from authentik.core.models import User | ||
from authentik.core.tests.utils import create_test_admin_user, create_test_flow | ||
from authentik.events.models import Event, EventAction | ||
from authentik.flows.markers import StageMarker | ||
from authentik.flows.models import FlowDesignation, FlowStageBinding | ||
from authentik.flows.planner import PLAN_CONTEXT_PENDING_USER, FlowPlan | ||
from authentik.flows.tests import FlowTestCase | ||
from authentik.flows.views.executor import SESSION_KEY_PLAN | ||
from authentik.lib.generators import generate_id | ||
from authentik.stages.email.models import EmailStage | ||
|
||
|
||
class TestEmailStageSending(APITestCase): | ||
class TestEmailStageSending(FlowTestCase): | ||
"""Email tests""" | ||
|
||
def setUp(self): | ||
|
@@ -44,6 +46,13 @@ def test_pending_user(self): | |
): | ||
response = self.client.post(url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertStageResponse( | ||
response, | ||
self.flow, | ||
response_errors={ | ||
"non_field_errors": [{"string": "email-sent", "code": "email-sent"}] | ||
}, | ||
) | ||
self.assertEqual(len(mail.outbox), 1) | ||
self.assertEqual(mail.outbox[0].subject, "authentik") | ||
events = Event.objects.filter(action=EventAction.EMAIL_SENT) | ||
|
@@ -54,6 +63,32 @@ def test_pending_user(self): | |
self.assertEqual(event.context["to_email"], [self.user.email]) | ||
self.assertEqual(event.context["from_email"], "[email protected]") | ||
|
||
def test_pending_fake_user(self): | ||
"""Test with pending (fake) user""" | ||
self.flow.designation = FlowDesignation.RECOVERY | ||
self.flow.save() | ||
plan = FlowPlan(flow_pk=self.flow.pk.hex, bindings=[self.binding], markers=[StageMarker()]) | ||
plan.context[PLAN_CONTEXT_PENDING_USER] = User(username=generate_id()) | ||
session = self.client.session | ||
session[SESSION_KEY_PLAN] = plan | ||
session.save() | ||
|
||
url = reverse("authentik_api:flow-executor", kwargs={"flow_slug": self.flow.slug}) | ||
with patch( | ||
"authentik.stages.email.models.EmailStage.backend_class", | ||
PropertyMock(return_value=EmailBackend), | ||
): | ||
response = self.client.post(url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertStageResponse( | ||
response, | ||
self.flow, | ||
response_errors={ | ||
"non_field_errors": [{"string": "email-sent", "code": "email-sent"}] | ||
}, | ||
) | ||
self.assertEqual(len(mail.outbox), 0) | ||
|
||
def test_send_error(self): | ||
"""Test error during sending (sending will be retried)""" | ||
plan = FlowPlan(flow_pk=self.flow.pk.hex, bindings=[self.binding], markers=[StageMarker()]) | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# CVE-2023-39522 | ||
|
||
_Reported by [@markrassamni](https://github.com/markrassamni)_ | ||
|
||
## Username enumeration attack | ||
|
||
### Summary | ||
|
||
Using a recovery flow with an identification stage an attacker is able to determine if a username exists. | ||
|
||
### Patches | ||
|
||
authentik 2023.5.6 and 2023.6.2 fix this issue. | ||
|
||
### Impact | ||
|
||
Only setups configured with a recovery flow are impacted by this. | ||
|
||
### Details | ||
|
||
An attacker can easily enumerate and check users' existence using the recovery flow, as a clear message is shown when a user doesn't exist. Depending on configuration this can either be done by username, email, or both. | ||
|
||
### For more information | ||
|
||
If you have any questions or comments about this advisory: | ||
|
||
- Email us at [[email protected]](mailto:[email protected]) |
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