-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resend confirmation is allowing unconfirmed users to login #4536
Comments
Hi @luismfonseca , Just not updating the confirmation_sent_at timestamp when a new confirmation email is requested would not work because a new confirmation token would be considered always invalid. The only way I see to limit the unconfirmed access to the period after the first confirmation is sent, is to add another timestamp field first_confirmation_sent_at, to be used just to check how many days passed after the first confirmation was sent. I have implemented this solution here https://github.com/domangi/devise/tree/allow-unconfirmed-access-only-for-one-period Test Code
The method that checks if unconfirmed access is allowed becomes
Where first_confirmation_sent_at is set only the first time a confirmation is send. I don't know if it is the best solution, for sure it requires some work to be backwards compatible, since it ads a new column to the database, perhaps there could be a fallback on confirmation_sent_at if first_confirmation_sent_at is not present. @luismfonseca what do you think about this solution? |
Right, I think that makes sense. It's unfortunate that it can't be done without adding a new field though. :/ Can libraries in Rails add migrations so that the default value is copied over from |
@luismfonseca I don't know if there is a way to copy the default value from confirmation_sent_at during migration, but probably it is not needed. If you have to correct version and columns from beginning there is nothing to be done.
But step 2 is not necessary, because I added a fallback in case first_confirmation_sent_at is nil: The first time the value of first_confirmation_sent_at is checked, if it is nil then it is set equal to confirmation_sent_at. Test case
Implementation
I pushed the "fallback" to https://github.com/domangi/devise/tree/allow-unconfirmed-access-only-for-one-period |
Hi everyone, thanks for the report. I'm not sure I fully understood the problem, but we have a pull request open (#4792) which seems related to this issue. Can you take a look at it to see if it solves this issue too? |
Yes, that PR will solve this issue. 👍 |
Hi, @tegon. Any plans of merging it anytime soon? |
@tannakartikey the PR is still missing a test case for the new behavior. |
Is anyone interested in tackling this issue? #4792 seems to fix it, but it's lacking tests and now it seems like the author deleted its GitHub account. |
@tegon I'd be happy to tackle it. |
If we set
config.confirm_within = 1.days
andconfig.allow_unconfirmed_access_for = 1.days
, then a user can just trigger aresend_confirmation_instructions
which will cause the update fieldconfirmed_sent_at
to be updated.And since that gets set to
Time.now.utc
, the user is now able to login for the next 24h, without confirming the email address.The natural response to this would be to bump
confirm_within
, but that does not solve the actual problem, it only defers it.PS: I've searched for similar tickets and I haven't found any, but feel free to close this if a ticket already existed.
The text was updated successfully, but these errors were encountered: