如何删除“Auth_Password”来自 ELMAH 日志

发布于 2024-08-05 06:28:37 字数 66 浏览 2 评论 0原文

出于相当明显的原因,我想确定删除 ELMAH 捕获的 Auth_Password 的最佳方法。这样做的最佳方法是什么?

For fairly obvious reasons, I would like to identify the best way to remove the Auth_Password from being captured by ELMAH. What is the best way to go about doing so?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦年海沫深 2024-08-12 06:28:37

由于 ELMAH 是开源的,我像这样修改了 Error.CS 文件。在 Error.CS 的 Error 构造函数内部(大约第 126 行),我添加了以下内容:

_serverVariables.Remove(AUTH_PASSWORD);
//AUTH_PASSWORD = const string = "AUTH_PASSWORD" AND SET ELSEWHERE

Since ELMAH is open source, I modified the Error.CS file like so. Inside of the Error cunstructor of Error.CS (about line 126), I added this:

_serverVariables.Remove(AUTH_PASSWORD);
//AUTH_PASSWORD = const string = "AUTH_PASSWORD" AND SET ELSEWHERE
情未る 2024-08-12 06:28:37

我刚刚遇到同样的事情;使用以下方法解决:

using Elmah;
using ElmahErrorLogModule = Elmah.ErrorLogModule;

namespace XXXX
{
    public class ErrorLogModule : ElmahErrorLogModule
    {
        protected override void OnErrorSignaled(object sender, ErrorSignalEventArgs args)
        {
            // Remove password from the server variables being serialized
            args.Context.Request.ServerVariables.Remove("AUTH_PASSWORD");

            //TODO: remove session id, cookie too?

            base.OnErrorSignaled(sender, args);
        }
    }
}

并将 web.config、configuration/system.webserver/modules 中的 ErrorLog 模块更新为:

<add name="ErrorLog" type="XXXX.ErrorLogModule" preCondition="managedHandler" />

这将解决问题,无需第二次往返。如果随后从传入请求中使用密码,那么这不是问题,因为 Elmah 源显示它需要副本。

我意识到对上述问题的回应有点晚了,但问题似乎已在当前的 Elmah for ASP 中得到纠正,而对于 Elmah.Mvc nuget 包则没有得到纠正。

I just encountered the same thing; solved using the following:

using Elmah;
using ElmahErrorLogModule = Elmah.ErrorLogModule;

namespace XXXX
{
    public class ErrorLogModule : ElmahErrorLogModule
    {
        protected override void OnErrorSignaled(object sender, ErrorSignalEventArgs args)
        {
            // Remove password from the server variables being serialized
            args.Context.Request.ServerVariables.Remove("AUTH_PASSWORD");

            //TODO: remove session id, cookie too?

            base.OnErrorSignaled(sender, args);
        }
    }
}

And updated the ErrorLog module in web.config, configuration/system.webserver/modules to:

<add name="ErrorLog" type="XXXX.ErrorLogModule" preCondition="managedHandler" />

This will solve the problem without a second round trip. Not a problem if the password is subsequently used from the incoming request as the Elmah source shows it takes a copy.

I realize this is a bit late in response to the above, but the problem seems to have been corrected in current Elmah for ASP, and not for Elmah.Mvc nuget package.

小嗲 2024-08-12 06:28:37

我无法让@Dominic Birch 的答案起作用,因为上下文是只读的。相反,我从 ErrorLog(在我的例子中是 MySqlErrorLog)派生并在那里执行:

public class FilteringMySqlErrorLog : MySqlErrorLog
{
    static readonly string[] _stripSearch = new[] { "password", "cardnumber", "ccnumber", "cvv" };

    public FilteringMySqlErrorLog(IDictionary config)
        : base(config)
    { }

    public override string Log(Error error)
    {
        error.ServerVariables.Remove("AUTH_PASSWORD");

        foreach (string key in error.Form.AllKeys.ToList())
        {
            if (_stripSearch.Any(x => key.IndexOf(x, StringComparison.InvariantCultureIgnoreCase) != -1))
                error.Form.Remove(key);
        }

        return base.Log(error);
    }
}

I wasn't able to get @Dominic Birch's answer working, because context is readonly. Instead, I derived from the ErrorLog (in my case, MySqlErrorLog) and did it there:

public class FilteringMySqlErrorLog : MySqlErrorLog
{
    static readonly string[] _stripSearch = new[] { "password", "cardnumber", "ccnumber", "cvv" };

    public FilteringMySqlErrorLog(IDictionary config)
        : base(config)
    { }

    public override string Log(Error error)
    {
        error.ServerVariables.Remove("AUTH_PASSWORD");

        foreach (string key in error.Form.AllKeys.ToList())
        {
            if (_stripSearch.Any(x => key.IndexOf(x, StringComparison.InvariantCultureIgnoreCase) != -1))
                error.Form.Remove(key);
        }

        return base.Log(error);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文