This is my current session management:
if(!isset($_SESSION["user"]["authenticated"]) ||
!$_SESSION["user"]["authenticated"])
redirect("login.php");
if($_SESSION["user"]["browserHash"] != md5($_SERVER["HTTP_USER_AGENT"]))
redirect("logout.php?err=browser_mismatch");
if($_SESSION["user"]["IPHash"] != md5($_SERVER["REMOTE_ADDR"]))
redirect("logout.php?err=ip_mismatch");
if(!isset($_SESSION["user"]["nonce"]) ||
$_SESSION["user"]["nonce"] == $_COOKIE["SITE_nonce"])
{
$nonce = md5(mt_rand() . time() . $_SERVER["REMOTE_ADDR"]);
$_SESSION["user"]["nonce"] = $nonce;
setcookie("SITE_nonce", $nonce, (60 * 15), "/path");
}
else
redirect("logout.php?err=nonce_mismatch");
I am aware of changing IP issues an plan on using only the first 3 parts of the IP address. But what I am concerned about is the attacker is able to sniff headers and such. Then I won't be protected right? If I were an attacker within the victims network, I would simply make a quick GET request after I sniff one response header and I will get the regenerated nonce. Is there really a way to prevent this?
If it wouldn't be too much, I was also hoping on getting an insight on my approach. How can this be circumvented? Am I missing something big?