Input Validation When Using a Rich Text Editor

跟風遠走 提交于 2019-12-04 21:20:00

How about AntiXSS?

rick schott

See my full answer here from similar question:

I have found that replacing the angel brackets with encoded angel brackets solves most problems

You could create a "whitelist" of sorts for the html tags you'd like to allow. You could start by HTML encoding the whole thing. Then, replace a series of "allowed" sequences, such as:

"&lt;strong&gt;" and "&lt;/strong&gt;" back to "<strong>" and "</strong>"
"&lt;em&gt;" and "&lt;/em&gt;" back to "<em>" and "</em>"
"&lt;li&gt;" and "&lt;/li&gt;" back to ... etc. etc.

For things like the A tag, you could resort to a regular expression (since you'd want the href attribute to be allowed too). You would still want to be careful about XSS; someone else already recommended AntiXSS.

Sample Regexp to replace the A tags:

&lt;a href="([^"]+)"&gt;

Then replace as

<a href="$1">

Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!