【问题标题】:Application Insights secure cookiesApplication Insights 安全 cookie
【发布时间】:2016-09-07 07:19:51
【问题描述】:

您好,我有一个 WebApp,我在其上使用带有 Javascript SDK 的 Application Insights。在 Chrome 开发人员工具中,我看到有 2 个不安全的 cookie,ai_user 和 ai_session。我已经更改了我的应用程序中的代码以使所有其他 cookie 都安全,但我无法设法让这些 cookie 也同样安全。我直接在Microsoft Application Insights documentation page上发了一个问题 他们告诉我更新脚本,这导致我修复了一个错误,但 cookie 仍然不安全(详细信息在我上面链接评论部分的评论中,目前是该部分中的第一个热门评论)。我问了他们,​​但他们不再回复我。

我当前用于初始化应用程序洞察力的代码是

var appInsights = window.appInsights || function (n) {
            function t(n) { i[n] = function () { var t = arguments; i.queue.push(function () { i[n].apply(i, t) }) } } var i = { config: n }, u = document, e = window, o = "script", s = "AuthenticatedUserContext", h = "start", c = "stop", l = "Track", a = l + "Event", v = l + "Page", y = u.createElement(o), r, f; y.src = n.url || "CDN_PATH"; u.getElementsByTagName(o)[0].parentNode.appendChild(y); try { i.cookie = u.cookie } catch (p) { } for (i.queue = [], r = ["Event", "Exception", "Metric", "PageView", "Trace", "Dependency"]; r.length;) t("track" + r.pop()); return t("set" + s), t("clear" + s), t(h + a), t(c + a), t(h + v), t(c + v), t("flush"), n.disableExceptionTracking || (r = "onerror", t("_" + r), f = e[r], e[r] = function (n, t, u, e, o) { var s = f && f(n, t, u, e, o); return s !== !0 && i["_" + r](n, t, u, e, o), s }), i
        }({
            url: '//az416426.vo.msecnd.net/scripts/a/ai.0.js',
            enableDebug: __solutionConfigurationIsDebug,
            instrumentationKey: __applicationInsightsInstumentationKey
        });

        window.appInsights = appInsights;
        appInsights.trackPageView('index.html');

我必须添加“url”属性,否则它指向“localhost/CDN_PATH”,这当然是错误的。

更新:我还在 GitHub 上找到了this issue,这似乎正是我正在寻找的东西,但它仍然开放......

【问题讨论】:

    标签: javascript cookies azure-application-insights


    【解决方案1】:

    好的,因为我没有找到更好的方法,所以我解压了 ApplicationInsights 的源代码(可以找到 here 并像这样更改第 254 行:

    i.canUseCookies() && (i.document.cookie = n + "=" + t + u + ";secure;path=/")
    

    (简而言之,我已将 'secure;' 字符串添加到现有字符串中)。然后我重新压缩了 js 代码并更改了我的 AI 初始化脚本,如下所示:

    var snippet = {
                config: {
                    enableDebug: __solutionConfigurationIsDebug,
                    instrumentationKey: __applicationInsightsInstumentationKey
                }
            };
            var init = new Microsoft.ApplicationInsights.Initialization(snippet);
            var appInsights = init.loadAppInsights();
    

    现在它可以工作了(cookie 现在设置为安全的),但我仍然愿意接受更好的方法。这可能意味着分叉corresponding GitHub repository,我可能会稍后尝试。

    【讨论】:

    • 您是否尝试过向官方 GitHub 存储库提交拉取请求以及您的更改?您还可以通过在该 repo 上创建一个问题来在提交 PR 之前对其进行讨论。
    • 我现在看到已经有一个关于此的问题,其最新更新日期为 3 周前,比这篇文章年轻得多。 github.com/Microsoft/ApplicationInsights-JS/pull/379
    【解决方案2】:

    由于我没有找到更好的方法,所以我解压了 ApplicationInsights 的源代码 (可以在这里找到并像这样更改第 254 行:

    i.canUseCookies() && (i.document.cookie = n + "=" + t + u + ";secure;path=/") (简而言之,我已将 'secure;' 字符串添加到现有字符串中)。

    然后我重新压缩了 js 代码并更改了我的 AI 初始化脚本,如下所示:

    var snippet = {
                config: {
                    enableDebug: __solutionConfigurationIsDebug,
                    instrumentationKey: __applicationInsightsInstumentationKey
                }
            };
            var init = new Microsoft.ApplicationInsights.Initialization(snippet);
            var appInsights = init.loadAppInsights();
    

    现在它可以工作了(cookie 现在设置为安全的),但我仍然愿意接受更好的方法。

    这可能意味着分叉相应的 GitHub 存储库,我可能会稍后尝试。

    对于其他方面,您应该使用此链接:

    https://docs.microsoft.com/en-us/azure/web-application-firewall/ag/web-application-firewall-troubleshoot

    参考链接:

    Application Insights secure cookies

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-14
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 1970-01-01
      相关资源
      最近更新 更多