ASP.NET MVC 4 by default ignores HTML input in a post message. If I don't explicitly accept HTML, is there any code I need to write to defend my site against XSS attacks? I won't be using [AllowHtml]
or [ValidateInput(false)]
. I'm just trying to find out if I should worry about XSS attacks or not. I'm using Razor as my view engine.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
I found an excellent blog post by Amir Ismail that addresses all of your concerns. http://miroprocessordev.blogspot.com/2012/03/save-aspnet-mvc-application-against.html
To summarize what he writes.
Razor is encoded default unless Html.Raw
is used.
Html.AntiForgeryToken()
can be used to create a random token that will protect against CSRF however it requires the user to accept cookies.