...and I hope you used a proper TOTP method to generate and validate this 6-digit code!
Re:Stupid Security Things
by gingerlime on Friday October 28, 2022 @03:10AM
(#33368515)
totp is good in theory but not ideal for sending via email. Users might miss the email, or it gets delayed, then they want to resend the email and end up with two codes or more. Which one to use then? and you might want bruteforce protection so you introduce a rate limit, which can lock users out in those scenarios.
I would not use a TOTP but a stateless HMAC token in this case. I was only evoking TOTP because the original comment mentioned a 6-digit code (which is not a proper way to reset a password).
Why? You just need a random number.
Re:Stupid Security Things
by lelanthran on Friday October 28, 2022 @07:17AM
(#33369949)
This!
Send them a random number. If you really need it time-based then store the expiry time along with the code you sent them.
Anytime you check the code you see if $current_time is greater than the $expiry_time.
In a security test of a bespoke password reset platform, I came across something quite similar, so you're not alone.
The JSESSIONID of the unauthenticated request for a password reset (as exposed to the client as a cookie) was used as the secret in the email sent to the user. Therefore an attacker knew the emailed token before it was even sent, and could reset the account password and take it over.
Re:Stupid Security Things
by andreareina on Friday October 28, 2022 @05:47AM
(#33369455)
Someone could also brute-force the 6 digit code from the hash.
I had to implement a "forgot password" feature in a web application. I implemented it via:
Someone could change the hash in the local storage and bypass this.Of course, I reverted to use Redis instead of local storage for this after like 3 days, fortunately with no mishaps.
I've since then made up my mind to not implement bad workarounds like this because it just felt so wrong.