@@ -26,6 +26,32 @@ defmodule Mix.Tasks.Phx.Gen.Auth do
2626 to authentication views without necessarily triggering a new HTTP request
2727 each time (which would result in a full page load).
2828
29+ ## Security considerations
30+
31+ By default, `mix phx.gen.auth` generates an authentication solution that allows registration
32+ using email and magic links only. Users must verify their email address after registration
33+ by clicking a magic link, which both logs them in and confirms their email.
34+ This email confirmation is crucial for preventing session fixation attacks.
35+
36+ If you allow users to immediately log in after registering, either by registering with a password,
37+ or by directly logging them in after only providing an email address, the following attack is possible:
38+
39+ 1. An attacker registers a new account with the email address of their target, anticipating
40+ that the target creates an account at a later point in time.
41+ 2. The attacker sets a password (either when registering, or in the settings).
42+ 3. The target registers an account and sees that their email address is already in use.
43+ 4. The target logs in by magic link, but does not change the existing password.
44+ 5. The attacker maintains access using the password they previously set.
45+
46+ This is why the default implementation raises whenever a user tries to log in by magic link
47+ when there is already a password set. You can safely remove this check if you do not allow
48+ unconfirmed users to log in. In that case, registering with email and password is still secure.
49+
50+ If you want to allow unconfirmed users to log in, you need to ensure that they need to reset
51+ their password when they first sign in by magic link. To do this, you can add a required password
52+ field to the confirmation LiveView / template and re-use the password change functionality from
53+ the settings page.
54+
2955 ## Password hashing
3056
3157 The password hashing mechanism defaults to `bcrypt` for
0 commit comments