简体   繁体   English

富文本编辑,防止嵌入javascript代码

[英]rich text editing, prevent embeded javascript code

I made a website using the famous symfony framework. 我使用著名的symfony框架创建了一个网站。 I wanted to add rich editing feature to it. 我想为其添加丰富的编辑功能。 And I found TinyMCE editor. 我找到了TinyMCE编辑器。 But there comed a problem: how about the user embed some javascript code into the content? 但是出现了一个问题:用户如何在内容中嵌入一些javascript代码? such as alert('hello world'). 例如alert('hello world')。

I tested wordpress, which is a very famous blog software. 我测试了wordpress,这是一个非常著名的博客软件。 It faces the same problem. 它面临着同样的问题。 example . 例子

It is no big deal if some one embed an alert script. 如果有人嵌入了警报脚本,这没什么大不了的。 But what if they embed some dangerous code? 但是,如果他们嵌入了一些危险的代码怎么办? Have you encountered the same problem? 您是否遇到过同样的问题? Should I use markdown instead of html? 我应该使用markdown而不是html吗? Any good widget for markdown editing? 有什么好的Markdown编辑小部件?

最好使用现有的库来清理您的用户输入,即html purifier项目: http : //htmlpurifier.org/似乎维护得很好。

Don't allow any embedded javascript in your user input. 禁止在用户输入中使用任何嵌入式JavaScript。 This is easy to clean out either on the client or the server. 这很容易在客户端或服务器上清除。 Have a "white list" of HTML tags you support, and remove any event listener attributes from whatever you do allow. 有一个您支持的HTML标签“白名单”,并从您允许的所有内容中删除所有事件侦听器属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM