My web app uses Node.js and Express in the backend. When there is violation of the content security policies (CSP), the report URI reports an empty object. The codes in my backend are as the following:
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(helmet({
contentSecurityPolicy: {
directives: {
// some policies here
reportUri: ["/my_amazing_csp_report_parser"],
},
},
}));
app.use('/my_amazing_csp_report_parser', (req, res, next) => {
console.log(req.body);
next();
})
I read on the Doc from MDN that the report URI should report a whole JSON object. But my console.log(req.body);
returns an empty object. I am wondering if I am parsing my JSON object wrong with app.use(bodyParser.urlencoded({ extended: true }));
and app.use(bodyParser.json());
?