I have an API which collects Content Security Policy (CSP) violation reports. Now that report-uri is being replaced by report-to directive, I planned to use that. However, I'm unable to get reports cross-origin. I've tried using the cors package. But still unable to get the report.
The headers I have set on client origin (example-1.com) are:
res.setHeader(
'Report-To',
'{"group":"csp-endpoint","max_age":10886400,"endpoints":[{"url": "https://example-2.com/csp-report"}]}'
);
In CSP, the report-to value is set to csp-endpoint (This is working on same origin)
On server-side (example-2.com), the following code is present (Express.js server):
app.use(
'/csp-report',
express.json({
type: [
'application/json',
'application/csp-report',
'application/reports+json'
]
})
);
app.use('/csp-report', cors()) // Using cors npm package
app.post('/csp-report', (req, res) => {
res.setHeader('Access-Control-Expose-Headers', '*, Authorization');
console.log(req.headers);
console.log('CSP Violation Timestamp : ' + new Date().getTime());
console.log(req.body);
res.status(204).send();
});
I'm not getting reports from cross origin. Please consider me a beginner and let me know where I'm making mistake. Thanks.
