Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit 263df57

Browse files
committed
Merge pull request #311 from SammyK/add-state-to-rerequest
Added CSRF protection for rerequest links
2 parents 242879e + 5959fe8 commit 263df57

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Facebook/FacebookRedirectLoginHelper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,12 @@ public function getLoginUrl($scope = array(), $version = null, $displayAsPopup =
121121
public function getReRequestUrl($scope = array(), $version = null)
122122
{
123123
$version = ($version ?: FacebookRequest::GRAPH_API_VERSION);
124+
$this->state = $this->random(16);
125+
$this->storeState($this->state);
124126
$params = array(
125127
'client_id' => $this->appId,
126128
'redirect_uri' => $this->redirectUrl,
129+
'state' => $this->state,
127130
'sdk' => 'php-sdk-' . FacebookRequest::VERSION,
128131
'auth_type' => 'rerequest',
129132
'scope' => implode(',', $scope)

tests/FacebookRedirectLoginHelperTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ public function testLoginURL()
3232
}
3333
}
3434

35+
public function testReRequestUrlContainsState()
36+
{
37+
$helper = new FacebookRedirectLoginHelper(
38+
self::REDIRECT_URL,
39+
FacebookTestCredentials::$appId,
40+
FacebookTestCredentials::$appSecret
41+
);
42+
$helper->disableSessionStatusCheck();
43+
44+
$reRequestUrl = $helper->getReRequestUrl();
45+
$state = $_SESSION['FBRLH_state'];
46+
47+
$this->assertContains('state=' . urlencode($state), $reRequestUrl);
48+
}
49+
3550
public function testLogoutURL()
3651
{
3752
$helper = new FacebookRedirectLoginHelper(

0 commit comments

Comments
 (0)