【问题标题】:ASP.NET MVC Application Insights Javascript Snippet preventing other JavaScript from workingASP.NET MVC Application Insights Javascript Snippet 阻止其他 JavaScript 工作
【发布时间】:2021-03-12 10:48:49
【问题描述】:

我刚刚更新了Web.Config 文件中的Content-Security-Policy 设置,并在我的_Layout.cshtml 中添加了Application Insights JavaScript snippet

这是 Web.config 中 Content-Security-Policy 的样子。

 script-src-elem 
    'self' 
    'unsafe-inline' 
    'unsafe-eval' 
     https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js
     *.mymapjs.com
script-src 
    'self' 
    'unsafe-inline' 
    'unsafe-eval' 
     https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js
     *.mymapjs.com

mymapjs.com 不再正常工作,我的地图没有显示,我的浏览器对我用红色字母对我大喊大叫感到不安:

CORS 策略已阻止从源“mywebsite.com”访问“mymapjs.com”处的 XMLHttpRequest:对预检请求的响应未通过访问控制检查:它没有 HTTP ok 状态。

当我从 Web.config Content-Security-Policy 中删除 https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js 网址时,我收到警告:

拒绝加载脚本“https://az416426.vo.msecnd.net/scripts/b/ai.2.min.js”,因为它违反了以下内容安全策略指令:“script-src-elem” self' 'unsafe-inline' 'unsafe-eval' https://*.mymapjs.com use.other.net use.other.net/ https://myfont.net/it.js

【问题讨论】:

    标签: javascript asp.net-mvc azure-application-insights


    【解决方案1】:

    原来我在Application Insights configuration. 中启用了enableCorsCorrelation = true 然后我尝试使用mymapjs.com 的通配符值更新correlationHeaderExcludedDomains 值。

    correlationHeaderExcludedDomains:
                        [
                            'myapp.azurewebsites.net',
                            '*.queue.core.windows.net',
                            '*.mymapjs.com'
                        ]
    

    单靠外卡是行不通的。我必须严格输入 JS 库 url AND 有通配符才能正常工作。它想要直接从_Layout.cshtml 请求的脚本以及从 JS 库生成的脚本。

    correlationHeaderExcludedDomains:
                        [
                            'myapp.azurewebsites.net',
                            '*.queue.core.windows.net',
                            '*.mymapjs.com'
                            'https://mymapjs.com-core-events.js'
                            'https://mymapjs.com-services.js'
                            'https://mymapjs.com-ui-services.js'
                        ]
    

    如果其他人发现这个问题,我希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 2022-01-04
      • 1970-01-01
      • 2016-11-10
      • 1970-01-01
      • 2020-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多