mirror of
https://github.com/wassname/talk.git
synced 2026-08-12 12:30:39 +08:00
csp fixes
This commit is contained in:
+13
-8
@@ -4,13 +4,18 @@ const { logger } = require('../../../services/logging');
|
||||
const router = express.Router();
|
||||
|
||||
const schema = Joi.object().keys({
|
||||
'csp-report': Joi.object().keys({
|
||||
'document-uri': Joi.string(),
|
||||
referrer: Joi.string(),
|
||||
'blocked-uri': Joi.string(),
|
||||
'violated-directive': Joi.string(),
|
||||
'original-policy': Joi.string(),
|
||||
}),
|
||||
'csp-report': Joi.object()
|
||||
.keys({
|
||||
'document-uri': Joi.string(),
|
||||
referrer: Joi.string().allow(''),
|
||||
'blocked-uri': Joi.string(),
|
||||
'violated-directive': Joi.string(),
|
||||
'original-policy': Joi.string(),
|
||||
'script-sample': Joi.string()
|
||||
.allow('')
|
||||
.optional(),
|
||||
})
|
||||
.optionalKeys('referrer', 'script-sample'),
|
||||
});
|
||||
|
||||
const json = express.json({ type: 'application/csp-report' });
|
||||
@@ -18,7 +23,7 @@ const json = express.json({ type: 'application/csp-report' });
|
||||
router.post('/', json, async (req, res, next) => {
|
||||
const { value, error: err } = Joi.validate(req.body, schema, {
|
||||
stripUnknown: true,
|
||||
presence: 'required',
|
||||
presence: 'optional',
|
||||
});
|
||||
if (err) {
|
||||
res.status(400).end();
|
||||
|
||||
Reference in New Issue
Block a user