首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Codeigniter global_xss_filtering

Codeigniter global_xss_filtering
EN

Stack Overflow用户
提问于 2010-10-10 17:36:13
回答 5查看 16.1K关注 0票数 8

在我的codeigniter配置中,我有$config['global_xss_filtering'] = TRUE;。在我的管理部分,我有一个ckeditor,它生成前端内容。

在编辑器中输入和放置的所有内容都可以正常工作,图像可以很好地显示,html可以正常工作。除了闪光灯。每当我切换到html模式并粘贴一段youtube代码时,代码就会被转义,并且代码会显示在首页上,而不是显示youtube电影。

如果我设置了$config['global_xss_filtering'] = FALSE;,youtube代码就会像应该的那样被传递。这是因为CI将“object”、“embed”等标记为"naughty“,因此进行了转义。

我如何绕过这个控制器方法的xss过滤?

EN

回答 5

Stack Overflow用户

发布于 2010-10-11 18:07:47

默认情况下将其关闭,然后在真正需要它的地方启用它。

例如,我为我的所有控制器关闭了它,然后为评论、页面等启用了它。

您可以做的一件事是创建一个类似于PyroCMS中的MY_Input (或CI 2中的MY_Security ),并用一个完全相同的副本覆盖xss_clean方法,去掉正则表达式中的object|embed|部分。

http://github.com/pyrocms/pyrocms/blob/master/system/pyrocms/libraries/MY_Security.php

这是一个地狱般的漫长的道路,但它是有效的。

也许我们可以创建一个配置选项,列出2.0的坏元素?

票数 8
EN

Stack Overflow用户

发布于 2015-02-22 20:33:27

我的情况是,我希望global_xss_filtering在默认情况下是打开的,但有时我需要$_POST (pst您可以对任何全局php数组执行此操作,例如$_GET...)数据作为从浏览器发送的原始数据,所以我的解决方案是:

  1. 在project
  2. added的根文件夹中打开index.php以下代码行$unsanitized_post = $_POST; after $application_folder = 'application'; (第92行)

< code >H117然后,每当我需要原始$_POST时,我都会执行以下操作:

全局$unsanitized_post;

print_r($unsanitized_post);

票数 2
EN

Stack Overflow用户

发布于 2014-11-21 11:48:52

在CodeIgniter 2.0中,最好的做法是覆盖核心CI库上的xss_clean,使用MY_Security.php将其放在应用程序/核心文件夹中,然后使用/应用程序/config.php

代码语言:javascript
复制
$config['xss_exclude_uris'] = array('controller/method');

下面是MY_Security.php https://gist.github.com/slick2/39f54a5310e29c5a8387

代码语言:javascript
复制
<?php

/**
 * CodeIgniter version 2
 * Note: Put this on your application/core folder
 */

class MY_Security extends CI_Security {

    /**
     * Method: __construct();
     * magic
     */
    function __construct()
    {
        parent::__construct();
    }

    function xss_clean($str, $is_image = FALSE)
    {

        $bypass = FALSE;

        /** 
         * By pass controllers set in /application/config/config.php
         * config.php
         * $config['xss_exclude_uris'] = array('controller/method')
         */

        $config = new CI_Config;
        $uri = new CI_URI;
        $uri->_fetch_uri_string();
        $uri->_explode_segments();

        $controllers_list = $config->item('xss_exclude_uris');

        // we need controller class and method only
        if (!empty($controllers_list))
        {
            $segments = array(0 => NULL, 1 => NULL);
            $segments = $uri->segment_array();
            if (!empty($segments))
            {
                if (!empty($segments[1]))
                {
                    $action = $segments[0] . '/' . $segments[1];
                }
                else
                {
                    $action = $segments[0];
                }
                if (in_array($action, $controllers_list))
                {
                    $bypass = TRUE;
                }
            }

            // we unset the variable
            unset($config);
            unset($uri);
        }



        if ($bypass)
        {
            return $str;
        }
        else
        {
            return parent::xss_clean($str, $is_image);
        }
    }

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3899777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档