angular6 - 由于安全策略指令,ReCAPTCHA2 脚本加载错误
问题描述
在我的Angular
应用程序中,当我尝试使用reCAPTCHA2
.
vendor.js:184374 Refused to load the script 'https://www.google.com/recaptcha/api.js?onload=ngx_captcha_onload_callback&render=explicit&hl=en' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
我正在使用这个Angular
变体 - https://enngage.github.io/ngx-captcha/
我该如何解决这个问题?我当前的安全策略是contentSecurityPolicy = "default-src 'self' ; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' ;img-src 'self' data: ; worker-src blob:"
我不想向所有类型的脚本打开 Web 应用程序。
解决方案
尝试像这样修改它:
contentSecurityPolicy = "default-src 'self' https://www.gstatic.com/recaptcha/ https://www.gstatic.com/recaptcha/ ; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' ;img-src 'self' data: ; worker-src blob:"
我刚刚添加了:
https://www.gstatic.com/recaptcha/ https://www.gstatic.com/recaptcha/
推荐阅读
- sql - SQL Server 两个更新锁同时持有在同一个对象上
- filter - 表达式类型错误
- c++ - 有没有办法可以从 const char* 转换为 int?
- microsoft-graph-api - Microsoft Graph 托管内容 ID 包含斜杠
- javascript - 使用 ReactJs 在电子商务网站中过滤性别
- firebase - 通过静态 IP 地址连接到 Firebase Functions
- reactjs - 为什么 console.log 显示正确的数组但状态错误(ReactJS)
- excel - 在 Angular 5 中将 XLSX 列数据类型更改为数字
- django - 如何正确过滤 Django 中的类别?
- r - 在 R 中使用 cplot() 绘制边际效应时出错