Alex Trofimov 8 лет назад
Родитель
Сommit
c3e80e047e

+ 21 - 23
inc/classes/BxDolForm.php

@@ -749,8 +749,6 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
             $this->aFormAttrs['action'] = '';
             $this->aFormAttrs['action'] = '';
 
 
         $this->_sCheckerHelper = isset($this->aParams['checker_helper']) ? $this->aParams['checker_helper'] : '';
         $this->_sCheckerHelper = isset($this->aParams['checker_helper']) ? $this->aParams['checker_helper'] : '';
-
-        BxDolForm::genCsrfToken();
     }
     }
 
 
     /**
     /**
@@ -987,32 +985,32 @@ class BxDolForm extends BxDol implements iBxDolReplaceable
 
 
     // Static Methods related to CSRF Tocken
     // Static Methods related to CSRF Tocken
     public static function genCsrfToken($bReturn = false)
     public static function genCsrfToken($bReturn = false)
+    {
+        // TODO: remove
+    }
+    public static function getCsrfToken()
     {
     {
         if (getParam('sys_security_form_token_enable') != 'on')
         if (getParam('sys_security_form_token_enable') != 'on')
             return false;
             return false;
 
 
-        $oSession = BxDolSession::getInstance();
-
-        $iCsrfTokenLifetime = (int)getParam('sys_security_form_token_lifetime');
-        if($oSession->getValue('csrf_token') === false || ($iCsrfTokenLifetime != 0 && time() - (int)$oSession->getValue('csrf_token_time') > $iCsrfTokenLifetime)) {
-            $sToken = genRndPwd(20, true);
-            $oSession->setValue('csrf_token', $sToken);
-            $oSession->setValue('csrf_token_time', time());
-        } else
-            $sToken = $oSession->getValue('csrf_token');
+        if (!($oKeys = BxDolKey::getInstance()))
+            return false;
 
 
-        if($bReturn)
-            return $sToken;
-    }
-    public static function getCsrfToken()
-    {
-        $oSession = BxDolSession::getInstance();
-        return $oSession->getValue('csrf_token');
+        return $oKeys->getNewKey (false, (int)getParam('sys_security_form_token_lifetime'));
     }
     }
-    public static function getCsrfTokenTime()
+    public static function isCsrfTokenValid($s)
     {
     {
-        $oSession = BxDolSession::getInstance();
-        return $oSession->getValue('csrf_token_time');
+        if (getParam('sys_security_form_token_enable') != 'on')
+            return true;
+
+        if (!($oKeys = BxDolKey::getInstance()))
+            return true;
+
+        if ($oKeys->isKeyExists($s)) {
+            $oKeys->removeKey($s);
+            return true;
+        }
+        return false;
     }
     }
 
 
     function _initCheckerNestedForms ()
     function _initCheckerNestedForms ()
@@ -1246,11 +1244,11 @@ class BxDolFormChecker
         }
         }
 
 
         // check CSRF token if it's needed.
         // check CSRF token if it's needed.
-        if (getParam('sys_security_form_token_enable') == 'on' && $this->_bFormCsrfChecking === true && ($mixedCsrfTokenSys = BxDolForm::getCsrfToken()) !== false) {
+        if (getParam('sys_security_form_token_enable') == 'on' && $this->_bFormCsrfChecking === true) {
             $mixedCsrfTokenUsr = BxDolForm::getSubmittedValue('csrf_token', $this->_sFormMethod, $this->_aSpecificValues);
             $mixedCsrfTokenUsr = BxDolForm::getSubmittedValue('csrf_token', $this->_sFormMethod, $this->_aSpecificValues);
             unset($aInputs['csrf_token']);
             unset($aInputs['csrf_token']);
 
 
-            if($mixedCsrfTokenUsr === false || $mixedCsrfTokenSys != $mixedCsrfTokenUsr) {
+            if ($mixedCsrfTokenUsr === false || !BxDolForm::isCsrfTokenValid($mixedCsrfTokenUsr)) {
                 $aInputs[$sSubmitName]['error'] = _t('_sys_txt_form_submission_error_csrf_expired');
                 $aInputs[$sSubmitName]['error'] = _t('_sys_txt_form_submission_error_csrf_expired');
                 return false;
                 return false;
             }
             }

+ 1 - 1
studio/template/scripts/BxBaseStudioFunctions.php

@@ -36,7 +36,7 @@ class BxBaseStudioFunctions extends BxBaseFunctions implements iBxDolSingleton
 
 
         $sHtml = $oTemplate->parseHtmlByName('login_form.html', array (
         $sHtml = $oTemplate->parseHtmlByName('login_form.html', array (
             'role' => BX_DOL_ROLE_ADMIN,
             'role' => BX_DOL_ROLE_ADMIN,
-            'csrf_token' => BxDolForm::genCsrfToken(true),
+            'csrf_token' => BxDolForm::getCsrfToken(),
             'relocate_url' => bx_html_attribute($sUrlRelocate),
             'relocate_url' => bx_html_attribute($sUrlRelocate),
             'action_url' => BX_DOL_URL_ROOT . 'member.php',
             'action_url' => BX_DOL_URL_ROOT . 'member.php',
             'forgot_password_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password'),
             'forgot_password_url' => BX_DOL_URL_ROOT . BxDolPermalinks::getInstance()->permalink('page.php?i=forgot-password'),

+ 4 - 2
template/scripts/BxBaseSearch.php

@@ -52,8 +52,10 @@ class BxBaseSearch extends BxDolSearch
                'action' => BX_DOL_URL_ROOT . 'searchKeyword.php',
                'action' => BX_DOL_URL_ROOT . 'searchKeyword.php',
                'method' => 'post',
                'method' => 'post',
             ),
             ),
-            'csrf' => array(
-                'disable' => true,
+            'params' => array(
+                'csrf' => array(
+                    'disable' => true,
+                ),
             ),
             ),
             'inputs' => array(
             'inputs' => array(
                 'live_search' => array(
                 'live_search' => array(