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.

当我清空缓存并硬刷新页面时,一切都会正常运行一段时间,然后错误就会回来。

我搜索了解决方案,但找不到一个适用于我的项目的解决方案。

内容安全策略限制浏览器可以连接到哪些主机。您应该找到策略的定义,并添加flagcdn.com和www.google.com,从而提供以下connect-src指令:"connect-src'self'webpack://*flagcdn.com www.google.com"。然后,您应该监视错误,并查看是否需要进行进一步的添加。

最新更新