|
@@ -7,6 +7,10 @@ const express = require('express');
|
|
|
|
|
|
|
|
const router = express.Router();
|
|
const router = express.Router();
|
|
|
|
|
|
|
|
|
|
+const { body } = require('express-validator/check');
|
|
|
|
|
+
|
|
|
|
|
+const validator = {};
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @swagger
|
|
* @swagger
|
|
|
* tags:
|
|
* tags:
|
|
@@ -16,11 +20,90 @@ const router = express.Router();
|
|
|
module.exports = (crowi) => {
|
|
module.exports = (crowi) => {
|
|
|
const loginRequiredStrictly = require('../../middleware/login-required')(crowi);
|
|
const loginRequiredStrictly = require('../../middleware/login-required')(crowi);
|
|
|
const adminRequired = require('../../middleware/admin-required')(crowi);
|
|
const adminRequired = require('../../middleware/admin-required')(crowi);
|
|
|
|
|
+ const csrf = require('../../middleware/csrf')(crowi);
|
|
|
|
|
|
|
|
const {
|
|
const {
|
|
|
ErrorV3,
|
|
ErrorV3,
|
|
|
Config,
|
|
Config,
|
|
|
} = crowi.models;
|
|
} = crowi.models;
|
|
|
|
|
|
|
|
|
|
+ const { ApiV3FormValidator } = crowi.middlewares;
|
|
|
|
|
+
|
|
|
|
|
+ validator.xssSetting = [
|
|
|
|
|
+ body('isEnabledXss').isBoolean(),
|
|
|
|
|
+ body('tagWhiteList').isArray(),
|
|
|
|
|
+ body('attrWhiteList').isArray(),
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @swagger
|
|
|
|
|
+ *
|
|
|
|
|
+ * paths:
|
|
|
|
|
+ * /_api/v3/markdown-setting/xss:
|
|
|
|
|
+ * put:
|
|
|
|
|
+ * tags: [Users]
|
|
|
|
|
+ * description: Update xss
|
|
|
|
|
+ * parameters:
|
|
|
|
|
+ * - name: markdown:xss:isEnabledPrevention
|
|
|
|
|
+ * in: query
|
|
|
|
|
+ * description: enable xss
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * type: boolean
|
|
|
|
|
+ * - name: markdown:xss:option
|
|
|
|
|
+ * in: query
|
|
|
|
|
+ * description: xss option
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * type: number
|
|
|
|
|
+ * - name: markdown:xss:tagWhiteList
|
|
|
|
|
+ * in: query
|
|
|
|
|
+ * description: custom tag whitelist
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * type: array
|
|
|
|
|
+ * items:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: tag whitelist
|
|
|
|
|
+ * - name: markdown:xss:attrWhiteList
|
|
|
|
|
+ * in: query
|
|
|
|
|
+ * description: custom attr whitelist
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * type: array
|
|
|
|
|
+ * items:
|
|
|
|
|
+ * type: string
|
|
|
|
|
+ * description: tag whitelist
|
|
|
|
|
+ * responses:
|
|
|
|
|
+ * 200:
|
|
|
|
|
+ * description: Updating xss success
|
|
|
|
|
+ * content:
|
|
|
|
|
+ * application/json:
|
|
|
|
|
+ * schema:
|
|
|
|
|
+ * properties:
|
|
|
|
|
+ * xssParams:
|
|
|
|
|
+ * type: object
|
|
|
|
|
+ * description: new xss params
|
|
|
|
|
+ */
|
|
|
|
|
+ router.put('/xss', loginRequiredStrictly, adminRequired, csrf, validator.xssSetting, ApiV3FormValidator, async(req, res) => {
|
|
|
|
|
+ if (req.body.isEnabledXss && req.body.xssOption == null) {
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3('xss option is required'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ const xssParams = {
|
|
|
|
|
+ 'markdown:xss:isEnabledPrevention': req.body.isEnabledXss,
|
|
|
|
|
+ 'markdown:xss:option': req.body.xssOption,
|
|
|
|
|
+ 'markdown:xss:tagWhiteList': req.body.tagWhiteList,
|
|
|
|
|
+ 'markdown:xss:attrWhiteList': req.body.attrWhiteList,
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ await crowi.configManager.updateConfigsInTheSameNamespace('markdown', xssParams);
|
|
|
|
|
+ return res.apiv3({ xssParams });
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (err) {
|
|
|
|
|
+ const msg = 'Error occurred in updating xss';
|
|
|
|
|
+ logger.error('Error', err);
|
|
|
|
|
+ return res.apiv3Err(new ErrorV3(msg, 'update-xss-failed'));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
return router;
|
|
return router;
|
|
|
};
|
|
};
|