NextJs - Firebase - 拒绝连接到“[url]”因为它违反了文档的内容安全策略
我正在构建一个 NextJs 应用程序,每次向外部 api 发出请求时,都会出现类似于以下错误的错误:
Refused to connect to 'https://flagcdn.com/64x48/us.png' because it violates the following
Content Security Policy directive: "connect-src 'self' webpack://*".
Refused to connect to 'https://flagcdn.com/64x48/us.png' because it violates the document's
Content Security Policy.
或者当我尝试使用 Firebase 电话身份验证登录时:
Refused to connect to 'https://www.google.com/recaptcha/....' because it violates the following
Content Security Policy directive: "connect-src 'self' webpack://*".
Refused to connect to 'https://www.google.com/recaptcha/...' because it violates the document's
Content Security Policy.
当我清空缓存并硬刷新页面时,一段时间内一切正常,然后错误又回来了。
我搜索了解决方案,但找不到适合我的项目的解决方案。
I'm building a NextJs app, and each time I make a request to an external api, it gives an error similar to the following error:
Refused to connect to 'https://flagcdn.com/64x48/us.png' because it violates the following
Content Security Policy directive: "connect-src 'self' webpack://*".
Refused to connect to 'https://flagcdn.com/64x48/us.png' because it violates the document's
Content Security Policy.
Or when I try to login using Firebase Phone Authentication:
Refused to connect to 'https://www.google.com/recaptcha/....' because it violates the following
Content Security Policy directive: "connect-src 'self' webpack://*".
Refused to connect to 'https://www.google.com/recaptcha/...' because it violates the document's
Content Security Policy.
When I empty cache and hard refresh the page, everything works fine for a while and then the errors come back.
I searched for solutions but couldn't find one that worked with my project.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
内容安全策略限制浏览器可以连接的主机。您应该找到政策的定义并添加 flagcdn.com 和 www.google.com,为您提供以下连接-src 指令:“connect-src 'self' webpack://* flagcdn.com www.google.com”。然后您应该监视错误并查看是否需要进一步添加。
A content security policy is restricting which hosts the browser can make a connection to. You should locate the definition of your policy and add flagcdn.com and www.google.com giving you the following connect-src directive: "connect-src 'self' webpack://* flagcdn.com www.google.com". Then you should monitor errors and see if further additions need to be made.