google recaptcha v2 中的内容安全策略问题
Content Security Policy issue in google recaptcha v2
我搜索了很多与此相关的问题。但没有什么能解决我的问题。
我在 asp.net mvc5 应用程序中使用 google recaptcha v2。它在 google chrome 中运行良好。但它在 firefox 和 edge 浏览器中显示了一些错误。我怀疑这与内容安全策略有关 headers.
Firefox 出错
Content Security Policy: Ignoring “'unsafe-inline'” within script-src: ‘strict-dynamic’ specified
Content Security Policy: Ignoring “https:” within script-src: ‘strict-dynamic’ specified
Content Security Policy: Ignoring “http:” within script-src: ‘strict-dynamic’ specified
边缘错误
Security of a sandboxed iframe is potentially compromised by allowing script and same origin access.
由于这个错误,recaptcha 无法正常工作,因为它每次都会超时
我试过在 web.config
中像这样添加 csp headers
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Content-Security-Policy" value="script-src 'self' 'unsafe-inline' https://www.google.com https://www.google.com/recaptcha/api.js https://www.gstatic.com" />
</customHeaders>
</httpProtocol>
</system.webServer>
但这并不奏效,因为所有其他文件都被浏览器阻止了,我的页面也被破坏了
脚本的失败似乎与 CSP 无关。这些并不是您遇到的真正错误;只是注意到。
在 CSP 中,一些策略会覆盖其他策略,因此您会收到一条通知,指出策略 A 被忽略,因为您正在使用策略 B。那么为什么要放入策略 A,您会问吗?为了与不理解策略 B 的旧浏览器兼容。
例如:我使用了CSP nonces,但也放入了“unsafe-inline”。 IE 不理解随机数,所以它使用“不安全内联”规则。现代浏览器忽略“不安全内联”并使用随机数。在 Firefox 控制台中,我收到与您收到的通知类似的通知
我搜索了很多与此相关的问题。但没有什么能解决我的问题。 我在 asp.net mvc5 应用程序中使用 google recaptcha v2。它在 google chrome 中运行良好。但它在 firefox 和 edge 浏览器中显示了一些错误。我怀疑这与内容安全策略有关 headers.
Firefox 出错
Content Security Policy: Ignoring “'unsafe-inline'” within script-src: ‘strict-dynamic’ specified
Content Security Policy: Ignoring “https:” within script-src: ‘strict-dynamic’ specified
Content Security Policy: Ignoring “http:” within script-src: ‘strict-dynamic’ specified
边缘错误
Security of a sandboxed iframe is potentially compromised by allowing script and same origin access.
由于这个错误,recaptcha 无法正常工作,因为它每次都会超时
我试过在 web.config
中像这样添加 csp headers<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Content-Security-Policy" value="script-src 'self' 'unsafe-inline' https://www.google.com https://www.google.com/recaptcha/api.js https://www.gstatic.com" />
</customHeaders>
</httpProtocol>
</system.webServer>
但这并不奏效,因为所有其他文件都被浏览器阻止了,我的页面也被破坏了
脚本的失败似乎与 CSP 无关。这些并不是您遇到的真正错误;只是注意到。
在 CSP 中,一些策略会覆盖其他策略,因此您会收到一条通知,指出策略 A 被忽略,因为您正在使用策略 B。那么为什么要放入策略 A,您会问吗?为了与不理解策略 B 的旧浏览器兼容。
例如:我使用了CSP nonces,但也放入了“unsafe-inline”。 IE 不理解随机数,所以它使用“不安全内联”规则。现代浏览器忽略“不安全内联”并使用随机数。在 Firefox 控制台中,我收到与您收到的通知类似的通知