From d8257d5ec8f717b521e80678d7f67e1bd08ee72f Mon Sep 17 00:00:00 2001 From: Nick Tindall Date: Fri, 5 Sep 2025 23:13:50 +1000 Subject: [PATCH] Upgrade Netty to 4.1.126.Final (#134182) (cherry picked from commit 500c4ff6252ed58c3162f1b92c6a21e01b43df41) --- build-tools-internal/version.properties | 2 +- docs/changelog/134182.yaml | 5 + gradle/verification-metadata.xml | 84 +++++------ ...ecurityNetty4HttpServerTransportTests.java | 131 ++++++++---------- 4 files changed, 105 insertions(+), 117 deletions(-) create mode 100644 docs/changelog/134182.yaml diff --git a/build-tools-internal/version.properties b/build-tools-internal/version.properties index bd254ce4a773f..b1f3e03bcad4d 100644 --- a/build-tools-internal/version.properties +++ b/build-tools-internal/version.properties @@ -14,7 +14,7 @@ log4j = 2.19.0 slf4j = 2.0.6 ecsLogging = 1.2.0 jna = 5.12.1 -netty = 4.1.118.Final +netty = 4.1.126.Final commons_lang3 = 3.9 google_oauth_client = 1.34.1 awsv1sdk = 1.12.270 diff --git a/docs/changelog/134182.yaml b/docs/changelog/134182.yaml new file mode 100644 index 0000000000000..4ec8a96a8ccc9 --- /dev/null +++ b/docs/changelog/134182.yaml @@ -0,0 +1,5 @@ +pr: 134182 +summary: Upgrade Netty to 4.1.126.Final +area: Network +type: upgrade +issues: [] diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index ce30fe7bf10dd..4e40d2c73469a 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -1452,74 +1452,74 @@ - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java index 0663172fa2e9c..5e06236dfaeca 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java @@ -573,9 +573,8 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th { EmbeddedChannel ch = new EmbeddedChannel(handler); ByteBuf buf = ch.alloc().buffer(); - ByteBufUtil.copy(AsciiString.of("This is not a valid HTTP line"), buf); - buf.writeByte(HttpConstants.LF); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("This is not a valid HTTP line", buf); + appendCrLf(buf); ch.writeInbound(buf); ch.flushInbound(); assertThat(dispatchThrowableReference.get().toString(), containsString("NOT A VALID HTTP LINE")); @@ -586,9 +585,8 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th { EmbeddedChannel ch = new EmbeddedChannel(handler); ByteBuf buf = ch.alloc().buffer(); - ByteBufUtil.copy(AsciiString.of("GET /this/is/a/valid/but/too/long/initial/line HTTP/1.1"), buf); - buf.writeByte(HttpConstants.LF); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("GET /this/is/a/valid/but/too/long/initial/line HTTP/1.1", buf); + appendCrLf(buf); ch.writeInbound(buf); ch.flushInbound(); assertThat(dispatchThrowableReference.get().toString(), containsString("HTTP line is larger than")); @@ -599,11 +597,9 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th { EmbeddedChannel ch = new EmbeddedChannel(handler); ByteBuf buf = ch.alloc().buffer(); - ByteBufUtil.copy(AsciiString.of("GET /url HTTP/1.1"), buf); - buf.writeByte(HttpConstants.LF); - ByteBufUtil.copy(AsciiString.of("Host"), buf); - buf.writeByte(HttpConstants.LF); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("GET /url HTTP/1.1", buf); + appendAsciiLine("Host", buf); + appendCrLf(buf); ch.writeInbound(buf); ch.flushInbound(); assertThat(dispatchThrowableReference.get().toString(), containsString("No colon found")); @@ -614,11 +610,9 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th { EmbeddedChannel ch = new EmbeddedChannel(handler); ByteBuf buf = ch.alloc().buffer(); - ByteBufUtil.copy(AsciiString.of("GET /url HTTP/1.1"), buf); - buf.writeByte(HttpConstants.LF); - ByteBufUtil.copy(AsciiString.of("Host: this.looks.like.a.good.url.but.is.longer.than.permitted"), buf); - buf.writeByte(HttpConstants.LF); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("GET /url HTTP/1.1", buf); + appendAsciiLine("Host: this.looks.like.a.good.url.but.is.longer.than.permitted", buf); + appendCrLf(buf); ch.writeInbound(buf); ch.flushInbound(); assertThat(dispatchThrowableReference.get().toString(), containsString("HTTP header is larger than")); @@ -629,12 +623,11 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th { EmbeddedChannel ch = new EmbeddedChannel(handler); ByteBuf buf = ch.alloc().buffer(); - ByteBufUtil.copy(AsciiString.of("GET /url HTTP/1.1"), buf); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("GET /url HTTP/1.1", buf); ByteBufUtil.copy(AsciiString.of("Host: invalid header value"), buf); buf.writeByte(0x01); - buf.writeByte(HttpConstants.LF); - buf.writeByte(HttpConstants.LF); + appendCrLf(buf); + appendCrLf(buf); ch.writeInbound(buf); ch.flushInbound(); assertThat(dispatchThrowableReference.get().toString(), containsString("Validation failed for header 'Host'")); @@ -645,10 +638,8 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th { EmbeddedChannel ch = new EmbeddedChannel(handler); ByteBuf buf = ch.alloc().buffer(); - ByteBufUtil.copy(AsciiString.of("GET /url HTTP/1.1"), buf); - buf.writeByte(HttpConstants.LF); - ByteBufUtil.copy(AsciiString.of("Host: localhost"), buf); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("GET /url HTTP/1.1", buf); + appendAsciiLine("Host: localhost", buf); ch.writeInbound(buf); ch.flushInbound(); safeGet(ch.close()); @@ -702,33 +693,24 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th // OPTIONS request with fixed length content written in one chunk { ByteBuf buf = ch.alloc().buffer(); - ByteBufUtil.copy(AsciiString.of("OPTIONS /url/whatever/fixed-length-single-chunk HTTP/1.1"), buf); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("OPTIONS /url/whatever/fixed-length-single-chunk HTTP/1.1", buf); if (randomBoolean()) { - ByteBufUtil.copy(AsciiString.of("Host: localhost"), buf); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("Host: localhost", buf); } if (randomBoolean()) { - ByteBufUtil.copy(AsciiString.of("Accept: */*"), buf); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("Accept: */*", buf); } if (randomBoolean()) { - ByteBufUtil.copy(AsciiString.of("Content-Encoding: gzip"), buf); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("Content-Encoding: gzip", buf); } if (randomBoolean()) { - ByteBufUtil.copy( - AsciiString.of("Content-Type: " + randomFrom("text/plain; charset=utf-8", "application/json; charset=utf-8")), - buf - ); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("Content-Type: " + randomFrom("text/plain; charset=utf-8", "application/json; charset=utf-8"), buf); } String content = randomAlphaOfLengthBetween(4, 1024); // having a "Content-Length" request header is what makes it "fixed length" - ByteBufUtil.copy(AsciiString.of("Content-Length: " + content.length()), buf); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("Content-Length: " + content.length(), buf); // end of headers - buf.writeByte(HttpConstants.LF); + appendCrLf(buf); ByteBufUtil.copy(AsciiString.of(content), buf); // write everything in one single chunk ch.writeInbound(buf); @@ -745,63 +727,44 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th } { ByteBuf buf = ch.alloc().buffer(); - ByteBufUtil.copy(AsciiString.of("OPTIONS /url/whatever/chunked-transfer?encoding HTTP/1.1"), buf); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("OPTIONS /url/whatever/chunked-transfer?encoding HTTP/1.1", buf); if (randomBoolean()) { - ByteBufUtil.copy(AsciiString.of("Host: localhost"), buf); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("Host: localhost", buf); } if (randomBoolean()) { - ByteBufUtil.copy(AsciiString.of("Accept: */*"), buf); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("Accept: */*", buf); } if (randomBoolean()) { - ByteBufUtil.copy(AsciiString.of("Content-Encoding: gzip"), buf); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("Content-Encoding: gzip", buf); } if (randomBoolean()) { - ByteBufUtil.copy( - AsciiString.of("Content-Type: " + randomFrom("text/plain; charset=utf-8", "application/json; charset=utf-8")), - buf - ); - buf.writeByte(HttpConstants.LF); + appendAsciiLine("Content-Type: " + randomFrom("text/plain; charset=utf-8", "application/json; charset=utf-8"), buf); } // do not write a "Content-Length" header to make the request "variable length" if (randomBoolean()) { - ByteBufUtil.copy(AsciiString.of("Transfer-Encoding: " + randomFrom("chunked", "gzip, chunked")), buf); + appendAsciiLine("Transfer-Encoding: " + randomFrom("chunked", "gzip, chunked"), buf); } else { - ByteBufUtil.copy(AsciiString.of("Transfer-Encoding: chunked"), buf); + appendAsciiLine("Transfer-Encoding: chunked", buf); } - buf.writeByte(HttpConstants.LF); - buf.writeByte(HttpConstants.LF); + // End of headers + appendCrLf(buf); // maybe append some chunks as well String[] contentParts = randomArray(0, 4, String[]::new, () -> randomAlphaOfLengthBetween(1, 64)); for (String content : contentParts) { - ByteBufUtil.copy(AsciiString.of(Integer.toHexString(content.length())), buf); - buf.writeByte(HttpConstants.CR); - buf.writeByte(HttpConstants.LF); - ByteBufUtil.copy(AsciiString.of(content), buf); - buf.writeByte(HttpConstants.CR); - buf.writeByte(HttpConstants.LF); + appendAsciiLine(Integer.toHexString(content.length()), buf); + appendAsciiLine(content, buf); } ch.writeInbound(buf); ch.flushInbound(); ByteBuf buf2 = ch.alloc().buffer(); contentParts = randomArray(1, 4, String[]::new, () -> randomAlphaOfLengthBetween(1, 64)); for (String content : contentParts) { - ByteBufUtil.copy(AsciiString.of(Integer.toHexString(content.length())), buf2); - buf2.writeByte(HttpConstants.CR); - buf2.writeByte(HttpConstants.LF); - ByteBufUtil.copy(AsciiString.of(content), buf2); - buf2.writeByte(HttpConstants.CR); - buf2.writeByte(HttpConstants.LF); + appendAsciiLine(Integer.toHexString(content.length()), buf2); + appendAsciiLine(content, buf2); } // finish chunked request - ByteBufUtil.copy(AsciiString.of("0"), buf2); - buf2.writeByte(HttpConstants.CR); - buf2.writeByte(HttpConstants.LF); - buf2.writeByte(HttpConstants.CR); - buf2.writeByte(HttpConstants.LF); + appendAsciiLine("0", buf2); + appendCrLf(buf2); ch.writeInbound(buf2); ch.flushInbound(); ch.runPendingTasks(); @@ -820,4 +783,24 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th } } + /** + * Append a string as ASCII terminated by a CR/LF newline + * + * @param string The string to append + * @param buf The buffer to append to + */ + private static void appendAsciiLine(String string, ByteBuf buf) { + ByteBufUtil.copy(AsciiString.of(string), buf); + appendCrLf(buf); + } + + /** + * Append a CR/LF newline + * + * @param buf The buffer to append to + */ + private static void appendCrLf(ByteBuf buf) { + buf.writeByte(HttpConstants.CR); + buf.writeByte(HttpConstants.LF); + } }