【问题标题】:How do I stop leaking implementation details in my Azure Mobile app's OData errors?如何停止在 Azure 移动应用的 OData 错误中泄露实施细节?
【发布时间】: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


【解决方案1】:

(使用新信息更新答案)

事实证明,Web API 本身会发生这种情况,而标准的 ExceptionFilterExceptionHandler 机制似乎不起作用。

如果您收到 400,似乎对重写响应有效的一件事如下:

public class MyExceptionFilterAttribute : ActionFilterAttribute
{
    public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
    {
        if (actionExecutedContext.Response.StatusCode == System.Net.HttpStatusCode.BadRequest)
        {
            actionExecutedContext.Response.Content = new StringContent("An error occurred.");
        }
    }
}

可能有比这更好的方法。

【讨论】:

  • 我使用了 Azure 的官方“快速入门”I think this is the one。那里没有IncludeErrorDetailPolicy,所以在Startup.ConfigureMobileApp() 中我添加了cfg.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Never,但是即使堆栈跟踪现在已经消失了,它仍然会泄漏一些数据(完整的命名空间)。我正在查看 SDK 的代码以查看发生这种情况的位置,但到目前为止还没有发现任何东西,所以这可能是 WebAPI 问题和 SDK 问题?
  • 用更多信息更新了我的问题。我认为这是一个 WebAPI 问题,而不是“Zumo”问题,但话又说回来,错误消息讨论了属性的扩展,这是 Zumo 的事情。不确定。
  • Expand 是一个 Web API/OData/Entity Framework 的东西,根本不特定于 Zumo。但是,可能会应用一些默认配置。我会和一些更专业的人核实一下,然后回复你。
  • 我添加了另一个想法,但我建议发布一个新问题以将其缩小到仅 OData 本身,并将其标记为 asp.net,并查看是否有具有特定专业知识的人.
  • 是的,这听起来是个好主意,感谢您对此进行调查!
猜你喜欢
  • 1970-01-01
  • 2018-07-26
  • 1970-01-01
  • 2017-12-14
  • 2017-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多