I make session cookies of form
session_id+'|'+hmac_sha256(session_id, static_secret) where
session_id = random_string(16 bytes) made with a PRNG (not a CSPRNG!) seeded on the server's timestamp at start-up.
The cookies have the
Secure flag so transport security is left to TLS to solve.
The session id is authenticated statelessly (i.e. without the need for a session database) the same way it was created, i.e. with
Is this breakable? If so, how?
Notes from brynk's answer:
A revocation list would have to be queried as a second authentication step to allow for killing sessions on stolen devices. This will make the session authentication stateful (though the list would likely be short).
The secret has to have 256bit+ of entropy if using HMAC-SHA256. Your cat should be able to handle that in 2-3 walks over the keyboard.
Using a PRNG for session id as opposed to say, an auto-incremented id does not make the cookie more secure. The reason I prefer it is because 1) it's stateless (don't have to keep a
next_idfile around), and 2) it hides the information of knowing how many sessions were generated before yours.