ckeditor xss_防止在CKEditor 3.x中进行XSS“ on”属性攻击

ckeditor xss

CKEditor 3.x had issues with XSS /security issues with on attributes.  For example, you could trigger malicious code via an onerror attribute -- ouch!  Of course the problem has been fixed in CKEditor 4 but upgrading can be an issue if you have custom plugins.  Here's how the issue can be solved!

CKEditor 3.x的XSS / security问题与on属性有关。 例如,您可以通过onerror属性触发恶意代码-哎呀! 当然,该问题已在CKEditor 4中解决,但如果您具有自定义插件,则升级可能会成为问题。 这是解决问题的方法!

JavaScript (The JavaScript)

We'll use prototype monkey-patching to accomplish this security fix:

我们将使用原型猴子补丁来完成此安全修复程序:


// Prevent bad on* attributes (https://github.com/ckeditor/ckeditor-dev/commit/1b9a322)
var oldHtmlDataProcessorProto = CKEDITOR.htmlDataProcessor.prototype.toHtml;
CKEDITOR.htmlDataProcessor.prototype.toHtml = function(data, fixForBody) {
    function protectInsecureAttributes(html) {
        return html.replace( /([^a-z0-9)/gi, '$1data-cke-' + CKEDITOR.rnd + '-$2' );
    }
    
    data = protectInsecureAttributes(data);
    data = oldHtmlDataProcessorProto.apply(this, arguments);
    data = data.replace( new RegExp( 'data-cke-' + CKEDITOR.rnd + '-', 'ig' ), '' );

    return data;
};


The toHtml method of CKEDITOR.htmlDataProcessor is modified to remove the troublesome on attributes during HTML render within the editor, but the attributes are indeed kept within the editor contents value and will display when you switch CKEditor to source mode.  Problem solved!

修改了CKEDITOR.htmlDataProcessortoHtml方法,以消除在编辑器内进行HTML渲染期间出现麻烦on属性,但是这些属性确实保留在编辑器的内容值之内,并且在将CKEditor切换到源代码模式时将显示。 问题解决了!

翻译自: https://davidwalsh.name/prevent-xss-ckeditor

ckeditor xss

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值