【问题标题】:ASP.NET Request Validator allowed scriptsASP.NET 请求验证器允许的脚本
【发布时间】:2018-02-26 20:44:53
【问题描述】:

我一直在从事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

请帮忙

谢谢

【问题讨论】:

    标签: c# asp.net request-validation


    【解决方案1】:

    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 验证用户输入并在 满足以下条件:

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

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

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

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

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

    查看答案here & here

    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" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-10
      • 2011-10-08
      • 1970-01-01
      • 1970-01-01
      • 2023-04-02
      相关资源
      最近更新 更多