环境:
IIS 8.5
.NET Framework 版本:4.6.2(使用 WebForms)
视窗服务器 2012 R2
问题:
正在报告以下异常:
BASE EXCEPTION: System.Web.HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (?).
at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()
at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)
BASE EXCEPTION HRESUT: -2147467259
EXCEPTION: System.Web.HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (?).
at System.Web.HttpRequest.ValidateInputIfRequiredByConfig()
at System.Web.HttpApplication.PipelineStepManager.ValidateHelper(HttpContext context)
Run Code Online (Sandbox Code Playgroud)
我们的日志中显示的其他信息:
PATH_INFO
/cities/index.aspx?locid=4163
----
QUERY_STRING
----
REMOTE_ADDR
66.249.65.204
----
REMOTE_HOST
66.249.65.204
----
REQUEST_METHOD
GET
----
SCRIPT_NAME
/cities/index.aspx?locid=4163
----
URL
/cities/index.aspx?locid=4163
----
HTTP_FROM
googlebot(at)googlebot.com
----
HTTP_USER_AGENT
Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
Run Code Online (Sandbox Code Playgroud)
我不明白的是,如果我在浏览器中剪切并粘贴路径,页面会呈现得很好并且没有错误。
问题:
任何建议将不胜感激,因为我试图了解当路径实际上有效时如何引发这个特定的“错误”。
提前致谢。
从 Asp.net 4.0+ 开始引入了严格的验证,因此您看到的任何错误都可能是其中的一部分。网址中有某些危险字符可能会导致 XSS 攻击。?其中之一也是如此。其余字符如下:
< > * % & : \ ?
Run Code Online (Sandbox Code Playgroud)
可能有两种解决方案
你可以让这些字符在您的网址,或至少某些字符,在配置下面的配置web config如下
<system.web>
<httpRuntime requestPathInvalidCharacters="<,>,*,%,&,:,\,?" />
</system.web>
可以回滚到asp.net 2.0,配置如下
<system.web>
<httpRuntime requestValidationMode="2.0" />
</system.web>
我突然明白为什么查询字符串在我们的日志中没有显示任何内容。编码“?”的请求 (%3f) 将导致引发上述异常,例如:
/cities/index.aspx%3flocid=4163
Run Code Online (Sandbox Code Playgroud)
编码的 %3f 被解释为路径的一部分,因此出现“从客户端检测到潜在危险的 Request.Path 值 (?)”的异常。
当我在浏览器中输入上面显示的 URL 时,会引发异常并且日志不包含查询字符串。所以我只能假设一切都正常运行,并且请求者正在对 ? 进行编码。当他们不应该的时候;基本上破坏了 URL 的查询字符串部分。
我们在 system.web 中也有 requestValidationMode="2.0",但不要使用 requestPathInvalidCharacters (httpRuntime) 设置。
| 归档时间: |
|
| 查看次数: |
12887 次 |
| 最近记录: |