Ask HN: Client side or server side sessions?
I have been doing a lot of reading lately on sessions and cookies. I am almost obsessing over web security while learning Python/Flask and building some small apps to teach myself.
I know there is probably not a one size fits all kind of answer for this but what are the pros and cons of client side vs. server side sessions ? I was thinking of building server side session (using redis). Thoughts?
(
12 comments
| 7 points
| on HN
)
But they have cons too:
- If a user changes his password, other sessions will keep active until they expire. This is a problem when (and not if) an account gets compromised. You can fix this easily, for example, including a token for each user that changes when changing the password, but then it defeats the point of client-side: you have to store the last token somewhere in your server.
- With the default implementation of Flask, if your secret key somehow leaks, apart of the obvious problem, anybody could execute arbitrary code in your server. You can fix this easily and without any serious consequences (apart from kicking out all your already logged users) by using JSON to serialize the cookies instead of Pickle: https://gist.github.com/2501926
- You are limited to 4 KB of data. In a server-side solution the user has only a session ID that gets associated to all the data you want in your database.
Related discussion: http://flask.pocoo.org/mailinglist/archive/2011/8/15/securit...
Unless you are only doing one request at a time or you don't mind rolling back to older session data, avoid cookie-based client side sessions.
If you need more security why not use https all the time and better use two factor authentication?
BTW, would you mind explaining what is a client side session? Share a link may be? Really, I have never heard of them-
There are very few situations in which I'd store anything on the client other than a basic session id representing server-side state.
1. Store session data on server side (use redis for storage)
2. Only exhcnage session id b/w client and server using cookies (serialized using pickle ?)
3. Regenerate session id after login ? Is this needed though ?