views:

401

answers:

3

I want to integrate a shopping cart in my site. The cart should be such that it resets once the user signs out of the application. This can be either achieved via sessions or using the database tables.

What should be prefered out of the above two? Are there any security loop holes if this is handled via sessions?

A: 

I don't see why HttpSessions increase your security exposure - if your session is hijacked then presumably so is your DB access.

If you really intend that your user's cart should be transient then clearly your HttpSession is sufficient. Scaling app servers usually have session replication capabilities to deal with individual server failures.

I'm sceptical in the long term that such a volatile cart will always be what you want, I find it very convenient to browse around Amazon and assemble my cart, then just leave it for while. As it's probably not a great deal more work to persist your cart in a DB, I'd probably go for that.

djna
A: 

I would use Sessions - no point of clogging up your DB on data that will be destroyed on log out.

Plus, Sessions are quite safe to use.

waqasahmed
+1  A: 

In the security department, none of the two are prefered over the other. You should understand that both concepts are basically "sessions", but one is handled in the appdomain, the other is handled in the DB-domain.

Appdomain sessions:

  • Faster (No round-tripping to database)
  • Not scalable
  • Prone to concurrency problems on server farms
  • Sessions will be lost on server restart

Database sessions:

  • Slower (Roundtrips to the DB for each request)
  • Easier to scale on serverfarms
  • Sessions will be kept open on server restarts

You should consider how many users will be using your site. If you are looking at a lot, you are probably going to need multiple servers, in which case the database sessions will be your best bet, if you will stay with a single webserver / database server, then appdomain sessions will do fine.

cwap