This time I am going to be brief :-)
Instead of issuing randomly generated session strings to a user and inserting them into database, mapping these to user identifiers, for subsequent lookup on every authentication, why not do the following, with the intention to avoid database access on every request and distribute the session store instead:
- Take the user's identifier
- Take a chosen expiry (date and) time
- Put the two above together
- Pad them with a 'salt' - here a secret string of (a longer) arbitrary length
- Encrypt the resultant string with a secret encryption key
The result would be a string that is sent to the user (using HTTP Cookie mechanism) as the session key. Obviously, on authentication, the procedure is reversed by the server again, to extract a user identifier. If the expiry datetime checks out, that is. The session string would be considered infeasible for the client to cook up himself, because a brute-force attack is required where a large amount of salts and large amount of decryption keys will have to be tried, plus a correct structure of the unencrypted data has to be guessed.
My question is: what are the security related implications of the method I outlined? In my opinion, obvious advantages are:
- The sessions are not in a centralized store, but are distributed instead.
- Expiration value still ensures that these distributed sessions do not circulate indefinitely.
- If decryption is speedier and less complicated than database access, the method is obviously faster as well.