【问题标题】:Codeigniter and Ckfinder csrf_exclude_urisCodeigniter 和 Ckfinder csrf_exclude_uris
【发布时间】:2017-11-07 12:09:35
【问题描述】:

我在使用 Codeigniter 3 时遇到问题,CKfinder 关于 CSRF 保护

如果我在我的 Codeigniter 配置文件中使用以下内容,CKFinder 图像上传工作正常

$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();

如果我更改 $config['csrf_protection'] = TRUE; CKFinder 图片上传失败

我需要的是能够将 CKFinder 排除在 CSFR 保护之外 - 我尝试了以下方法,但似乎没有任何效果:

$config['csrf_exclude_uris'] = array('assets/plugins/ckfinder/.*+', 'assets/plugins/ckfinder/ckfinder.js', 'assets/plugins/ckfinder', 'admin/news/.*+');

任何指针将不胜感激

【问题讨论】:

  • 您需要找到一种方法将 csrf 令牌与所有 ajax 一起发送,并在 ajax 响应后更新 html 端的 csrf 令牌。
  • 你应该提到所有不应该检查 csrf 的 URI。它在浏览器调试控制台的网络选项卡中显示什么 URL?它将帮助您确定正确的 URI。
  • CKFinder $post 因操作而异。一个例子是:/assets/plugins/ckfinder/core/connector/php/connector.php?command=DeleteFiles&lang=en&type=Images&currentFolder=%2F&hash=91aa280181912a4c - 我需要能够排除:/assets/plugins/ckfinder/core /connector/php/* 但我不知道该怎么做?
  • 试试$config['csrf_exclude_uris'] = ['assets/plugins/ckfinder/.*?'];
  • 谢谢 - 但这没有用

标签: codeigniter csrf ckfinder


【解决方案1】:

希望这可能有效。它在我的情况下有效。

$config['csrf_exclude_uris'] = array('assets/plugins/ckfinder/[\s\S]*');

但据我所知,“资产”资源不需要任何 csrf 保护。

【讨论】:

    【解决方案2】:

    提交表单数据的URL。

    config.php 文件中添加以下行。这将起作用。

    $config['**csrf_exclude_uris**'] = array(
            *'device/deviceProcess/pushData'*
    );
    
    -- deviceProcess : Controller
    
    --- pushData : Method
    
    ----- URL : http://hostname/index.php/device/deviceProcess/pushData
    

    【讨论】:

      【解决方案3】:
      # Its work fine #
      $config['csrf_protection'] = TRUE;
      if(isset($_SERVER["PHP_SELF"])){
        $parts = explode("/",$_SERVER["PHP_SELF"]);
        $exclude_url_arr = array('login');
        if (!empty($exclude_url_arr[0])) {
          foreach($parts as $part) {
            if (in_array($part,$exclude_url_arr)) {
                $config['csrf_protection'] = FALSE;
                break;
            }
          }
        }
      }
      

      【讨论】:

        猜你喜欢
        • 2015-06-27
        • 1970-01-01
        • 2021-06-13
        • 1970-01-01
        • 1970-01-01
        • 2017-11-06
        • 1970-01-01
        • 1970-01-01
        • 2018-05-16
        相关资源
        最近更新 更多