【问题标题】:Disable global fitering for particular variables禁用特定变量的全局过滤
【发布时间】:2011-06-20 07:16:59
【问题描述】:

我已在我的配置文件中将 global_xss_filtering 设置为 TRUE。是否可以禁用特定数据的 xss 过滤 - 假设我想禁用 'title' post 变量的 xss 过滤。

有可能吗?

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    嗯,据我所知,您可以做一些小技巧。 您转到输入类 (system/core/input.php) 并更改 $xss_clean 参数的默认值。 它本身设置为 FALSE,因此您可以选择通过将 TRUE 传递给 $this->input->post() 或 get() 来更改它。

    post() 示例(在 input.php 的第 128 行),但您还需要申请 get。

    /**
        * Fetch an item from the POST array
        *
        * @access   public
        * @param    string
        * @param    bool
        * @return   string
        */
        function post($index = NULL, $xss_clean = TRUE)   // <-- Here I changed the default from FALSE to TRUE)
        {
            // Check if a field has been provided
            if ($index === NULL AND ! empty($_POST))
            {
                $post = array();
    
                // Loop through the full _POST array and return it
                foreach (array_keys($_POST) as $key)
                {
                    $post[$key] = $this->_fetch_from_array($_POST, $key, $xss_clean);
                }
                return $post;
            }
    
            return $this->_fetch_from_array($_POST, $index, $xss_clean);
        }
    

    现在,您关闭全局过滤(将其设置为 FALSE)。现在,您的输入将被自动过滤,除非您将 FALSE 指定为调用的第二个参数,例如 $this-&gt;input-&gt;post('title',FALSE).

    您也可以选择(而不是破解核心)想要扩展本机输入库,以便传递 TRUE 而不是 FALSE,类似于以下内容:

    class MY_Input extends CI_Input {
    
        function __construct()
        {
           parent::__construct();
        }
    
        //........
    
        function get($index = NULL, $xss_clean = TRUE)
        {
            return parent::get($index, $xss_clean);
        }
    
        //...........
    
        function post($index = NULL , $xss_clean = TRUE)
        {
            return parent::post($index, $xss_clean);
        }
    
    }
    

    它应该以相同的方式工作,并且每次更改核心文件时都不需要破解它。
    阅读手册上的extending the core 页面以获得更好的信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多