zamis 5 лет назад
Родитель
Сommit
77114a6a36
2 измененных файлов с 21 добавлено и 2 удалено
  1. 20 1
      src/server/routes/admin.js
  2. 1 1
      src/server/routes/index.js

+ 20 - 1
src/server/routes/admin.js

@@ -22,7 +22,7 @@ module.exports = function(crowi, app) {
   const MAX_PAGE_LIST = 50;
   const actions = {};
 
-  const { check } = require('express-validator');
+  const { check, param } = require('express-validator');
 
   const api = {};
 
@@ -316,14 +316,33 @@ module.exports = function(crowi, app) {
 
   // Export management
   actions.export = {};
+  actions.export.api = api;
+
+  // api.validators = {};
+  api.validators.export = {};
+
   actions.export.index = (req, res) => {
     return res.render('admin/export');
   };
 
+  api.validators.export.download = function() {
+    const validator = [
+      param('fileName').not().contains('../'),
+    ];
+    return validator;
+  };
+
   actions.export.download = (req, res) => {
+    console.log(req.params);
     // TODO: add express validator
     const { fileName } = req.params;
 
+    const { validationResult } = require('express-validator');
+    const errors = validationResult(req);
+    if (!errors.isEmpty()) {
+      return res.status(422).json({ errors: 'Unprocessable entity' });
+    }
+
     try {
       const zipFile = exportService.getFile(fileName);
       return res.download(zipFile);

+ 1 - 1
src/server/routes/index.js

@@ -111,7 +111,7 @@ module.exports = function(crowi, app) {
 
   // export management for admin
   app.get('/admin/export'                       , loginRequiredStrictly , adminRequired ,admin.export.index);
-  app.get('/admin/export/:fileName'             , loginRequiredStrictly , adminRequired ,admin.export.download);
+  app.get('/admin/export/:fileName'             , loginRequiredStrictly , adminRequired ,admin.export.api.validators.export.download(),admin.export.download);
 
   app.get('/me'                       , loginRequiredStrictly , me.index);
   // external-accounts