CKEditor会自动删除样式属性并添加XSS属性“Removed”。

3

CKEditor会自动删除style属性并添加xss属性'removed',例如如果我在一个元素中放置style属性:

<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>
4个回答

6

我正在使用CodeIgniter中的CKEditor

它可以通过$this->input->post('filed_name', FALSE)的第二个参数来正常工作

输入文本

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

范例1

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

输出

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

例子2

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

输出

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

1

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

$config['global_xss_filtering'] = FALSE;

xss=removed 是 CodeIgniter 中常用的典型清洗方法。


{btsdaf} - Diptesh Atha
1
你不应该覆盖核心文件,这是非常糟糕的做法。没有人应该覆盖核心文件。实际上,将其设置为FALSE不会造成问题,因为从3.*.*开始的新版本中,它们不再使用它,只是为了旧版本的兼容性而存在。或者你可以使用$this->input->post($template_editor_custom, FALSE); - Anil Prz

1
我通过更改core/Security.php文件来解决我的问题。 只需转到_sanitize_naughty_html函数,并从这两个静态数组中删除style标签即可。
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函数中的这两个数组,并从这两个列表中删除样式标签。
谢谢。

1
不行,编辑核心代码从来都不是解决方案——如果你认为有问题,请提交一个错误报告! - whiteatom
谢谢,我不知道它的存在。@whitatom 这不是错误也不是漏洞,只是个人偏好,你认为在安全方面可以安全允许什么。 - Broly LSSJ

0

CKEDITOR没有任何问题。

只需在config文件中关闭它,就可以正常工作。

$config['global_xss_filtering'] = FALSE;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接