在使用 MVC 3 的 ELMAH 中,如何从错误日志中隐藏敏感表单数据?
这是场景...
用户输入他的用户名。输入“不正确”的密码。 用户名和密码值都被传递到 Elmah 错误日志 通过Exception.Context.Request.Form[“密码”]
。 它是只读值,无法修改。
不...我不想忽略异常(失败)。我们以编程方式添加了 ErrorLog 过滤:
void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
if (e.Exception is LogOnException)
{
((HttpContext) e.Context).Request.Form.Remove("Password");
// This is what we want to do, but we can't because it is read-only
}
}
但无法修改 Request.Form,以便在错误日志中隐藏密码。
有人遇到过解决这个问题的方法吗?
我基本上想要所有没有密码字段的错误数据。我们考虑手动记录它,但与简单地隐藏敏感数据相比,这似乎需要大量工作。
干杯,伙计们。提前致谢。
Here is the scenario...
User types his username. Types an "incorrect" password.
Both username and password values are being passed to the Elmah error log
via the Exception.Context.Request.Form["Password"]
.
It's a read-only value and cannot be modified.
And no... I don't want to dismiss the exception (fail). We added ErrorLog Filtering programmatically:
void ErrorLog_Filtering(object sender, ExceptionFilterEventArgs e)
{
if (e.Exception is LogOnException)
{
((HttpContext) e.Context).Request.Form.Remove("Password");
// This is what we want to do, but we can't because it is read-only
}
}
But cannot modify the Request.Form so that the password is hidden from our error log.
Anybody ever encountered a way around this?
I basically want all the error data without the password field. We considered logging it manually but that seemed to be a lot of work compared to simply hiding the sensitive data.
Cheers guys. Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您无法修改请求上的表单集合,但可以修改 Elmah 错误实例上的表单集合,然后手动记录它。即
然后在 Global.asax 中
You can't modify the form collection on the request but you can modify the form collection on an Elmah Error isntance and then manually log it. I.e.
Then in Global.asax
捕获异常,然后手动在 ELMAH 中记录一些内容,如下所示:
Catch the exception, then log something in ELMAH manually, like this:
除非修改源本身,否则无法执行此操作。您当然可以修改配置并向其中添加“排除的表单元素”的概念,然后当 Error 类从 HttpContext 复制集合时,您可以删除该列表中的任何项目。
显然,另一种选择是使用其他东西,它可以对日志记录过程提供更明确的控制,例如 EntLib 或 log4net。编写模块或全局异常处理程序来利用这些工具中的任何一个都很简单。此外,它们与 Web 应用程序之外的范围相关。
You can't do this unless you modify the source itself. You could certainly modify the configuration and add the notion of an "Excluded Form Elements" to that, then when the Error class copies the collection from the HttpContext, you can remove any items in that list.
Another alternative would be to use something else, obviously, that provides more explicit control over the logging process like EntLib or log4net. It's trivial to write a module or global exception handler to utilize either one of those tools. Moreover, they are relevant in scopes outside of web applications.