Markdown and XSS

前端 未结 5 1680
萌比男神i
萌比男神i 2020-12-31 10:20

Ok, so I have been reading about markdown here on SO and elsewhere and the steps between user-input and the db are usually given as

  1. convert markdown to html
5条回答
  •  自闭症患者
    2020-12-31 10:45

    There are two issues with what you've proposed:

    1. I don't see a way for your users to be able to format posts. You took advantage of Markdown to provide nice numbered lists, for example. In the proposed no-tags-no-exceptions world, I'm not seeing how the end user would be able to do such a thing.
    2. Considerably more important: When using Markdown as the "native" formatting language, and whitelisting the other available tags,you are limiting not just the input side of the world, but the output as well. In other words, if your display engine expects Markdown and only allows whitelisted content out, even if (God forbid) somebody gets to the database and injects some nasty malware-laden code into a bunch of posts, the actual site and its users are protected because you are sanitizing it upon display, as well.

    There are some good resources on the web about output sanitization:

    • Sanitizing user data: Where and how to do it
    • Output sanitization (One of my clients, who shall remain nameless and whose affected system was not developed by me, was hit with this exact worm. We have since secured those systems, of course.)
    • BizTech: Best Practices: Never heard of XSS?

提交回复
热议问题