Best practice for allowing Markdown in Python, while preventing XSS attacks?

前端 未结 2 656
孤街浪徒
孤街浪徒 2021-01-30 22:25

I need to let users enter Markdown content to my web app, which has a Python back end. I don’t want to needlessly restrict their entries (e.g. by not allowing any HTML,

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 23:15

    Markdown in Python is probably what you are looking for. It seems to cover a lot of your requested extensions too.

    To prevent XSS attacks, the preferred way to do it is exactly the same as other languages - you escape the user output when rendered back. I just took a peek at the documentation and the source code. Markdown seems to be able to do it right out of the box with some trivial config tweaks.

提交回复
热议问题