【发布时间】:2020-12-20 01:02:50
【问题描述】:
我正在使用 npm 头盔来保护我的 express 应用程序,但我想允许我的 S3 存储桶中的图像进行渲染。当我使用 helment Refused to load the image '<URL>' because it violates the following Content Security Policy directive: "img-src 'self' data:". 时出现此错误,这是有道理的,我违反了头盔实现的 CSP。
我能在他们的文档中找到的唯一内容是:
app.use(
helmet({
contentSecurityPolicy: false,
})
);
这确实允许我的图像渲染,但我仍然想要头盔提供的 CSP。我只需要基本上将我的 S3 链接列入白名单,但我在他们的文档中找不到关于此主题的任何内容
【问题讨论】:
-
我目前也在处理类似的事情,经过研究,我正在接近
app.use(helmet({contentSecurityPolicy: {directives:{...helmet.contentSecurityPolicy.getDefaultDirectives(),"img-src" : ["'self'", "data: https:"]}}}));
标签: node.js express amazon-s3 node-modules helmet.js