Application Insights保护cookie

卢加诺(Mirko Lugano)

嗨,我有一个WebApp,我在其中使用Application Insights和Javascript SDK。在Chrome开发人员工具中,我看到有2个cookier,ai_user和ai_session并不安全。我已经更改了我应用程序中的代码,以确保所有其他cookie都安全,但是我无法保证这些cookie也同样安全。我直接在Microsoft Application Insights文档页面上发布了一个问题,他们告诉我更新脚本,这导致我修复了一个错误,但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上发现了这个问题,这似乎正是我在寻找的问题,但它仍然处于打开状态...

卢加诺(Mirko Lugano)

好的,因为找不到更好的方法,所以我解压缩了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存储库,我稍后可能会尝试。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章