I use AntiXSS but I still can hack page

放肆的年华 提交于 2019-12-06 13:26:31
Darin Dimitrov

I added AntiXSS library to my project

And where are you using it?

Make sure that you have not only added AntiXSS but you actually used it:

@Html.Raw(Microsoft.Security.Application.Sanitizer.GetSafeHtmlFragment(Model.Place.Description))

But remember that the new version of the AntiXSS library is a bit too restrictive and will strip tags like <strong> and <br> out which might not be desired.

As an alternative to the AntiXSS library you could use HTML Agility Pack to do this job. Rick Strahl blogged about a sample implementation.

Adam Tuliper - MSFT

First off you are displaying RAW Html- not encoded in any manner. If you want to display Html you should ideally be doing several things.

  1. Sanitize it with the antixss Sanitizer class using GetSafeHtmlFragment. Note that this wont protect you completely. Do this before saving to the DB.

  2. Implement the not yet fully supported headers to prevent other script from running. This is limited to only some of the modern browsers.

  3. Or... Dont allow html or don't allow any HTML outside of known character tags. Ie a whitelist approach so you allow <strong> and nothing outside of other alphanumeric chars is allowed.

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