TheThingsNetwork / lorawan-stack

The Things Stack, an Open Source LoRaWAN Network Server
https://www.thethingsindustries.com/stack/
Apache License 2.0
975 stars 306 forks source link

Allow user to re-request account validation email before token expires #6525

Closed nicholaspcr closed 1 year ago

nicholaspcr commented 1 year ago

Summary

As pointed out by @kschiffer in https://github.com/TheThingsNetwork/lorawan-stack/pull/6524 when a validation for an user's contact_info/email_address is requested, no other request can be made until the token expires.

Since the default TTL value of the token is 48 hours it would be in the user's interest for us to support re-sending the same validation a few extra times while the token is still valid. That way if by some reason the initial email does not reach the user, the request of another validation email can be done.

Current Situation

We sent a validation request to the email once and can only do it again after the period specified in the is.user-registration.contact-info-validation.token-ttl.

Why do we need this? Who uses it, and when?

It is an edge case but a user might not receive the validation email if:

Proposed Implementation

Cache the validation with a short TTL, use it to assert if we should or not send the same email again.

If the email (or a hash of the email) is present in the cache then the validation email was sent recently and it might be sent at maximum of X times, if it is not present then it should only be sent after the token is expired.

Contributing

Code of Conduct

nicholaspcr commented 1 year ago

https://github.com/TheThingsNetwork/lorawan-stack/pull/6524#issuecomment-1710292556

@KrishnaIyer replying in here just so we can develop the discussion in this issue.

I said we should rate-limit the RPC, not using the existing rate limiting code. If our current rate-limiting logic doesn't work then we figure something else out. We can think of a max limit of retries per email ID or something. The point is that we don't want bots continuously triggering emails.

I agree with what you said in regards to avoid continuously triggering the emails.

What I proposed in here is to allow the user to retry the RequestValidation procedure, not only a limited amount of times but for limited period of time as well. The reason behind this is to avoid people requesting validation every Y minutes until the token expires which I imagined it could be something a bot would do.

If you think the idea is overkill I'm also down to do a new implementation of the rate-limiting that would take something like email ID as its key. Could be in memory first and could be moved to using Redis by https://github.com/TheThingsIndustries/lorawan-stack/issues/2969, which is on backlog for a while but I've been meaning to pick this up again.

KrishnaIyer commented 1 year ago

Let's keep this simple. What's the problem:

Simple solution:

Something like this both solves the users' problems and we prevent spam. If we want to reduce this window to 15 mins or something based on how customers use this, thats fine.