仅限 Safari:拒绝连接到...,因为它没有出现在内容安全策略的 connect-src 指令中
Safari only: Refused to connect to ... because it does not appear in the connect-src directive of the Content Security Policy
使用 Google Analytics 时,我从 Safari 13.1 收到以下错误,但 Chrome 没有:
Refused to connect to https://www.google-analytics.com/j/collect?XYZ
because it does not appear in the connect-src directive of the Content Security Policy.
我的应用程序没有尝试连接到 www.google-analytics.com
,但它从 www.googletagmanager.com
下载脚本,而后者又从 www.google-analytics.com
下载脚本。
我的CSP配置如下:
script-src 'self' 'unsafe-eval' data: www.google-analytics.com www.googletagmanager.com www.google.com www.gstatic.com
connect-src 'self'
正如 Safari 所说,我在 connect-src
中没有 google-analytics
,但这似乎不是 Chrome 的问题。
是我的 CSP 错了(Chrome 过于宽容)还是这是 Safari 中的错误?
Safari 是对的。 Chrome is being too permissive:
The HTTP Content-Security-Policy (CSP) script-src directive specifies valid sources for JavaScript.
请注意,此语句不合格。
Chrome 也违反了 CSP 的其他假设。例如,blocked-uri
用于不同的来源 requires that the URI path is stripped,但 Chrome 不会这样做,而 Safari 会。
此时 Safari 似乎 compliant/strict 比 Chrome,但无论如何你应该使用更严格的浏览器,因为,好吧,你真的别无选择...
使用 Google Analytics 时,我从 Safari 13.1 收到以下错误,但 Chrome 没有:
Refused to connect to https://www.google-analytics.com/j/collect?XYZ
because it does not appear in the connect-src directive of the Content Security Policy.
我的应用程序没有尝试连接到 www.google-analytics.com
,但它从 www.googletagmanager.com
下载脚本,而后者又从 www.google-analytics.com
下载脚本。
我的CSP配置如下:
script-src 'self' 'unsafe-eval' data: www.google-analytics.com www.googletagmanager.com www.google.com www.gstatic.com
connect-src 'self'
正如 Safari 所说,我在 connect-src
中没有 google-analytics
,但这似乎不是 Chrome 的问题。
是我的 CSP 错了(Chrome 过于宽容)还是这是 Safari 中的错误?
Safari 是对的。 Chrome is being too permissive:
The HTTP Content-Security-Policy (CSP) script-src directive specifies valid sources for JavaScript.
请注意,此语句不合格。
Chrome 也违反了 CSP 的其他假设。例如,blocked-uri
用于不同的来源 requires that the URI path is stripped,但 Chrome 不会这样做,而 Safari 会。
此时 Safari 似乎 compliant/strict 比 Chrome,但无论如何你应该使用更严格的浏览器,因为,好吧,你真的别无选择...