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



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

<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:'*{*}'
})
});

目录:

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

我在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>

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

$config['global_xss_filtering'] = FALSE;

xss=removed是CodeIgniter中使用的典型消毒方法。

我通过更改核心/安全.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(
'onw+', 'style', 'xmlns', 'formaction', 'form', 'xlink:href', 'FSCommand', 'seekSegmentTime'
);

我以这种方式解决了问题,而不会影响我的整个网站安全性。将来,如果要升级CI版本,则在升级后_sanitize_naughty_html安全性中的函数中找到这两个数组.php并从这两个列表中删除样式标记。

谢谢。

CKEDITOR 没有任何问题

从文件关闭config如下所示它将起作用

$config['global_xss_filtering'] = FALSE;

最新更新