aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares
diff options
context:
space:
mode:
Diffstat (limited to 'server/middlewares')
-rw-r--r--server/middlewares/validators/plugins.ts15
1 files changed, 14 insertions, 1 deletions
diff --git a/server/middlewares/validators/plugins.ts b/server/middlewares/validators/plugins.ts
index a06add6b8..a1634ded4 100644
--- a/server/middlewares/validators/plugins.ts
+++ b/server/middlewares/validators/plugins.ts
@@ -6,6 +6,7 @@ import { isPluginNameValid, isPluginTypeValid, isPluginVersionValid, isNpmPlugin
6import { PluginManager } from '../../lib/plugins/plugin-manager' 6import { PluginManager } from '../../lib/plugins/plugin-manager'
7import { isBooleanValid, isSafePath } from '../../helpers/custom-validators/misc' 7import { isBooleanValid, isSafePath } from '../../helpers/custom-validators/misc'
8import { PluginModel } from '../../models/server/plugin' 8import { PluginModel } from '../../models/server/plugin'
9import { InstallPlugin } from '../../../shared/models/plugins/install-plugin.model'
9 10
10const servePluginStaticDirectoryValidator = [ 11const servePluginStaticDirectoryValidator = [
11 param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name'), 12 param('pluginName').custom(isPluginNameValid).withMessage('Should have a valid plugin name'),
@@ -48,13 +49,25 @@ const listPluginsValidator = [
48] 49]
49 50
50const installPluginValidator = [ 51const installPluginValidator = [
51 body('npmName').custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'), 52 body('npmName')
53 .optional()
54 .custom(isNpmPluginNameValid).withMessage('Should have a valid npm name'),
55 body('path')
56 .optional()
57 .custom(isSafePath).withMessage('Should have a valid safe path'),
52 58
53 (req: express.Request, res: express.Response, next: express.NextFunction) => { 59 (req: express.Request, res: express.Response, next: express.NextFunction) => {
54 logger.debug('Checking installPluginValidator parameters', { parameters: req.body }) 60 logger.debug('Checking installPluginValidator parameters', { parameters: req.body })
55 61
56 if (areValidationErrors(req, res)) return 62 if (areValidationErrors(req, res)) return
57 63
64 const body: InstallPlugin = req.body
65 if (!body.path && !body.npmName) {
66 return res.status(400)
67 .json({ error: 'Should have either a npmName or a path' })
68 .end()
69 }
70
58 return next() 71 return next()
59 } 72 }
60] 73]