소스 검색

fix CodeQL alert

Yuki Takei 4 달 전
부모
커밋
7cd3bfbb6a
1개의 변경된 파일5개의 추가작업 그리고 3개의 파일을 삭제
  1. 5 3
      apps/app/src/server/routes/apiv3/g2g-transfer.ts

+ 5 - 3
apps/app/src/server/routes/apiv3/g2g-transfer.ts

@@ -523,9 +523,11 @@ module.exports = (crowi: Crowi): Router => {
           500,
         );
       }
-      if (!isPathWithinBase(file.path, importService.baseDir)) {
+      // Normalize the path to prevent path traversal attacks
+      const resolvedFilePath = path.resolve(file.path);
+      if (!isPathWithinBase(resolvedFilePath, importService.baseDir)) {
         logger.error('Path traversal attack detected', {
-          filePath: file.path,
+          filePath: resolvedFilePath,
           baseDir: importService.baseDir,
         });
         return res.apiv3Err(
@@ -534,7 +536,7 @@ module.exports = (crowi: Crowi): Router => {
         );
       }
 
-      const fileStream = createReadStream(file.path, {
+      const fileStream = createReadStream(resolvedFilePath, {
         flags: 'r',
         mode: 0o666,
         autoClose: true,