我正在尝试编写一个中间件来接受来自浏览器的 CSP 报告。浏览器问题application/csp-report
as Content-Type
。发布的请求是 JSON 格式。目前我使用bodyParser.text
接受该内容类型。但我想也许有更好的方式去接受application/csp-report
作为 bodyParser 中的 JSON。
这就是我现在正在做的事情。
app.use(bodyParser.json());
app.use(bodyParser.text({type: 'application/csp-report'}));
我的问题是如何接受 JSON 请求负载Content-Type
application-csp-report
?
因为它实际上是 JSON,所以你可以像这样告知 Express 这一事实:
app.use(bodyParser.json({type: 'application/csp-report'}));
但请注意,某些浏览器使用application/csp-report
, some application/json
所以我设置了两者:
app.use(bodyParser.json({type: 'application/json'}));
app.use(bodyParser.json({type: 'application/csp-report'}));
如果有帮助的话,我在这里编写了一个(非常简单的)节点报告服务的代码:https://www.tunetheweb.com/security/http-security-headers/csp/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)