From 440711def0bbb13d7a0f58cc9f0233ba350b503a Mon Sep 17 00:00:00 2001 From: Graham Date: Sun, 23 May 2021 21:37:50 +0100 Subject: [PATCH] Fix JAGGRAB request parsing The paths aren't prefixed with a slash, unlike HTTP. Signed-off-by: Graham --- game/src/main/kotlin/org/openrs2/game/net/FileProvider.kt | 6 +----- .../org/openrs2/game/net/http/HttpChannelHandler.kt | 8 +++++++- share/doc/protocol/jaggrab.md | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/game/src/main/kotlin/org/openrs2/game/net/FileProvider.kt b/game/src/main/kotlin/org/openrs2/game/net/FileProvider.kt index dfd1b3d6..73050a04 100644 --- a/game/src/main/kotlin/org/openrs2/game/net/FileProvider.kt +++ b/game/src/main/kotlin/org/openrs2/game/net/FileProvider.kt @@ -10,11 +10,7 @@ import javax.inject.Singleton @Singleton public class FileProvider { public fun get(uri: String): FileRegion? { - if (!uri.startsWith("/")) { - return null - } - - var path = ROOT.resolve(uri.substring(1)).toAbsolutePath().normalize() + var path = ROOT.resolve(uri).toAbsolutePath().normalize() if (!path.startsWith(ROOT)) { return null } diff --git a/game/src/main/kotlin/org/openrs2/game/net/http/HttpChannelHandler.kt b/game/src/main/kotlin/org/openrs2/game/net/http/HttpChannelHandler.kt index 660962d4..71a96a0b 100644 --- a/game/src/main/kotlin/org/openrs2/game/net/http/HttpChannelHandler.kt +++ b/game/src/main/kotlin/org/openrs2/game/net/http/HttpChannelHandler.kt @@ -25,7 +25,13 @@ public class HttpChannelHandler @Inject constructor( } override fun channelRead0(ctx: ChannelHandlerContext, msg: HttpRequest) { - val file = fileProvider.get(msg.uri()) + val uri = msg.uri() + if (!uri.startsWith("/")) { + ctx.write(createResponse(HttpResponseStatus.BAD_REQUEST)).addListener(ChannelFutureListener.CLOSE) + return + } + + val file = fileProvider.get(uri.substring(1)) if (file == null) { ctx.write(createResponse(HttpResponseStatus.NOT_FOUND)).addListener(ChannelFutureListener.CLOSE) return diff --git a/share/doc/protocol/jaggrab.md b/share/doc/protocol/jaggrab.md index e717e701..6f06e6a1 100644 --- a/share/doc/protocol/jaggrab.md +++ b/share/doc/protocol/jaggrab.md @@ -10,7 +10,7 @@ contains a single opcode byte: `17`. The loader then writes the following string: - JAGGRAB / + JAGGRAB where `` is replaced with the name of the file to fetch. The string is followed by two line feed characters.