Skip to content

Commit ce7f506

Browse files
committed
Disable strict line parsing
1 parent d76be4b commit ce7f506

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpServerTransport.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.netty.handler.codec.ByteToMessageDecoder;
2424
import io.netty.handler.codec.http.HttpContentCompressor;
2525
import io.netty.handler.codec.http.HttpContentDecompressor;
26+
import io.netty.handler.codec.http.HttpDecoderConfig;
2627
import io.netty.handler.codec.http.HttpMessage;
2728
import io.netty.handler.codec.http.HttpRequestDecoder;
2829
import io.netty.handler.codec.http.HttpResponse;
@@ -342,23 +343,19 @@ protected void initChannel(Channel ch) throws Exception {
342343
ch.pipeline().addLast("read_timeout", new ReadTimeoutHandler(transport.readTimeoutMillis, TimeUnit.MILLISECONDS));
343344
}
344345
final HttpRequestDecoder decoder;
346+
final HttpDecoderConfig decoderConfig = new HttpDecoderConfig().setMaxInitialLineLength(handlingSettings.maxInitialLineLength())
347+
.setMaxHeaderSize(handlingSettings.maxHeaderSize())
348+
.setMaxChunkSize(handlingSettings.maxChunkSize())
349+
.setStrictLineParsing(false);
345350
if (httpValidator != null) {
346-
decoder = new HttpRequestDecoder(
347-
handlingSettings.maxInitialLineLength(),
348-
handlingSettings.maxHeaderSize(),
349-
handlingSettings.maxChunkSize()
350-
) {
351+
decoder = new HttpRequestDecoder(decoderConfig) {
351352
@Override
352353
protected HttpMessage createMessage(String[] initialLine) throws Exception {
353354
return HttpHeadersAuthenticatorUtils.wrapAsMessageWithAuthenticationContext(super.createMessage(initialLine));
354355
}
355356
};
356357
} else {
357-
decoder = new HttpRequestDecoder(
358-
handlingSettings.maxInitialLineLength(),
359-
handlingSettings.maxHeaderSize(),
360-
handlingSettings.maxChunkSize()
361-
);
358+
decoder = new HttpRequestDecoder(decoderConfig);
362359
}
363360
decoder.setCumulator(ByteToMessageDecoder.COMPOSITE_CUMULATOR);
364361
ch.pipeline().addLast("decoder", decoder); // parses the HTTP bytes request into HTTP message pieces

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/transport/netty4/SecurityNetty4HttpServerTransportTests.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -800,14 +800,18 @@ public void dispatchBadRequest(final RestChannel channel, final ThreadContext th
800800
}
801801

802802
/**
803-
* Append a string as ASCII terminated by a CR/LF newline
803+
* Append a string as ASCII terminated by a newline (sometimes CR/LF, sometimes LF)
804804
*
805805
* @param string The string to append
806806
* @param buf The buffer to append to
807807
*/
808808
private static void appendAsciiLine(String string, ByteBuf buf) {
809809
ByteBufUtil.copy(AsciiString.of(string), buf);
810-
appendCrLf(buf);
810+
if (randomBoolean()) {
811+
buf.writeByte(HttpConstants.LF);
812+
} else {
813+
appendCrLf(buf);
814+
}
811815
}
812816

813817
/**

0 commit comments

Comments
 (0)