You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "walterddr (via GitHub)" <gi...@apache.org> on 2023/07/20 21:58:01 UTC

[GitHub] [pinot] walterddr commented on a diff in pull request #11132: Sanitise API inputs used as file path variables

walterddr commented on code in PR #11132:
URL: https://github.com/apache/pinot/pull/11132#discussion_r1270001646


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/LLCSegmentCompletionHandlers.java:
##########
@@ -448,8 +448,13 @@ private static File extractSegmentFromFormToLocalTempFile(FormDataMultiPart form
           "Invalid multi-part for segment: %s", segmentName);
       FormDataBodyPart bodyPart = map.values().iterator().next().get(0);
 
-      File localTempFile = new File(ControllerFilePathProvider.getInstance().getFileUploadTempDir(),
-          getTempSegmentFileName(segmentName));
+      File fileUploadTempDir = ControllerFilePathProvider.getInstance().getFileUploadTempDir();
+      File localTempFile = new File(fileUploadTempDir, getTempSegmentFileName(segmentName));
+
+      if (!localTempFile.getCanonicalPath().startsWith(fileUploadTempDir.getPath())) {
+        throw new IllegalArgumentException("Invalid segment name: " + segmentName);
+      }

Review Comment:
   create a file path util (put in pinot-common/src/main/java/org/apache/pinot/common/utils/FileUtils.java)
   ```suggestion
   public static File concatAndSanitizedFile(File folderDir, File filename) {
         File filePath = new File(folderDir, filename);
   
         if (!filePath.getCanonicalPath().startsWith(folderDir.getPath())) {
           throw new IllegalArgumentException("Invalid file name: " + filename);
         }
       }
   ```
     and then the util can be used across all the following



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org