File tree Expand file tree Collapse file tree
exec/java-exec/src/main/java/org/apache/drill/exec/server/rest Expand file tree Collapse file tree Original file line number Diff line number Diff line change 5050import java .io .FileOutputStream ;
5151import java .io .IOException ;
5252import java .io .InputStream ;
53+ import java .nio .file .Path ;
5354import java .time .Instant ;
5455import java .util .ArrayList ;
5556import java .util .Arrays ;
@@ -940,8 +941,16 @@ public Response getImage(
940941 .build ();
941942 }
942943
944+ // Use Path normalization to prevent path traversal (CodeQL-recognized sanitizer)
943945 File uploadDir = getUploadDir ();
944- File imageFile = new File (uploadDir , filename );
946+ Path basePath = uploadDir .toPath ();
947+ Path resolvedPath = basePath .resolve (filename ).normalize ();
948+ if (!resolvedPath .startsWith (basePath )) {
949+ return Response .status (Response .Status .BAD_REQUEST )
950+ .entity (new MessageResponse ("Invalid filename" ))
951+ .build ();
952+ }
953+ File imageFile = resolvedPath .toFile ();
945954
946955 if (!imageFile .exists ()) {
947956 return Response .status (Response .Status .NOT_FOUND )
You can’t perform that action at this time.
0 commit comments