apache Google Analytics v4的内容安全策略

zed5wv10  于 2022-11-16  发布在  Apache
关注(0)|答案(2)|浏览(110)

我的Google Analytics上没有任何跟踪信息...我怀疑我的内容安全策略是错误的,即使浏览器控制台是干净的。这是我目前拥有的:

Header always set Content-Security-Policy "script-src 'self' https: data: 'unsafe-inline' 'unsafe-eval' https://www.googletagmanager.com img-src: https://www.googletagmanager.com connect-src: https://www.googletagmanager.com;"

在这个问题上有什么建议吗?最好的。

kcrjzv8t

kcrjzv8t1#

connect-srcimg-src不应该有冒号。也可以用分号结束每个策略。但是我相信你可能还需要一些来自谷歌的其他主机。如果你在你的CSP中添加一个report-to,你可以看到什么被阻止了。
我还想建议不允许不安全的内联js(当然如果可能的话)

1aaf6o9v

1aaf6o9v2#

Google建议使用some CSP policies

script-src:  https://*.googletagmanager.com
img-src:     https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com
             https://*.g.doubleclick.net https://*.google.com https://*.google.<TLD>
connect-src: https://*.google-analytics.com https://*.analytics.google.com
             https://*.googletagmanager.com https://*.g.doubleclick.net https://*.google.com https://*.google.<TLD>

但是为了保持HTTP头的苗条,我仍然想知道如何事先知道required TLDs

相关问题