This repository was archived by the owner on Jan 13, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +8
-16
lines changed Expand file tree Collapse file tree 1 file changed +8
-16
lines changed Original file line number Diff line number Diff line change @@ -235,27 +235,19 @@ public function getAccessToken($redirectUrl = null)
235235 protected function validateCsrf ()
236236 {
237237 $ state = $ this ->getState ();
238- $ savedState = $ this ->persistentDataHandler ->get ('state ' );
239-
240- if (!$ state || !$ savedState ) {
241- throw new FacebookSDKException ('Cross-site request forgery validation failed. Required param "state" missing. ' );
238+ if (!$ state ) {
239+ throw new FacebookSDKException ('Cross-site request forgery validation failed. Required GET param "state" missing. ' );
242240 }
243-
244- $ savedLen = strlen ($ savedState );
245- $ givenLen = strlen ($ state );
246-
247- if ($ savedLen !== $ givenLen ) {
248- throw new FacebookSDKException ('Cross-site request forgery validation failed. The "state" param from the URL and session do not match. ' );
241+ $ savedState = $ this ->persistentDataHandler ->get ('state ' );
242+ if (!$ savedState ) {
243+ throw new FacebookSDKException ('Cross-site request forgery validation failed. Required param "state" missing from persistent data. ' );
249244 }
250245
251- $ result = 0 ;
252- for ($ i = 0 ; $ i < $ savedLen ; $ i ++) {
253- $ result |= ord ($ state [$ i ]) ^ ord ($ savedState [$ i ]);
246+ if (\hash_equals ($ savedState , $ state )) {
247+ return ;
254248 }
255249
256- if ($ result !== 0 ) {
257- throw new FacebookSDKException ('Cross-site request forgery validation failed. The "state" param from the URL and session do not match. ' );
258- }
250+ throw new FacebookSDKException ('Cross-site request forgery validation failed. The "state" param from the URL and session do not match. ' );
259251 }
260252
261253 /**
You can’t perform that action at this time.
0 commit comments