I came across a session management class in PHP which encrypts session data in the session storage folder (i.e., /tmp) and can be decrypted later in your script using a key. I was wondering if it's really needed? If you already doing some session hijacking prevention like this (simplified) example:
session_start();
if (isset($_SESSION['fingerprint']))
if ($_SESSION['fingerprint'] != md5($_SERVER['HTTP_USER_AGENT'].'SECRETSALT'))
exit; // prompt for password
else
$_SESSION['fingerprint'] = md5($_SERVER['HTTP_USER_AGENT'].'SECRETSALT');
Do you still need to encrypt your session data? Or is encryption only needed if you are storing sensitive info via sessions (e.g., personal info, cc number, credentials) ?
Moreover, if you are validating whether a user is logged-in or not in a simple way like this:
// login.php
if ($_POST['password'] == $db_password)
{
$_SESSION['logged_in'] = true;
redirect_to_protected_area();
}
else
// show login again
// protected_area.php
if (!isset($_SESSION['logged_in']) OR !$_SESSION['logged_in'])
exit; // prompt for password
else
// show protected area
What damage can be done if session data is unencrypted and a hacker saw the data in plain sight (i.e., the md5 hash of the fingerprint and the logged_in = true). Can he actually log himself in or he must first "crack" the md5?
Note: md5 was used to simplify example, a much better hashing algo is used in real life.
/tmpthen/tmpis PHP's default session folder in a shared hosting environment. – IMB Aug 19 '12 at 18:08/tmpwritten on disk storage? Is it atmpfsfilesystem? – curiousguy Aug 19 '12 at 18:10tmpfsis but/tmpis usually just a regular folder in windows or linux. More info about it here: php.net/manual/en/… – IMB Aug 19 '12 at 19:10$_SESSIONso that attacks that read files in/tmpcan't divulge user info. – Polynomial Aug 19 '12 at 19:55