【问题标题】:Content Secuty Policy and Google Analytics image from differrent domain zones [duplicate]来自不同域区域的内容安全策略和 Google Analytics 图像 [重复]
【发布时间】:2017-07-27 14:30:53
【问题描述】:

我为 HTTP Content-Security-Policy 设置了 img-src 指令,它指定了允许在我的网站上使用的图像和网站图标的有效来源。 我还设置了谷歌分析。 这是指令的值: img-src 'self' data: www.google-analytics.com https://www.google.com/pagead/ 问题是谷歌切换到访问者的国家域,因此它试图从该域而不是 www.google.com 加载特殊服务图像。例如。如果我从意大利 (google.com => google.it) 访问该网站,它会在浏览器控制台中抱怨:

Refused to load the image 'https://www.google.it/ads/ga-audiences?v=1&aip=1&t=sr&_r=4&tid=UA-1234…' because it violates the following Content Security Policy directive: "img-src 'self' data: www.google-analytics.com https://www.google.com/pagead/".

有什么方法可以在 img-src 指令中计算 Google.com 的所有可能的域区域?据我所知,不可能写出类似于“google.*”的东西 谷歌分析方面可能有一些解决方案?

【问题讨论】:

    标签: javascript image google-analytics content-security-policy


    【解决方案1】:

    不幸的是,Content-Security-Policy 资源需要被列入白名单,而通配符与该想法不兼容:

    接受通配符,但只能作为方案、端口或位于主机名最左边的位置:://.example.com:* 将匹配 example.com 的所有子域(但不是 example.com 本身),在任何端口上使用任何方案。

    有关此问题的解决方案,请参阅 this previous answer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-05
      • 1970-01-01
      • 1970-01-01
      • 2020-10-19
      • 2020-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多