I am building a web API and I have a hard time choosing between cryptographic session token and stored random session token for user authentication.
I see several pros & cons for each:
stored random session token (store an expiring pair {token:userId} in a db):
- really random, with a negligible collision risk; an additional unique check can be done during database insertion
- stored in a database, which leads to scaling costs, devops maintenance costs
- tokens can be revoked
- no risk of cryptanalysis as long as the correct random function is used
cryptographic session token (use an strongly encrypted mix of 'userId, expiryTime' with a common symmetric key stored in the backend)
- random at each session, thanks to expiry time & a nonce
- no need to store them (no need for extra network calls) - symmetric decryption of session token will be faster. This leads to massive devops improvement and cost
- tokens cannot be revoked
- risk of cryptanalysis
- negligible but existing collision risk that cannot be prevented
- risk with the symmetric master key
The safer approach seems the stored random session token, however the costs & devops database related issues are really making me doubt.
Any help on the best practice, and whether the cryptographic session token would be considered bullet proof by security experts? Perhaps a suggestion of a stronger solution?
The provided link still acknowledges that both are used - I am wondering if a security expert will reject the crypto token for a banking website? Where do you draw the line?