所见即所得和 XSS
我使用 TinyMCE 作为我的在线编辑器,但我担心 XSS 攻击等。 我虽然替换了所有 <
和 >
,但这似乎不是这种编辑器的一个选项,而且我不确定删除脚本标签是否有效也足够了(onclick、onmouseover 和其他事件怎么样)。
我应该采取什么方法来避免此类攻击?
I'm using TinyMCE as my online editor but I'm concerned of XSS attacks etc..
I though of replacing all <
and >
, but that doesn't seem to be an option with this kind of editor and I'm not sure removing script tags is enough too (what about onclick, onmouseover and other events).
What should be my approach to avoid such attacks?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你必须选择,安全还是便利。像TinyMCE这样的所见即所得编辑器非常方便。它允许非专家使用 Web 界面来更新某些带或不带 html 标签的内容。这是允许非技术人员更新 html 的偷懒方式,并且会带来各种危险。
当您允许用户访问数据库的 TinyMCE 接口时,这绝对等于为他们提供了一个数据库客户端来直接更新数据库中的数据。
另外,请注意,今天有大量非恶意的跨站点脚本,实际上是 facebook、linkedin、youtube 等集成,需要对第三方域等进行脚本引用。
因此,如果您强化 TinyMCE 工具因此无法添加 XSS,这对于认真的 Web 开发人员来说在很多情况下都是毫无用处的。
但是,如果您需要添加/编辑/更新/删除编辑器 XSS 证明,您需要验证和清理所有输入,而您的最佳选择是自己推出。
You have to choose, security or convenience. The WYSIWYG editor like TinyMCE is very convenient. It allows non-experts to use a web interface to update some content with or without html tags. Its the lazy way to allow someone non-technical to update html, and it comes with all kinds of hazards.
When you give users access to TinyMCE interface to your database it is absolutely equal to giving them a database client to update data directly in your database.
ALso, note that today there is a great deal of Cross-Site-Scripting that is not malicious, that is in fact facebook, linkedin, youtube, etc integration that requires script references to third party domains etc.
So if you harden the TinyMCE tool so that XSS can not be added it will be useless to a serious web developer in many scenarios.
But if you need to make an add/edit/update/delete editor XSS proof you need to validate and sanitize all inputs and your best choice is to roll your own.
理论上你可以像这样消除XSS,但实际上很难。似乎总有一些事情被你忽略了。
我发现的最好方法是使用正则表达式仅允许使用您指定的某些标签(
、等
)并删除所有其他标签。您还需要寻找对字符进行编码的用户试图规避您的保护的情况。In theory you can eliminate XSS like this, but in practice its difficult. There always seems to be something that you've overlooked.
The best way I've found is to use a regular expression to only permit use of certain tags that you specify (
<strong>, <em> etc
) and remove all others. You also need to look for attempts to circumvent your protection by users encoding characters.