codeigniter 2 以及如何禁用 TinyMCE 的 xss

2023-12-03

我搜索了每个网站,包括关于这个问题的 stackoverflow。

我全局开启了 XSS,并且很少有页面使用 TinyMCE。在这些页面上,我希望 TinyMCE 部分不启用 XSS。

读完大约 40 页后,他们都说要做以下事情:

$tiny_mce = $this->input->post('note'); // xss filtering off

or

$tiny_mce = $this->input->post('note', FALSE); // xss filtering off

我都尝试过,这是我的模型:

public function edit($id) {

          $tiny_mce = $this->input->post('note'); // xss filtering off
          $userId = $this->ion_auth->get_user_id();
          $data = array(
                        'note' => $tiny_mce
                        ,'postedBy' => $userId);
          $this->db->where('id', $id);
          $this->db->update('company_notes', $data);

}

有人知道为什么它不起作用吗?任何帮助都会很棒!我真的不想全局关闭 XSS,所以我希望有一个“ 每个基础”的方法。

Edit我刚刚尝试过

public function edit($id) {
          $this->config->set_item('global_xss_filtering', FALSE);
          $tiny_mce = $this->input->post('note'); // xss filtering off
          $userId = $this->ion_auth->get_user_id();
          $data = array(
                        'note' => $tiny_mce
                        ,'postedBy' => $userId);
          $this->db->where('id', $id);
          $this->db->update('company_notes', $data);

}

但这也行不通。


Controller 初始化后无法禁用 XSS 过滤。

因为如果你启用$config['global_xss_filtering'] = TRUE; at config.php文件,CodeIgniter执行XSS过滤$_POST, $_GET, $_COOKIE初始化之前Controllers, Models and ...

所以当你可以访问Controller一切都已完成。

虽然解决方案是禁用$config['global_xss_filtering']并根据需要对特定变量运行 XSS 过滤,有一种方法可以将原始值(预过滤的)保留在某处以供以后使用:

1)设置$config['enable_hooks'] to TRUE at application/config.php.

2)将以下内容插入到application/config/hooks.php:

$hook['pre_controller'] = array(
    'class'    => '',
    'function' => 'keep_vars',
    'filename' => 'keep_vars.php',
    'filepath' => 'hooks',
    'params'   => array($_POST, $_GET)
);

Note:我们正在使用这个Hook执行keep_vars()控制器初始化之前的函数(您可能还想考虑使用'pre_system' key).

3) Create keep_vars.php inside application/hooks/目录内容如下:

<?php

function keep_vars ($vars = array())
{
    if (empty($vars)) return;

    global $pre_filter;

    $pre_filter = array();

    foreach ($vars as $var) {
        $pre_filter = array_merge($pre_filter, $var);
    }
}

4)最后,当你想访问一个变量时$_GET or $_POST在您的控制器中,定义全局$pre_filter方法内的变量:

class Foo extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
    }

    public function bar ()
    {
        // define as global
        global $pre_filter;

        // check the pre XSS filtered values
        print_r($pre_filter);

        // you can get access to pre filtered $_POST['key'] by:
        echo $pre_filter['key'];
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

codeigniter 2 以及如何禁用 TinyMCE 的 xss 的相关文章

随机推荐