gpt4 book ai didi

c# - ASP.NET 请求验证程序允许的脚本

转载 作者:太空宇宙 更新时间:2023-11-03 15:00:48 24 4
gpt4 key购买 nike

我一直致力于 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

请帮忙

谢谢

最佳答案

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

部分摘录:

ValidateRequest is present in ASP.NET versions 1, 2 and 3. ASP.NET version 4 does not use the ValidateRequest filter.

ValidateRequest validates user input and returns false when the following conditions are met:

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

您可以编写自己的自定义验证器,它扩展了 RequestValidator 并负责这些事情。 Eg:

2)有没有办法在同一页面上显示错误

是的。但随后您将必须自己验证输入并与 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" />

关于c# - ASP.NET 请求验证程序允许的脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46277154/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com