2016-09-07 109 views
3

您好我有一個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上這似乎正是我期待的,但它仍然是開放的......

回答

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,我也許會稍後嘗試。

+1

您是否嘗試過使用您的更改向官方GitHub存儲庫提交請求?在提交公關之前,您可以通過在回購協議上創建一個問題來討論它。 – Jaxidian

+1

我現在看到,已經有一個問題,最近的更新日期爲3周前,比這篇文章年輕很多。 https://github.com/Microsoft/ApplicationInsights-JS/pull/379 –