Avoid XSS and allow some html tags with JavaScript

后端 未结 5 1193
自闭症患者
自闭症患者 2020-12-09 13:45

I\'ve got a problem in my current project: Users can send an email using a textarea. We allow the user to put in whatever they want, and thus some HTML for formatting. For e

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 14:09

    Best way to avoid most of the XSS attacks is:

    • By sanitizing your data so text is properly escaped before it hits the html (you can build exceptions for your and


      and others

    • Using Content Security Policy to disable all inline scripting (also avoids man in the middle attacks): http://www.html5rocks.com/en/tutorials/security/content-security-policy/

    These two together will make your site pretty robust

提交回复
热议问题