3 ms·
why do people use cryptographically signed tokens for secret tokens (reset password / confirmation)? it should be safer to generate a random string and if the t
by benmmurphy 4y ago
why do people use cryptographically signed tokens for secret tokens (reset password / confirmation)? it should be safer to generate a random string and if the token needs to expire to store a timestamp in the database. revocation can then be performed on individual tokens. I can see why people might be more tempted to use these crypto-tokens for session storage to avoid the database but I think if this is a requirement then you should be using redis or some other fast key storage to hold the sessions.
if you are worried about timing attacks then you can just have your routes in the form of `/user/<id>/reset_password/<token>` and pull the user out of the DB and then do the comparison using a timing safe function. alternatively, if that is not possible and you need to do a lookup by the token its possible to blind the value stored in the DB but i would avoid that because it introduces another cryptographic primitive unnecessarily. and having only index on user_id and not having to have indexes on all your tokens saves space as well!
- aobdev 4y agoI think the most secure approach is to store a random id in the database and to also sign it any time it’s exposed to the user (as a cookie or url sent via email). The first benefit is that you won’t be exposed to DoS attacks whereby you’re querying non-existent tokens from your database, and the second benefit is that illegitimate sessions can only be established by compromising both your database sessions table and your application’s signing secrets.
- benmmurphy 4y agoif you worried about a database compromise you can use the blinding trick. so you expose secret to the user and store HASH(secret).