소스 검색

add joinAndValidatePath method

NaokiHigashi28 1 년 전
부모
커밋
f8113705dd
1개의 변경된 파일8개의 추가작업 그리고 0개의 파일을 삭제
  1. 8 0
      apps/app/src/features/growi-plugin/server/services/growi-plugin/growi-plugin.ts

+ 8 - 0
apps/app/src/features/growi-plugin/server/services/growi-plugin/growi-plugin.ts

@@ -402,6 +402,14 @@ export class GrowiPluginService implements IGrowiPluginService {
     return entries;
   }
 
+  private joinAndValidatePath(baseDir: string, ...paths: string[]):fs.PathLike {
+    const joinedPath = path.join(baseDir, ...paths);
+    if (!joinedPath.startsWith(baseDir)) {
+      throw new Error(`Invalid path: Outside of allowed directory - ${joinedPath}`);
+    }
+    return joinedPath;
+  }
+
 }