Is there a risk in using @Html.Raw?

≡放荡痞女 提交于 2019-12-19 17:47:08

问题


Is there a risk in using @Html.Raw? It seems to me there shouldn't be. If there is a risk then wouldn't that risk already exist regardless of using @Html.Raw in that modern browsers such as Chrome will allow an edit injection of <script>malicious()</script> or even to change a form's post action to something else.


回答1:


@Html.Raw will allow executing any script that is on the value to display. If you want to prevent that you need to use @Html.AttributeEncode




回答2:


Correct, the risk is in how it is used. There's no risk inherent in Html.Raw. It's a tool, nothing more.




回答3:


If you are displaying user entered information it is better to use @Html.Encode().

In another words, if you are displaying non-user eneterd data you are safe to go with @Html.Raw()



来源:https://stackoverflow.com/questions/11144943/is-there-a-risk-in-using-html-raw

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