views:

1395

answers:

3

I am using codeigniter's session class to handle my PHP sessions. One of the session variables automatically created on every visit to the site is session_id:

The user's unique Session ID (this is a statistically random string with very strong entropy, hashed with MD5 for portability, and regenerated (by default) every five minutes)

On my site I need to have functionality to track unregistered user's and I currently have this implemented by comparing the visitor's session_id with a stored id value in a VISITOR table in the database. This works perfectly except for the fact that the session id times out every five minutes. I would like my application to remember visitors for longer than 5 minutes (kind of like what SO does when you post a question or answer without registering).

My question is this: can you see any security issues with simply extending the regeneration time of the session class (to something like 12 hours)?

Update: based on the answers I've seen so far, it seems like its more of a performance concern rather than a safety issue. Its kinda weird how the codeigniter session class works because when creating a new session, it also creates a new cookie which seems to persist as long as the session. I guess I could create another cookie with the session ID that lasts as long as I need it to. But how much of a performance concern would it be if I were to save the sessions for something like 12 hours? Would it slow things down unless I have millions of unique visitors within a 12 hour period (in which case I'd have bigger problems to worry about...)?

A: 

Depending on the amount of visitors to your site, saving sessions for 12 hours may not be a good idea. Why not use cookies? This is dependent on whether or not the user has it enabled in his browser though: http://www.php.net/setcookie.

Mr. Smith
my understanding may be off..but do sessions even get saved once the page is closed?
es11
I apologize for the confusion, perhaps I misunderstood. Sessions have a default set time-out period server side. Even if the user closes his browser, the session may continue to exist depending on the time out set.
Mr. Smith
A: 

Two things with that idea :

  • If users go away from their computer (without locking it / closing their browser), someone else might use it to go to your site with their account
    • well, that's probably not your problem
    • if you have some login/password fields, your users probably already have their login+password memorized by the browser anyway (well, for the registedred ones, anyway -- and those probably have more "power" than not registered ones)
  • If you have lots of users on your site, you will have more session files
    • as sessions are stored in files
    • (same if they are stored in DB / memcached -- in which case you must ensure you have configured memcached so there is enough RAM to store more sessions)

So, yes, there is a small security risk ; but I don't think it is really relevant.


Another idea would be to keep a short session lifetime, but to store some informations in cookies, with a lifetime more important than that ?
Enough information, actually, to allow re-creation of a new session, without the user noticing anything ?

But, yes, that would require a bit more work on your side...


To add a bit more precisions after your edit :

Its kinda weird how the codeigniter session class works because when creating a new session, it also creates a new cookie which seems to persist as long as the session.

This is the "standard" way of dealing with sessions -- at least, in PHP :

  • The session's data is stored in a file, on disk, on the server
  • and a cookie is used to keep a "link" between a user, and the file containing his session's information. Without that cookie, there would be no way of knowing which one of those files contains the session of a specific user.

But how much of a performance concern would it be if I were to save the sessions for something like 12 hours?

If you're having millions of users on your site, this will means having millions of files, each one containing the session's data of one user -- and it's not good to have too many files.
But is you are having a few hundreds user, that should be allright, I guess.

Pascal MARTIN
A: 

One Security Tip:

Leave True on sess_match_useragent(application/config/config.php)

Hitesh Chavda