Skip to content

Commit 1c1d666

Browse files
Handle path parsing for opaque URIs (#2067)
When we're working with an opaque URI that the netty code can't parse a path from, we can end up with a null path, causing a NPE as we try to parse it. This adds a quick check — if we don't have a path, just return the URI. This matches the existing behavior — scope out the `parseUriFromNetty_unknown` test: ``` @test void parseUriFromNetty_unknown() { EmbeddedChannel channel = new EmbeddedChannel(new ClientRequestReceiver(null)); channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234); HttpRequestMessageImpl result; { channel.writeInbound( new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "asdf", Unpooled.buffer())); result = channel.readInbound(); result.disposeBufferedBody(); } assertThat(result.getPath()).isEqualTo("asdf"); channel.close(); } ``` We can match this behavior with our null check defense.
1 parent 59abacd commit 1c1d666

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

zuul-core/src/main/java/com/netflix/zuul/netty/server/ClientRequestReceiver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,11 @@ private String parsePath(String uri) {
420420
try {
421421
URI uriObject = new URI(uri);
422422
uriObject = uriObject.normalize();
423-
path = uriObject.getRawPath();
423+
path = uriObject.getRawPath();
424+
if (path == null) {
425+
// If we have an opaque URI, match existing behavior of using the URI as the path.
426+
return uri;
427+
}
424428
while (path.startsWith("/..")) {
425429
path = path.substring(3);
426430
}

zuul-core/src/test/java/com/netflix/zuul/netty/server/ClientRequestReceiverTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,22 @@ void pathTraversal_withQueryString() {
536536
channel.close();
537537
}
538538

539+
@Test
540+
void pathTraversal_withOpaqueURI() {
541+
EmbeddedChannel channel = new EmbeddedChannel(new ClientRequestReceiver(null));
542+
channel.attr(SourceAddressChannelHandler.ATTR_SERVER_LOCAL_PORT).set(1234);
543+
HttpRequestMessageImpl result;
544+
{
545+
channel.writeInbound(new DefaultFullHttpRequest(
546+
HttpVersion.HTTP_1_1, HttpMethod.GET, "foo.netflix.net:443", Unpooled.buffer()));
547+
result = channel.readInbound();
548+
result.disposeBufferedBody();
549+
}
550+
551+
assertThat(result.getPath()).isEqualTo("foo.netflix.net:443");
552+
channel.close();
553+
}
554+
539555
@Test
540556
void pathNormalization_emptyPath() {
541557
EmbeddedChannel channel = new EmbeddedChannel(new ClientRequestReceiver(null));

0 commit comments

Comments
 (0)