Application Insights 安全 cookie
Application Insights secure cookies
您好,我有一个 Web 应用程序,我在其上使用 Application Insights 和 Javascript SDK。在 Chrome 开发人员工具中,我看到有 2 个 cookie,ai_user 和 ai_session,它们是不安全的。我已经更改了我的应用程序中的代码以确保所有其他 cookie 安全,但我无法设法让这些 cookie 也同样安全。我直接在 Microsoft Application Insights documentation page 上发布了一个问题
他们告诉我更新脚本,这导致我修复了一个错误,但 cookie 仍然不安全(详细信息在我上面 link 的评论部分的评论中,目前是第一个顶部评论区)。我问过他们,但他们不再回复我。
我当前初始化应用程序见解的代码是
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,这似乎正是我要找的,但它仍然是开放的...
好的,由于我没有找到更好的方法来做到这一点,我已经解压了 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,我稍后可能会尝试。
您好,我有一个 Web 应用程序,我在其上使用 Application Insights 和 Javascript SDK。在 Chrome 开发人员工具中,我看到有 2 个 cookie,ai_user 和 ai_session,它们是不安全的。我已经更改了我的应用程序中的代码以确保所有其他 cookie 安全,但我无法设法让这些 cookie 也同样安全。我直接在 Microsoft Application Insights documentation page 上发布了一个问题 他们告诉我更新脚本,这导致我修复了一个错误,但 cookie 仍然不安全(详细信息在我上面 link 的评论部分的评论中,目前是第一个顶部评论区)。我问过他们,但他们不再回复我。
我当前初始化应用程序见解的代码是
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,这似乎正是我要找的,但它仍然是开放的...
好的,由于我没有找到更好的方法来做到这一点,我已经解压了 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,我稍后可能会尝试。