Ver Fonte

Add validation to throw error when more than 300 paths are included

Shun Miyazawa há 1 ano atrás
pai
commit
7b4b04fc4a

+ 6 - 0
apps/app/src/server/routes/apiv3/page/get-page-paths-with-descendant-count.ts

@@ -33,6 +33,12 @@ export const getPagePathsWithDescendantCountFactory: GetPagePathsWithDescendantC
 
   const validator: ValidationChain[] = [
     query('paths').isArray().withMessage('paths must be an array of strings'),
+    query('paths').custom((paths: string[]) => {
+      if (paths.length > 300) {
+        throw new Error('paths must be an array of strings with a maximum length of 300');
+      }
+      return true;
+    }),
     query('paths.*') // each item of paths
       .isString()
       .withMessage('paths must be an array of strings'),