Jump to content
MakeWebGames

Login problems: Your request has expired for security reasons! Please try again.


dnenb

Recommended Posts

This is the function that's causing my headache (in authenticate.php, mccode v2). If you can explain to me how this CSRF-system works and help me to fix it I'll send you $15.

 

// Check CSRF input
if (!isset($_POST['verf'])
       || !verify_csrf_code('login', stripslashes($_POST['verf'])))
{
   die(
           "<h3>{$set['game_name']} Error</h3>
Your request has expired for security reasons! Please try again.<br />
<a href='login.php'>> Back</a>");
}
Link to comment
Share on other sites

I'm not telling anyone that, sorry. I figure that if someone knows the script (and seen the problem before) they'll be able to help me with the problem without the link to my game.

The reason I ask is as I've tested every v2 version I have access to and a few modern browers with no issue, so really cannot test it out.

If you wish more help tell us the exact v2 version you're using, being able to recreate the issue goes a long way to fixing it.

Cheers.

As for the code, either the verf param isn't being passed or the value set on login.php doesn't match the one that is being retrieved when the function is called from authenticate.php.

Ps: the actual verify_csrf_code function is located in global_func.php (as far as I am aware)

Link to comment
Share on other sites

The reason I ask is as I've tested every v2 version I have access to and a few modern browers with no issue, so really cannot test it out.

If you wish more help tell us the exact v2 version you're using, being able to recreate the issue goes a long way to fixing it.

Cheers.

As for the code, either the verf param isn't being passed or the value set on login.php doesn't match the one that is being retrieved when the function is called from authenticate.php.

Ps: the actual verify_csrf_code function is located in global_func.php (as far as I am aware)

The version I'm using is 2.0.5b (from here).

It seems that there's a problem with the functions request_csrf_code() and verify_csrf_code() in authenticate.php. They look like this:

function request_csrf_code($formid)
{
   // Generate the token
   $token = md5(mt_rand());
   // Insert/Update it
   $issue_time = time();
   $_SESSION["csrf_{$formid}"] =
           array('token' => $token, 'issued' => $issue_time);
   return $token;
}

You can see that the token is stored in the session array $_SESSION["csrf_login"].

 

function verify_csrf_code($formid, $code)
{
   // Lookup the token entry
   // Is there a token in existence?
   if (!isset($_SESSION["csrf_{$formid}"])
           || !is_array($_SESSION["csrf_{$formid}"]))
   {
       // Obviously verification fails
       return false;
   }
   else
   {
       // From here on out we always want to remove the token when we're done - so don't return immediately
       $verified = false;
       $token = $_SESSION["csrf_{$formid}"];
       // Expiry time on a form?
       $expiry = 900; // hacky lol
       if ($token['issued'] + $expiry > time())
       {
           // It's ok, check the contents
           $verified = ($token['token'] === $code);
       } // don't need an else case - verified = false
       // Remove the token before finishing
       unset($_SESSION["csrf_{$formid}"]);
       return $verified;
   }
}

 

But when this function tries to get the token it seems to be different, resulting in $verified to always be false. But it works as it should in internet explorer. I'm literally banging my head against the wall here. Can aynone help me out?

Edited by dnenb
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...