Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Cookies for Web Session State - What are the pitfalls?

Using in-process session state is evil when it comes to scaling web applications (does not play well with clusters, bombs out when server recycles).

Assuming you just need to keep a small amount of information in the session state, what is the downside of using encrypted cookie items for this purpose rather than specific state servers/db’s?

Obviously using cookies will create a small amount of network overhead, and clearly you operate under the assumption that cookies are enabled on the client browser/mobile device.

What other pitfalls can you see with approach?

Is this a good option for simple, scalable and robust sessions?

like image 881
nick_alot Avatar asked Dec 29 '08 22:12

nick_alot


People also ask

What are disadvantages of cookies?

The main drawback is the privacy for most users , The cookie enabled web browsers keep track of all the websites you have visited , The third parties can access the information stored by these cookies , These third parties can be advertisers , The other users or the government in some cases .

Which of the following are limitations of using cookies while using state management?

Some limitations of cookies include the fact that many browsers limit the amount of data sent through cookies (only 4,096 bytes are guaranteed) and that clients can potentially disable all cookie support in their browser.

What is cookies write advantages and disadvantages?

Most cookies are able to store information only up to 4kb. Browsers too pose restrictions when it comes to number of cookies. Except internet explorer, all other browsers only allow up to 20 cookies for a single website. Apart from security, privacy is another concern for users in cookies.

What is an advantage of sessions over cookies?

Sessions are more secured compared to cookies, as they save data in encrypted form. Cookies are not secure, as data is stored in a text file, and if any unauthorized user gets access to our system, he can temper the data.


2 Answers

This is an excellent approach for simple, scalable, and robust sessions. Of course the quality of your crypto is important, and that is often something that often proves tricky to get right, but it's possible to do.

I disagree with some of the other posters:

Any replay attack that can be launched against an encrypted cookie value can be launched against a session key stored as a cookie. Use https if this matters.

Session data stored in a state server or database is also lost if the cookie is cleared; when the session key is lost the session can no longer be retrieved.

like image 200
Sean Reilly Avatar answered Nov 02 '22 23:11

Sean Reilly


Another pitfall is that they can be stolen and replayed on your site.

BTW: Instead of storing some stuff in the cookie, you should also look at storing a key in the cookie and using something like memcached (memcached works across server farms).

like image 44
Robert C. Barth Avatar answered Nov 03 '22 00:11

Robert C. Barth