With the CSP middleware it is possible to enable reporting of CSP violations to an API endpoint using the legacy v0 Report-To, or v1 Reporting-Endpoints directives (more info). Using the Reporting API, the browser sends a violation report as an HTTP POST request with content type: ['application/json', 'application/csp-report', 'application/reports+json'] to the endpoint.
Would it be possible to create a middleware to setup an API endpoint and listen for incoming reports, like described here in the example for node js, to listen for incoming reports?
// node js example
app.use(
bodyParser.json({
type: [
'application/json',
'application/csp-report',
'application/reports+json',
],
})
);
app.post('/__cspreport__', (req, res) => {
console.log(req.body);
});
Another great example how this could be done found in this blog post Monitoring Content Security.
With the CSP middleware it is possible to enable reporting of CSP violations to an API endpoint using the legacy v0
Report-To, or v1Reporting-Endpointsdirectives (more info). Using the Reporting API, the browser sends a violation report as an HTTP POST request with contenttype: ['application/json', 'application/csp-report', 'application/reports+json']to the endpoint.Would it be possible to create a middleware to setup an API endpoint and listen for incoming reports, like described here in the example for node js, to listen for incoming reports?
Another great example how this could be done found in this blog post Monitoring Content Security.