简体   繁体   English

拒绝加载图像'<url> ' 因为它违反了以下内容安全策略指令:“img-src 'self' data:”</url>

[英]Refused to load the image '<URL>' because it violates the following Content Security Policy directive: "img-src 'self' data:"

after i uploaded my website on herokuy the images do not working and it gave me that error在我将我的网站上传到 herokuy 后,图像无法正常工作,这给了我这个错误

Refused to load the image '' because it violates the following Content Security Policy directive: "img-src 'self' data:".拒绝加载图像'',因为它违反了以下内容安全策略指令:“img-src 'self' data:”。

i have tried somethings like我尝试过类似的东西

<meta http-equiv="Content-Security-Policy" content="default-src 'self'; font-src data:" />

that but it does not work also但它也不起作用

This disables the contentSecurityPolicy middleware but keeps the rest:这将禁用contentSecurityPolicy中间件,但保留 rest:

app.use(
  helmet({
    contentSecurityPolicy: false,
  })
);
app.use(helmet({ crossOriginEmbedderPolicy: false, originAgentCluster: true }));
app.use(
  helmet.contentSecurityPolicy({
    useDefaults: true,
    directives: {
      "img-src": ["'self'", "https: data: blob:"],
    },
  })
);

Better practice instead of setting contentSecurityPolicy to false which should be the most last option.更好的做法,而不是将 contentSecurityPolicy 设置为 false,这应该是最后一个选项。 Using the Helmet documentation helps alot.使用Helmet 文档有很大帮助。 I used this in my app and it solves the issue very well.我在我的应用程序中使用了它,它很好地解决了这个问题。 My app is hosted here .我的应用程序托管在这里 Checkout my source code here . 在这里查看我的源代码。

app.use(
  helmet.contentSecurityPolicy({
    useDefaults: true,
    directives: {
      "img-src": ["'self'", "https: data:"]
    }
  })
)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在生产中加载图像,违反内容安全策略指令:“img-src 'self' data - Cannot load images on production, violates Content Security Policy directive: "img-src 'self' data 拒绝加载图像'https://res.cloudinary.com/.. violngecurity Policy directive: "img-src 'self' data:" - Refused to load the image 'https://res.cloudinary.com/.. violngecurity Policy directive: "img-src 'self' data:" create-react-app 问题:拒绝加载图像&#39;<URL> &#39; 因为它违反了以下内容安全策略指令: - create-react-app issue: Refused to load the image '<URL>' because it violates the following Content Security Policy directive: 拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“script-src &#39;self&#39;”。? - Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".? CSP,拒绝加载脚本,违反了以下内容安全策略指令:“script-src 'self'” - CSP, Refused to load the script, violates the following Content Security Policy directive: "script-src 'self'" 错误:拒绝加载脚本,因为它违反了以下内容安全策略指令:“default-src 'none'” - Error: Refused to load the script because it violates the following Content Security Policy directive: "default-src 'none'" 拒绝连接到 x 因为它违反了以下内容安全策略指令 (connect-src) - Refused to connect to x because it violates the following Content Security Policy directive (connect-src) 拒绝加载图像'https://authorization.example.herokuapp.com/favicon.ico,因为它违反了以下内容安全策略指令 - Refused to load the image 'https://authorization.example.herokuapp.com/favicon.ico because it violates the following Content Security Policy directive React JS 拒绝加载图像,因为它违反了以下内容安全策略指令 - React JS Refuse to load the image because it violates the following Content Security Policy directive 在 Digital Ocean Droplet 中部署 Strapi 时出错:因为它违反了以下内容安全策略指令:“connect-src &#39;self&#39; https: - Errors deploying Strapi in Digital Ocean Droplet: because it violates the following Content Security Policy directive: "connect-src 'self' https:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM