Skip to content

Commit 5681ab6

Browse files
committed
[FIX] CWE-22 in FileServer
1 parent 52acc4f commit 5681ab6

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

  • components/launchserver/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver

components/launchserver/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,13 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr
197197
return;
198198
}
199199

200-
File file = base.resolve(path).toFile();
200+
Path basePath = base.toAbsolutePath().normalize();
201+
Path resolved = basePath.resolve(path).toAbsolutePath().normalize();
202+
if (!resolved.startsWith(basePath)) {
203+
sendError(ctx, FORBIDDEN);
204+
return;
205+
}
206+
File file = resolved.toFile();
201207
if ((file.isHidden() && !showHiddenFiles) || !file.exists()) {
202208
sendError(ctx, NOT_FOUND);
203209
return;

0 commit comments

Comments
 (0)