How do I HTML Encode all the output in a web application?

前端 未结 11 1517
暖寄归人
暖寄归人 2020-12-10 17:20

I want to prevent XSS attacks in my web application. I found that HTML Encoding the output can really prevent XSS attacks. Now the problem is that how do I HTML encode every

11条回答
  •  旧时难觅i
    2020-12-10 17:33

    My personal preference is to diligently encode anything that's coming from the database, business layer or from the user.

    In ASP.Net this is done by using Server.HtmlEncode(string) .

    The reason so encode anything is that even properties which you might assume to be boolean or numeric could contain malicious code (For example, checkbox values, if they're done improperly could be coming back as strings. If you're not encoding them before sending the output to the user, then you've got a vulnerability).

提交回复
热议问题