0

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

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 Google.com的所有可能的域区-src指令?据我所知,写一些类似于“google。*”的东西是不可能的。 Google Analytics可能有一些解决方案吗?

回答

0
与内容安全,政策资源

不幸的是需要被列入白名单,和通配符不会有这种想法兼容:

接受通配符,但只作为一个方案,一个端口,或者在最左边的主机名的位置::// .example.com:*可以在任何端口上使用任何方案匹配example.com的所有子域(但不包括example.com本身)。

解决办法见this previous answer这个问题

相关问题