by throwaway_bad · 7y ago · 0 comments
Apparently there's no good way to do this other than pick a date that's far enough out in the future.
A stackover answer gave an example setting it for 10 years. I thought I would be defensive and set it to 20 years.
But then it will immediately break because 32 bit dates wrap around in 2038!
Why would that wrap around in 2038? Are you assuming that browsers handle this incorrectly?
I only thought about it because I was also saving the expiration in a session table in mysql and my expires column is a `timestamp` which is 4bytes. I was using a language that uses more than 32 bits for dates, so you're right, it probably would've sent out the right cookie.
Of course I don't expect everybody will be able to support those configurations. There are currently unknown security holes someplace in out old equipment so nobody sane will connect our old stuff to the public internet. Thus most developers are safe depending on users having something fairly new. However a few will target behind the firewall customers and they will be stuck supporting whatever that old machines supports.
No solution is in sight, but things are getting better.
Do modern browsers still use 32 bit timestamps internally?
Regardless, it's probably not a good idea to rely on the browser saving cookies forever.
The Jurassic Park quote comes to mind: "Your scientists were so preoccupied with whether or not they could, they didn't stop to think if they should."