mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
Merge pull request #768 from sharetribe/csp-additions
Improve CSP error messages
This commit is contained in:
commit
e116c1cd6a
2 changed files with 11 additions and 3 deletions
|
|
@ -81,7 +81,7 @@ module.exports = (reportUri, enforceSsl, reportOnly) => {
|
|||
// https://content-security-policy.com/
|
||||
|
||||
// Example: extend default img directive with custom domain
|
||||
// const { imgSrc = [] } = defaultDirectives;
|
||||
// const { imgSrc = [self] } = defaultDirectives;
|
||||
// const exampleImgSrc = imgSrc.concat('my-custom-domain.example.com');
|
||||
|
||||
const customDirectives = {
|
||||
|
|
|
|||
|
|
@ -239,10 +239,18 @@ app.get('*', (req, res) => {
|
|||
app.use(log.errorHandler());
|
||||
|
||||
if (cspEnabled) {
|
||||
// Dig out the value of the given CSP report key from the request body.
|
||||
const reportValue = (req, key) => {
|
||||
const report = req.body ? req.body['csp-report'] : null;
|
||||
return report && report[key] ? report[key] : key;
|
||||
};
|
||||
|
||||
// Handler for CSP violation reports.
|
||||
app.post(cspReportUrl, (req, res) => {
|
||||
const report = req.body ? req.body['csp-report'] : null;
|
||||
log.error(new Error('CSP violation'), 'csp-violation', report);
|
||||
const effectiveDirective = reportValue(req, 'effective-directive');
|
||||
const blockedUri = reportValue(req, 'blocked-uri');
|
||||
const msg = `CSP: ${effectiveDirective} doesn't allow ${blockedUri}`;
|
||||
log.error(new Error(msg), 'csp-violation');
|
||||
res.status(204).end();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue