拒绝连接到 x 因为它违反了以下内容安全策略指令 (connect-src) [英] Refused to connect to x because it violates the following Content Security Policy directive (connect-src)

查看:161
本文介绍了拒绝连接到 x 因为它违反了以下内容安全策略指令 (connect-src)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 heroku 上部署了一个 MERN 应用,并为 CSP 设置了这些值:

I deployed a MERN app on heroku and I set these values for the CSP:

<meta
      http-equiv="Content-Security-Policy"
      content="connect-src https://api.themoviedb.org 'self'; default-src 'self'; base-uri 'self'; object-src 'none'; script-src 'unsafe-inline' 'self' ; style-src 'unsafe-inline' 'self' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com"
    />

但是这是我在 Chrome 控制台中得到的:

However this is what I get in Chrome console:

拒绝连接到 [URL],因为它违反了以下内容安全策略指令:default-src 'self'".请注意,未明确设置connect-src",因此使用default-src"作为后备.

为什么当我检查页面时可以在 index.html 中看到它时,它告诉我没有设置 connect-src?

Why does it tell me that connect-src was not set, when I can see it in the index.html when I inspect the page?

推荐答案

CSP 的版本(或级别)具有扩展原始规范的新支持功能.通过 html 元标头为 CSP 提供服务被认为是传统的,并且有一些缺点.尝试通过请求的 HTTP 标头设置 CSP此外,作为最佳实践,将 default-src 设为您的第一个指令.

CSP has versions (or levels) with newly supported features extending the original spec. Serving the CSP through an html meta header is considered legacy and has some drawbacks. Try setting CSP via the HTTP headers of the request Also, as a best practice make the default-src you first directive.

这篇关于拒绝连接到 x 因为它违反了以下内容安全策略指令 (connect-src)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆