Should i sanitize markdown?

半城伤御伤魂 提交于 2019-12-03 03:00:26

Markdown can contain arbitrary HTML; this is explicitly allowed. So you should sanitise it too, or at least sanitise the result of converting it to HTML, before sending to web clients.

I remember that one of the exploits possible with SO in the early days is that you could put JS content in the Markdown, and whoever edited your article would trigger those scripts in the preview. I don't know if this is fixed yet.

I've noticed that you "sanitize HTML before storing to db" and speak of xss-safe in the next sentence. Those are two different facets of input validation, and you should not mix them up, and address both in your design:

  • You should safely insert any user input into the database, i.e. make sure the input is properly escaped (mysql_real_escape_string, stored procedures, ORM libraries, etc.)

  • You should safely output to HTML / JS (including input to WMD), removing or escaping any sequences that can be turned into XSS exploits and other unpleasantness.

As to the question, I agree with Chris - since Markdown can include HTML, it must be sanitized.

Itay Moav -Malimovka

Just an addition:
This question came from using WMD

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