Skip to content

Update phx.gen.auth with sudo mode and magic links #6041

Open
@josevalim

Description

Today phx.gen.auth generates the following functionality:

  1. Registration
  2. Login / logout
  3. Confirmation
  4. Forgot password
  5. Change email/password

I believe we can improve both the user experience and reduce the amount of generated code with a few changes. Behind the scenes, forgot password already behaves as magic links with extra steps. My proposal is:

  1. Introduce magic links as an official mechanism and remove "Forgot password"
  2. For users who forget their password, they can use a magic link and then change their password in Settings
  3. In order to keep changing email and passwords safe, we will introduce "sudo mode" that expects users to have authenticated within the last 15 minutes

This keeps the threat model roughly the same given anyone with access to the user email today is already capable of resetting and changing the user password. Anyone with access to the email can also change the email used in the account too.

Furthermore, requiring the user to enter "sudo mode" upfront actually improves the user experience as changes to email/password will immediately take effect instead of requiring an email confirmation later, which the user may forget. It also simplifies the code considerably and provides a more reusable functionality (as it can be used to authenticate other features as done by GitHub).

My only question is if we should change the confirmation feature to be implemented on top of magic links too. Today, confirming an account does not sign the user in, as we want to avoid leaked tokens from giving user access. However, password recovery (and magic links) give a leaked token access. There are two possible arguments here:

  1. Keep confirmation separate, as such emails are sent by default after sign in, and theoretically certain users may not even use password recovery or magic links (therefore they would never be vulnerable to token exposure)

  2. Realistically most users will use magic links and password recovery. Furthermore a user who is being targeted will be vulnerable to those attacks anyway. Therefore there is little benefit in not giving users access after confirmation

In any case, using a magic link should automatically confirm the account anyway. Thoughts?

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions