Skip to content

Commit be9dee8

Browse files
committed
More code fixes
1 parent ee49d3b commit be9dee8

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/DashboardResources.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.io.FileOutputStream;
5151
import java.io.IOException;
5252
import java.io.InputStream;
53+
import java.nio.file.Path;
5354
import java.time.Instant;
5455
import java.util.ArrayList;
5556
import 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)

0 commit comments

Comments
 (0)