我在页面加载时使用CAPTCHA,但是由于一些安全原因,它被阻塞了。
我正面临这样的问题:
Content Security Policy: The page's settings blocked the loading
of a resource at
http://www.google.com/recaptcha/api.js?onload=myCallBack&render=explicit
("script-src http://test.com:8080 'unsafe-inline' 'unsafe-eval'").
我使用了以下JavaScript和 meta标签:
<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
<script src="http://www.google.com/recaptcha/api.js?onload=myCallBack&render=explicit" async defer></script>
6条答案
按热度按时间ilmyapht1#
你说你只能从你自己的站点(self)加载脚本,然后你试图从另一个站点(www.google.com)加载脚本,因为你限制了它,所以你不能加载,这就是Content Security Policy(CSP)的全部意义。
您可以将第一行更改为:
或者,在您了解更多关于CSP的信息之前,完全删除这一行是值得的。您当前的CSP无论如何都是相当宽松的(允许
unsafe-inline
、unsafe-eval
和*
的default-src
),所以老实说,它可能没有增加太多的价值。b5buobof2#
当我的**ASP.NET Core Angular**项目在Visual Studio 2019中运行时,有时我会在Firefox控制台中收到以下错误消息:
内容安全策略:页面的设置阻止了在inline("default-src")加载资源。
在Chrome中,错误消息改为:
加载资源失败:服务器以状态404()响应
在我的情况下,它与我的内容安全策略无关,而只是我的TypeScript错误的结果。
检查IDE输出窗口中是否存在TypeScript错误,例如:
注意:由于此问题是Google上此错误消息的第一个结果。
noj0wjuj3#
我也遇到过类似的错误类型,首先,我尝试在代码中添加 meta标签,但是没有成功。
我发现在nginx Web服务器上,您可能有一个安全设置,可能会阻止外部代码运行:
请检查Content-Security-Policy。您可能需要添加源引用。
gwo2fgha4#
我设法允许我所有必要的网站与此标题:
x6492ojm5#
您可以通过在htaccess中添加代码来修复
ee7vknir6#
!!仅用于调试!!
如果真的有必要,请暂时这样做,因为这会使您的浏览器在所有网站上都容易受到攻击!
您可以在浏览器中禁用它们。
火狐
在Firefox地址栏中输入
about:config
,找到security.csp.enable
并将其设置为false
。chrome 合金
您可以安装名为
Disable Content-Security-Policy
的扩展来禁用CSP。