我使用的是AntiXssLibrary 4.0,但它没有转义\x3c。我犯了什么错?
我已经将AntiXss配置为基于http://haacked.com/archive/2010/04/06/using-antixss-as-the-default-encoder-for-asp-net.aspx的默认HttpEncoder,并在web.config中设置了encoderType of httpRuntime。
我还创建了从AntiXSSEncoder派生而来的HttpEncoder,而不是废弃的
output.Write(AntiXss.HtmlEncode(value));我使用它来覆盖HtmlEncode方法:
output.Write(Encoder.HtmlEncode(value));目前,如果我浏览这个:
http://localhost:28453/?k=sss\x3cscript\x3ealert%28\x27haaha\x27%29;\x3c/script\x3e警报"haaha“显示AntiXss库不工作。我只想让http://channel9.msdn.com/Events/MIX/MIX10/FT05在第13分钟看到这个节目。
需要确认的是,我还在一个操作中设置了这一点:
public ActionResult Index(string k)
{
ViewBag.k = k;
ViewBag.j = Microsoft.Security.Application.Encoder.HtmlEncode(k);
return View();
}在我看来,我说:
<script type="text/javascript">
$(document).ready(function () {
var a = '@ViewBag.k';
var b = '@ViewBag.j';
$('.resultName:first').html(b);
});
</script>在浏览器中,值a和b是相同的,这表明AntiXss不能正常工作!
<script type="text/javascript">
$(document).ready(function () {
var a = 'sss\x3cscript\x3ealert(\x27haaha\x27);\x3c/script\x3e';
var b = 'sss\x3cscript\x3ealert(\x27haaha\x27);\x3c/script\x3e';
$('.resultName:first').html(b);
});
</script>更新:只有当我使用AntiXssEncoder作为编码器类型时才会发生这种情况。当我评论这个和重建的时候。单引号“被MVC逃脱了。看来AntiXss被禁用了!我是不是遗漏了什么?我想让它工作,因为我希望像\x3c一样像视频一样逃脱。
<!--<httpRuntime encoderType="AntiXSSEncoder, MVCWeb"/>-->发布于 2011-04-01 04:52:39
这是正确的,因为4.0 .NET已经在HTMLEncode中编码了撇号,而AntiXSS没有编码,因为严格地说,它不需要对HTMLEncode,只对属性字符串。
现在,一旦你把AntiXSS替换成编码器,假设不再适用,人们就会随处可见地使用Html编码。
因此,当我推送下一个版本的AntiXSS时,它将一直对撇号进行编码。
https://stackoverflow.com/questions/5497795
复制相似问题