应用程序洞察安全Cookie

问题描述:

您好我有一个WebApp,我在其中使用了Application Developer的Javascript SDK。在Chrome开发人员工具中,我看到有2个cookier,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'); 

我不得不添加的网址属性,否则它指向“本地主机/ CDN_PATH”这当然是错误的。

更新:我也发现this issue在GitHub上这似乎正是我期待的,但它仍然是开放的......

好了,因为我发现没有更好的办法来做到这一点,我已经解压缩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,我也许会稍后尝试。

+1

您是否尝试过使用您的更改向官方GitHub存储库提交请求?在提交公关之前,您可以通过在回购协议上创建一个问题来讨论它。 – Jaxidian

+1

我现在看到,已经有一个问题,最近的更新日期为3周前,比这篇文章年轻很多。 https://github.com/Microsoft/ApplicationInsights-JS/pull/379 –