Skip to content
Snippets Groups Projects
Commit beb4db73 authored by Patrick Radtke's avatar Patrick Radtke
Browse files

authfacebook compatability with Facebook strict URI match

Per https://developers.facebook.com/docs/facebook-login/security/#strict_mode the
`state` parameter should be used for any state needed after the redirect, and the
redirect URI should remain constant.
parent 886534d1
No related branches found
No related tags found
No related merge requests found
...@@ -698,7 +698,7 @@ abstract class BaseFacebook ...@@ -698,7 +698,7 @@ abstract class BaseFacebook
$this->clearPersistentData('state'); $this->clearPersistentData('state');
return $_REQUEST['code']; return $_REQUEST['code'];
} else { } else {
self::errorLog('CSRF state token does not match one provided.'); self::errorLog('CSRF state token does not match one provided. ' . $this->state . '!=' . $_REQUEST['state']);
return false; return false;
} }
} }
......
...@@ -91,7 +91,7 @@ class sspmod_authfacebook_Auth_Source_Facebook extends SimpleSAML_Auth_Source { ...@@ -91,7 +91,7 @@ class sspmod_authfacebook_Auth_Source_Facebook extends SimpleSAML_Auth_Source {
$facebook = new sspmod_authfacebook_Facebook(array('appId' => $this->api_key, 'secret' => $this->secret), $state); $facebook = new sspmod_authfacebook_Facebook(array('appId' => $this->api_key, 'secret' => $this->secret), $state);
$facebook->destroySession(); $facebook->destroySession();
$linkback = SimpleSAML\Module::getModuleURL('authfacebook/linkback.php', array('AuthState' => $stateID)); $linkback = SimpleSAML\Module::getModuleURL('authfacebook/linkback.php');
$url = $facebook->getLoginUrl(array('redirect_uri' => $linkback, 'scope' => $this->req_perms)); $url = $facebook->getLoginUrl(array('redirect_uri' => $linkback, 'scope' => $this->req_perms));
SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT); SimpleSAML_Auth_State::saveState($state, self::STAGE_INIT);
......
...@@ -146,4 +146,11 @@ class sspmod_authfacebook_Facebook extends BaseFacebook ...@@ -146,4 +146,11 @@ class sspmod_authfacebook_Facebook extends BaseFacebook
} }
return implode('_', $parts); return implode('_', $parts);
} }
protected function establishCSRFTokenState() {
if ($this->state === null) {
$this->state = SimpleSAML_Auth_State::getStateId($this->ssp_state);
$this->setPersistentData('state', $this->state);
}
}
} }
...@@ -3,11 +3,15 @@ ...@@ -3,11 +3,15 @@
/** /**
* Handle linkback() response from Facebook. * Handle linkback() response from Facebook.
*/ */
if (!array_key_exists('AuthState', $_REQUEST) || empty($_REQUEST['AuthState'])) { // For backwards compatability look for AuthState first
throw new SimpleSAML_Error_BadRequest('Missing state parameter on facebook linkback endpoint.'); if (array_key_exists('AuthState', $_REQUEST) && !empty($_REQUEST['AuthState'])) {
$state = SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], sspmod_authfacebook_Auth_Source_Facebook::STAGE_INIT);
} elseif (array_key_exists('state', $_REQUEST) && !empty($_REQUEST['state'])) {
$state = SimpleSAML_Auth_State::loadState($_REQUEST['state'], sspmod_authfacebook_Auth_Source_Facebook::STAGE_INIT);
} else {
throw new SimpleSAML_Error_BadRequest('Missing state parameter on facebook linkback endpoint.');
} }
$state = SimpleSAML_Auth_State::loadState($_REQUEST['AuthState'], sspmod_authfacebook_Auth_Source_Facebook::STAGE_INIT);
// Find authentication source // Find authentication source
if (!array_key_exists(sspmod_authfacebook_Auth_Source_Facebook::AUTHID, $state)) { if (!array_key_exists(sspmod_authfacebook_Auth_Source_Facebook::AUTHID, $state)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment