Browse Source

add joinAndValidatePath method

NaokiHigashi28 1 year ago
parent
commit
f8113705dd

+ 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;
+  }
+
 }