Prevent information leakage on registration when using PowEmailConfirmation #350
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adheres to OWASP recommendation to show the default confirmation required message when a user attempts to register with an already taken e-mail, but otherwise has valid params.
This to some degree prevents information leakage about an accounts existence as discussed in #238 (comment). I will also implement the same logic for authentication with invalid credentials for existing user to fully prevent fully any information leakage.
I'm not completely convinced that the controller callbacks should have this expectation of the changeset map since I try to make any Phoenix modules just pass along whatever is sent to them without caring what it is to have clear separation of responsibility. I kind of wish I could handle it at the Ecto level, but it really only makes sense to have this logic in the controller callbacks to figure out the correct response based on error type. In PowAssent I've let the context method return an error that could be acted upon. It might be difficult to implement this with how the Pow context works though, since there is only extension callback in the changeset, not for context methods.
One doubt I have about the logic is that this only checks the email taken. What if you have both email and username? In that case it should probably check both the user id and email. But what if there is an additional unique field defined by the user? I'll think about this and figure out what is appropriate.
Edit: I've changed the logic so the success message is always shown when email has been taken disregarding any other errors there may be.