Problem with Facebook login not matching CSRF state token

前端 未结 7 1981
离开以前
离开以前 2021-01-03 03:11

I did some searches and I didn\'t find anything that was related to my problem.

I\'m currently trying to implement a Facebook login to my website and I\'m having pro

7条回答
  •  庸人自扰
    2021-01-03 03:53

    The Facebook SDK code has a bug when checking against tokens twice in the same handler.

    I edited the getCode function of facebook.php like this:

    protected function getCode() {
        if (!isset($_REQUEST['code']) || !isset($_REQUEST['state']) || $this->state === null) {
            return false;
        }
        if ($this->state === $_REQUEST['state']) {
            // CSRF state has done its job, so clear it
            $this->state = null;
            $this->clearPersistentData('state');
            return $_REQUEST['code'];
        }
        self::errorLog('CSRF state token does not match one provided.');
    
        return false;
    }
    

    to be more clear and does not state an invalid token if called twice.

    To be clear the function can be called twice on the same URL handler if for example:

    $facebook->getUser(); and then in the same handler $facebook->getLogoutUrl() then the getCode() is called twice thus resulting into and invalid error message

提交回复
热议问题