2

我一直在做ASP.NET项目我Request Validator是默认true 的因此不允许危险的脚本攻击,并且 ASP.NET 向我抛出错误危险请求

<script>alert('hello')</script>

这是非常好的。安全

但是为什么我的下面的脚本没有被阻止,ASP.NET 请求验证器没有被阻止下面的脚本

<%tag style=xss:expression(alert('hello'))>

这没有被阻止并被解雇

我的问题

1) <%tag style=xss:expression(alert('hello'))>
why this request was not blocked

2) <script>alert('hello')</script> 
This request was blocked and ASP.NET throws me to yellow error page
Is there any way to show error on the same page

请帮忙

谢谢

4

1 回答 1

0

1)这篇文章可能会帮助您更好地理解 validaterequest: https ://infosecauditor.wordpress.com/2013/05/27/bypassing-asp-net-validaterequest-for-script-injection-attacks/

一些摘录:

ValidateRequest 存在于 ASP.NET 版本 1、2 和 3 中。ASP.NET 版本 4 不使用 ValidateRequest 过滤器。

ValidateRequest 验证用户输入并在满足以下条件时返回 false:

<a-z     –    A ‘&lt;’ character followed by an alpha character.
<!, </, <?     –    A ‘&lt;’ character followed by a special character.
&,#    –    A special character.

您可以编写自己的自定义验证器,扩展 RequestValidator 并处理这些事情。 例如:

2) Is there any way to show error on the same page

是的。但随后您将不得不自己验证输入并告别 asp.net 的好处https://gargmanoj.wordpress.com/tag/httprequestvalidationexception/

不,因为发生了应用程序错误并且 asp.net 已停止处理它。但是您绝对可以显示自定义错误页面。

在此处此处查看答案:

protected void Application_Error(object sender, EventArgs e)
{
    var context = HttpContext.Current;
    var exception = context.Server.GetLastError();
    if (exception is HttpRequestValidationException)
    {
HttpContext.Current.Server.ClearError();
HttpContext.Current.Response.Redirect("~/ErrorPage.aspx");

        return;
    }
}

AntiXss编码器类还有一个用于对输出值进行编码的选项。

<httpRuntime encoderType="System.Web.Security.AntiXss.AntiXssEncoder" />
于 2017-09-19T13:32:52.520 回答