CKEditor自动删除样式属性并添加xss属性'Removed'

时间:2017-08-28 06:40:27

标签: javascript php html ckeditor

CKEditor自动删除样式属性并添加xss属性'removed',就像我在一个元素中放置一个样式属性一样:

<div class="text-center" style="text-align: center;">Test Heading</div>

保存后我得到以下输出:

<div class="text-center" xss="removed">Test Heading</div>

我的配置是:

var toolbar_custom=[
    { name: 'document', items: [ 'Source' ] },
    { name: 'editing', items: [ 'Scayt' ] },
    { name: 'basicstyles', items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] },
    { name: 'paragraph', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] },
    { name: 'insert', items: [ 'Image', 'Flash', 'Table', 'HorizontalRule', 'Smiley', 'SpecialChar', 'PageBreak', 'Iframe' ] },
    { name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
    { name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ]}

];

jQuery(function(){
        CKEDITOR.replace('template_editor_custom',{
            uiColor:'#2778a7', 
            toolbar:toolbar_custom,
            autoParagraph:false,
            enterMode:CKEDITOR.ENTER_DIV,
            allowedContent:true,
            extraAllowedContent:'*{*}'
        })
    });

HTML:

<textarea class="form-control textbox-style" id="template_editor_custom" name="page[content]" placeholder="Page content"><?php echo set_value('page[content]', $content); ?></textarea>

3 个答案:

答案 0 :(得分:3)

我在 CodeIgniter

中使用 CKEditor

使用$ this-&gt; input-&gt; post('filed_name',FALSE)的第二个参数

输入文字

select 
count(*)/sum(1/col) harmonic_mean,
sqrt(sum(col * col)/count(*)) quadratic_mean
from table1

示例1

<div style="background-color:#eee; padding:15px">
    <span style="font-size:16px;"> <u>Friendly Reminder</u> </span>
</div>

<强>输出

<?php
    echo html_escape($this->input->post('template_editor_custom'));
?>

示例2

<div xss=removed>
    <span xss=removed> <u>Friendly Reminder</u> </span>
</div>

<强>输出

<?php
    echo html_escape($this->input->post('template_editor_custom', FALSE));
?>

答案 1 :(得分:0)

这不是CKEditor的问题 我怀疑您使用的是CodeIgniter 2.x,并启用了“全局XSS过滤”功能。您需要在配置文件中将其关闭:

$config['global_xss_filtering'] = FALSE;

xss=removed是CodeIgniter中使用的典型清理方法。

答案 2 :(得分:0)

我通过更改core / Security.php文件解决了我的问题。 只需转到_sanitize_naughty_html函数并从这两个静态数组中删除样式标记:

static $naughty_tags    = array(
            'alert', 'prompt', 'confirm', 'applet', 'audio', 'basefont', 'base', 'behavior', 'bgsound',
            'blink', 'body', 'embed', 'expression', 'form', 'frameset', 'frame', 'head', 'html', 'ilayer',
            'iframe', 'input', 'button', 'select', 'isindex', 'layer', 'link', 'meta', 'keygen', 'object',
            'plaintext', 'style', 'script', 'textarea', 'title', 'math', 'video', 'svg', 'xml', 'xss'
        );

        static $evil_attributes = array(
            'on\w+', 'style', 'xmlns', 'formaction', 'form', 'xlink:href', 'FSCommand', 'seekSegmentTime'
        );

我在不影响整个网站安全的情况下解决了这个问题。将来如果要升级CI版本,那么升级后在Security.php中的_sanitize_naughty_html函数中找到这两个数组,并从这两个列表中删除样式标记。

谢谢。

相关问题