我想为helmet.js中间件中的一个设置一些自定义选项,但我不明白这样做是否会启用其他中间件,还是必须显式启用它们?
来自helmet.js文档:
// Sets all of the defaults, but overrides `script-src` and disables the default `style-src`
app.use(
helmet.contentSecurityPolicy({
useDefaults: true,
directives: {
"script-src": ["'self'", "example.com"],
"style-src": null,
},
})
);我应该在上面的代码之前添加app.use(helmet())吗?
发布于 2021-11-22 15:20:29
app.use(helmet())包含头盔的所有默认中间件及其默认选项。
app.use(helmet.contentSecurityPolicy())仅包括内容安全策略中间件。换句话说,你不会得到其余的头盔中间件。
要包含头盔的所有默认值并自定义CSP中间件,请在顶级helmet()下指定它
app.use(
helmet({
contentSecurityPolicy: {
// ...
},
})
);https://stackoverflow.com/questions/70066996
复制相似问题