【发布时间】: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