I'm using Devise 3.5 in my Rails 4.2 app. I've overridden all of the stock emails with custom HTML emails. Because of how I've designed the email delivery code, it's impossible for the email templates to have access to the hashed version of a token, such as the reset_password_token
.
The problem I'm having is that the email template only has access to the unhashed token that is stored in the database. I've tried using the unhashed token from the database in my email template, but when a user clicks the link, Devise's PasswordsController#update
calls resource_class.reset_password_by_token(resource_params)
. Devise::Recoverable then unhashes the token and tries to find the user. This fails because the unhashed token doesn't match the token in the database (because the token was already unhashed to begin with).
My question is three-part:
- What are the security implications of sending the unhashed token in emails such as the password reset email?
- I'm assuming that sending the unhashed token is a bad idea. If so, can I get around this problem by overriding
PasswordsController#create
so that I can intercept the hashed and unhashed tokens and save both to the database, therefore making the hashed token available to my mailer code? Are there security implications I should be aware of before attempting this approach? - Is there some way I can take the unhashed token and hash it before rendering my email template so that I can avoid a hacky workaround such as saving it to the database?