Application Insights安全cookie

时间:2016-09-07 07:19:51

标签: javascript cookies azure-application-insights

您好我有一个WebApp,我正在使用Javascript SDK使用Application Insights。在Chrome开发者工具中,我看到有2个cookier,ai_user和ai_session,这些都不安全。我已经更改了我的应用程序中的代码,以使所有其他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,这似乎正是我正在寻找的,但它仍然是开放的......

1 个答案:

答案 0 :(得分:3)

好的,既然我找不到更好的方法,我已经解压缩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,我稍后会尝试。

相关问题