【问题标题】:Control the data being sent to AppInsight traces控制发送到 AppInsight 跟踪的数据
【发布时间】:2019-02-17 08:28:58
【问题描述】:

有没有办法控制发送到 AppInsights 跟踪的数据。正如官方文档所说,文件过滤和预处理是一种方法。我无法从 POST & PUT 获取属性(密码)。由于密码很敏感,我不想被发送到 App Insights。 以下是我的痕迹:

“值”:“client_id={someguid}&resource={someguid}&username={username}&password={password}&grant_type=password&scope=openid&nca=1;1;login-NonInteractive;False”

 public void Initialize(ITelemetry telemetry)
    {
        var requestTelemetry = telemetry as RequestTelemetry;
        if (requestTelemetry != null && (HttpContext.Current.Request.HttpMethod == HttpMethod.Post.ToString() || HttpContext.Current.Request.HttpMethod == HttpMethod.Put.ToString()))
        {
            using (var reader = new StreamReader(HttpContext.Current.Request.InputStream))
            {
                string requestBody = reader.ReadToEnd();
                requestTelemetry.Properties.Add("body", requestBody);
            }
        }
    }

【问题讨论】:

  • 当您提到“密码”属性时,您是要将密码发送给应用洞察,还是不发送给?你能提供更多细节吗?谢谢。
  • 是的,密码在请求遥测中以纯文本形式结束
  • 您发送密码的代码在哪里?还是由sdk自动发送?
  • 当 b2cazure 配置为开发模式时,所有详细信息都将发送过来
  • 在using语句中,拿到inputStream后,尝试替换密码或者remove。比如 if(requestBody.contains("password")){requestBody="new xxx"}.

标签: c# azure azure-application-insights telemetry


【解决方案1】:

在将数据推送到 appinsight 之前,我们通常会序列化我们的类对象。当您当时序列化您的类对象时,您应该忽略序列化中的属性。在 C# 中,您可以使用 System.Web.Script.Serialization 库的 ScriptIgnore 属性。

请浏览一下下面的帖子。

https://docs.microsoft.com/en-us/dotnet/api/system.web.script.serialization.scriptignoreattribute?view=netframework-4.8

如果 scriptignore 不能解决您的问题,那么您可以创建自己的属性。

【讨论】:

    【解决方案2】:

    直接的答案是目前Application Insights不支持

    您可以在这里查看如何处理Personal Data with Application insights

    注意:如果您有兴趣查看或删除个人数据,请 有关 GDPR 文章,请参阅Azure Data Subject Requests。如果你是 寻找有关 GDPR 的一般信息,请参阅GDPR section 服务信任门户。

    对于任何典型的项目,不建议将密码存储/显示为裸露(即使在日志中)严重侵犯隐私

    对于您的用例,正如 Ivan Yang 在评论中提到的那样。 您应该过滤掉/删除密码,而不是将整个请求正文内容放入/转储到应用洞察日志中。

       public void Initialize(ITelemetry telemetry)
        {
            var requestTelemetry = telemetry as RequestTelemetry;
            if (requestTelemetry != null && (HttpContext.Current.Request.HttpMethod == HttpMethod.Post.ToString() || HttpContext.Current.Request.HttpMethod == HttpMethod.Put.ToString()))
            {
                using (var reader = new StreamReader(HttpContext.Current.Request.InputStream))
                {
                    string requestBody = reader.ReadToEnd();
                    int startIndex= requestBody.LastIndexOf("&password=");
                    int endIndex= requestBody.LastIndexOf("&scope=");
                    requestBody = requestBody.Replace(requestBody.Substring(startIndex, (endIndex - startIndex) -1),""); 
                    requestTelemetry.Properties.Add("body", requestBody);
                }
            }
        }
    

    如果您真的希望在登录应用洞察时启用/关闭某些字段等功能,可以提供您的own feedback here 来屏蔽/取消屏蔽

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-04
      • 1970-01-01
      • 2014-03-17
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      相关资源
      最近更新 更多