【发布时间】:2017-01-04 03:08:29
【问题描述】:
我正在使用 Azure 移动应用服务。
假设我有一个Customer 实体,带有一个Orders 导航属性。然后我可以这样做:
http://foo.url.com/tables/Customer?$expand=Orders
但假设我尝试扩展非导航属性Foo:
http://foo.url.com/tables/Customer?$expand=Foo
然后我会在客户端(或邮递员)上得到这个:
{
"message": "The query specified in the URI is not valid. Property 'Foo' on type 'my.namespace.Customer' is not a navigation property. Only navigation properties can be expanded.",
"exceptionMessage": "Property 'Foo' on type 'my.namespace.Customer' is not a navigation property. Only navigation properties can be expanded.",
"exceptionType": "Microsoft.Data.OData.ODataException",
"stackTrace": " at Microsoft.Data.OData.Query.SyntacticAst.ExpandBinder... VERY LONG STACKTRACE..."
}
或者假设我尝试扩展不存在的属性Bar:
http://foo.url.com/tables/Customer?$expand=Bar
然后我会在客户端(或邮递员)上得到这个:
{
"message": "The query specified in the URI is not valid. Could not find a property named 'Bar' on type 'my.namespace.Customer'.",
"exceptionMessage": "Could not find a property named 'Bar' on type 'my.namespace.Customer'.",
"exceptionType": "Microsoft.Data.OData.ODataException",
"stackTrace": " at Microsoft.Data.OData.Query.SyntacticAst.ExpandBinder... VERY LONG STACKTRACE"
}
如果我编辑配置以包含config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Never,那么它仍然会在此错误中泄漏命名空间(它还鼓励攻击者执行枚举攻击并尝试各种排列):
{
"message": "The query specified in the URI is not valid. Property 'Foo' on type 'my.namespace.Customer' is not a navigation property. Only navigation properties can be expanded."
}
和
{
"message": "The query specified in the URI is not valid. Could not find a property named 'Bar' on type 'my.namespace.Customer'."
}
这会泄露许多攻击者感兴趣的实现细节。如何抑制/替换该错误消息?
【问题讨论】:
-
我不会说它会创建一个攻击向量,但它确实会泄露攻击者可能会感兴趣的信息。解决方案当然是捕获并重新引发异常。
标签: c# asp.net asp.net-web-api odata azure-mobile-services