NextJs - Firebase - 拒绝连接到“[url]”因为它违反了文档的内容安全策略

发布于 2025-01-09 13:41:41 字数 794 浏览 1 评论 0原文

我正在构建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ζ澈沫 2025-01-16 13:41:41

内容安全策略限制浏览器可以连接的主机。您应该找到政策的定义并添加 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文