Răsfoiți Sursa

#4753 Make CSRF checking in grids optional

Alexander 2 ani în urmă
părinte
comite
eb0185050d
2 a modificat fișierele cu 14 adăugiri și 1 ștergeri
  1. 1 1
      grid.php
  2. 13 0
      inc/classes/BxDolGrid.php

+ 1 - 1
grid.php

@@ -32,7 +32,7 @@ if(method_exists($oGrid, 'init'))
 
 
 $sAction = 'performAction' . bx_gen_method_name(bx_process_input(bx_get('a')));
 $sAction = 'performAction' . bx_gen_method_name(bx_process_input(bx_get('a')));
 if (method_exists($oGrid, $sAction)) {
 if (method_exists($oGrid, $sAction)) {
-    if (BxDolForm::isCsrfTokenValid(bx_get('csrf_token'), false)) {
+    if ($oGrid->isActionCsrfCheckingDisabled() || BxDolForm::isCsrfTokenValid(bx_get('csrf_token'), false)) {
         $oGrid->$sAction();
         $oGrid->$sAction();
     }
     }
     else {
     else {

+ 13 - 0
inc/classes/BxDolGrid.php

@@ -252,6 +252,8 @@ class BxDolGrid extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
     protected $_sDefaultSortingOrder = 'ASC';
     protected $_sDefaultSortingOrder = 'ASC';
     protected $_iTotalCount = 0;
     protected $_iTotalCount = 0;
 
 
+    protected $_bActionCsrfChecking;
+
     /**
     /**
      * Constructor
      * Constructor
      * @param $aOptions array of grid options
      * @param $aOptions array of grid options
@@ -262,6 +264,8 @@ class BxDolGrid extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
 
 
         $this->_bIsApi = bx_is_api();
         $this->_bIsApi = bx_is_api();
 
 
+        $this->_bActionCsrfChecking = true;
+
         $this->_sObject = $aOptions['object'];
         $this->_sObject = $aOptions['object'];
         $this->_aOptions = $aOptions;
         $this->_aOptions = $aOptions;
 
 
@@ -647,6 +651,15 @@ class BxDolGrid extends BxDolFactory implements iBxDolFactoryObject, iBxDolRepla
     {
     {
         return bx_unicode_urldecode(bx_process_input(bx_get($this->_aOptions['order_get_field'])));
         return bx_unicode_urldecode(bx_process_input(bx_get($this->_aOptions['order_get_field'])));
     }
     }
+
+    public function setActionCsrfChecking($bCsrfChecking)
+    {
+        $this->_bActionCsrfChecking = $bCsrfChecking;
+    }
+
+    public function isActionCsrfCheckingDisabled() {
+        return !$this->_bActionCsrfChecking;
+    }
 }
 }
 
 
 /** @} */
 /** @} */