内容安全策略阻止图像加载

Content Security Policy preventing images from loading

我有一个正在加载一些外部资产的 Express 应用程序,但它们被 CSP 阻止了。我以前从未遇到过这个问题,但这是我第一次在应用程序中使用 passport.js 和 helmet.js,所以这可能与它们的配置有关?

Refused to load the image 'https://fake-url.com' because it violates the following Content Security Policy directive: "img-src 'self' data:".

我尝试添加元标记以允许来自外部来源的图像,但这似乎没有效果。任何帮助将不胜感激。

你有

content="default-src 'none'

这会阻止从任何来源加载资源。删除它。

然后改成:

default-src 'self' fake-url.com';

有关 HTTP Content-Security-Policy 响应 header 的更多信息如下:

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy

https://content-security-policy.com/