GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — HTTP3: Limit the max payload length of unknown frames · netty/netty@cfcfb97

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codec-http3/src
    • main/java/io/netty/handler/codec/http3
      • Http3ClientConnectionHandler.java
      • Http3CodecUtils.java
      • Http3ConnectionHandler.java
      • Http3FrameCodec.java
      • Http3ServerConnectionHandler.java
    • test/java/io/netty/handler/codec/http3
      • Http3FrameCodecTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codec-http3/src/main/java/io/netty/handler/codec/http3/Http3ClientConnectionHandler.java‎

Copy file name to clipboardExpand all lines: codec-http3/src/main/java/io/netty/handler/codec/http3/Http3ClientConnectionHandler.java
+33-1Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,40 @@ public Http3ClientConnectionHandler(@Nullable ChannelHandler inboundControlStrea
8383
@Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable,
8484
@Nullable Http3Settings.NonStandardHttp3SettingsValidator
8585
nonStandardSettingsValidator) {
86+
this(inboundControlStreamHandler, pushStreamHandlerFactory, unknownInboundStreamHandlerFactory, localSettings,
87+
disableQpackDynamicTable, nonStandardSettingsValidator,
88+
Http3CodecUtils.DEFAULT_MAX_UNKNOWN_FRAME_PAYLOAD_LENGTH);
89+
}
90+
91+
/**
92+
* Create a new instance.
93+
*
94+
* @param inboundControlStreamHandler the {@link ChannelHandler} which will be notified about
95+
* {@link Http3RequestStreamFrame}s or {@code null} if the user is not
96+
* interested in these.
97+
* @param pushStreamHandlerFactory the {@link LongFunction} that will provide a custom
98+
* {@link ChannelHandler} for push streams {@code null} if no special
99+
* handling should be done. When present, push ID will be passed as an
100+
* argument to the {@link LongFunction}.
101+
* @param unknownInboundStreamHandlerFactory the {@link LongFunction} that will provide a custom
102+
* {@link ChannelHandler} for unknown inbound stream types or
103+
* {@code null} if no special handling should be done.
104+
* @param localSettings the local {@link Http3SettingsFrame} that should be sent to the
105+
* remote peer or {@code null} if the default settings should be used.
106+
* @param disableQpackDynamicTable If QPACK dynamic table should be disabled.
107+
* @param nonStandardSettingsValidator the {@link Http3Settings.NonStandardHttp3SettingsValidator} to use
108+
* when validating settings that are non-standard.
109+
* @param maxUnknownFramePayloadLength the maximum payload size of an unknown frame.
110+
*/
111+
public Http3ClientConnectionHandler(@Nullable ChannelHandler inboundControlStreamHandler,
112+
@Nullable LongFunction<ChannelHandler> pushStreamHandlerFactory,
113+
@Nullable LongFunction<ChannelHandler> unknownInboundStreamHandlerFactory,
114+
@Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable,
115+
@Nullable Http3Settings.NonStandardHttp3SettingsValidator
116+
nonStandardSettingsValidator,
117+
int maxUnknownFramePayloadLength) {
86118
super(false, inboundControlStreamHandler, unknownInboundStreamHandlerFactory, localSettings,
87-
disableQpackDynamicTable, nonStandardSettingsValidator);
119+
disableQpackDynamicTable, nonStandardSettingsValidator, maxUnknownFramePayloadLength);
88120
this.pushStreamHandlerFactory = pushStreamHandlerFactory;
89121
}
90122

Collapse file

‎codec-http3/src/main/java/io/netty/handler/codec/http3/Http3CodecUtils.java‎

Copy file name to clipboardExpand all lines: codec-http3/src/main/java/io/netty/handler/codec/http3/Http3CodecUtils.java
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ final class Http3CodecUtils {
6363
*/
6464
static final long DEFAULT_MAX_FIELD_SECTION_SIZE = 8192;
6565

66+
// Let's use 32kb as max
67+
static final int DEFAULT_MAX_UNKNOWN_FRAME_PAYLOAD_LENGTH = 32 * 1024;
68+
6669
private Http3CodecUtils() { }
6770

6871
static long checkIsReservedFrameType(long type) {
Collapse file

‎codec-http3/src/main/java/io/netty/handler/codec/http3/Http3ConnectionHandler.java‎

Copy file name to clipboardExpand all lines: codec-http3/src/main/java/io/netty/handler/codec/http3/Http3ConnectionHandler.java
+5-2Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,13 @@ public abstract class Http3ConnectionHandler extends ChannelInboundHandlerAdapte
5858
* @param localSettings the local {@link Http3SettingsFrame} that should be sent to the
5959
* remote peer or {@code null} if the default settings should be used.
6060
* @param disableQpackDynamicTable If QPACK dynamic table should be disabled.
61+
* @param maxUnknownFramePayloadLength the maximum payload size of an unknown frame.
6162
*/
6263
Http3ConnectionHandler(boolean server, @Nullable ChannelHandler inboundControlStreamHandler,
6364
@Nullable LongFunction<ChannelHandler> unknownInboundStreamHandlerFactory,
6465
@Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable,
65-
@Nullable Http3Settings.NonStandardHttp3SettingsValidator nonStandardSettingsValidator) {
66+
@Nullable Http3Settings.NonStandardHttp3SettingsValidator nonStandardSettingsValidator,
67+
int maxUnknownFramePayloadLength) {
6668
this.unknownInboundStreamHandlerFactory = unknownInboundStreamHandlerFactory;
6769
this.disableQpackDynamicTable = disableQpackDynamicTable;
6870
if (nonStandardSettingsValidator != null) {
@@ -95,7 +97,8 @@ public abstract class Http3ConnectionHandler extends ChannelInboundHandlerAdapte
9597
);
9698
qpackDecoder = new QpackDecoder(maxTableCapacity, maxBlockedStreams);
9799
qpackEncoder = new QpackEncoder();
98-
codecFactory = Http3FrameCodec.newFactory(qpackDecoder, maxFieldSectionSize, qpackEncoder);
100+
codecFactory = Http3FrameCodec.newFactory(
101+
qpackDecoder, maxFieldSectionSize, maxUnknownFramePayloadLength, qpackEncoder);
99102
remoteControlStreamHandler = new Http3ControlStreamOutboundHandler(server, localSettings,
100103
codecFactory.newCodec(Http3FrameTypeValidator.NO_VALIDATION, NO_STATE, NO_STATE,
101104
this.nonStandardSettingsValidator));
Collapse file

‎codec-http3/src/main/java/io/netty/handler/codec/http3/Http3FrameCodec.java‎

Copy file name to clipboardExpand all lines: codec-http3/src/main/java/io/netty/handler/codec/http3/Http3FrameCodec.java
+13-4Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@
5151
import static io.netty.handler.codec.http3.Http3CodecUtils.writeVariableLengthInteger;
5252
import static io.netty.util.internal.ObjectUtil.checkNotNull;
5353
import static io.netty.util.internal.ObjectUtil.checkPositive;
54+
import static io.netty.util.internal.ObjectUtil.checkPositiveOrZero;
5455

5556
/**
5657
* Decodes / encodes {@link Http3Frame}s.
5758
*/
5859
final class Http3FrameCodec extends ByteToMessageDecoder implements ChannelOutboundHandler {
5960
private final Http3FrameTypeValidator validator;
6061
private final long maxHeaderListSize;
62+
private final int maxUnknownFramePayloadLength;
6163
private final QpackDecoder qpackDecoder;
6264
private final QpackEncoder qpackEncoder;
6365
private final Http3RequestStreamCodecState encodeState;
@@ -72,23 +74,29 @@ final class Http3FrameCodec extends ByteToMessageDecoder implements ChannelOutbo
7274
private WriteResumptionListener writeResumptionListener;
7375

7476
static Http3FrameCodecFactory newFactory(QpackDecoder qpackDecoder,
75-
long maxHeaderListSize, QpackEncoder qpackEncoder) {
77+
long maxHeaderListSize, int maxUnknownFramePayloadLength,
78+
QpackEncoder qpackEncoder) {
7679
checkNotNull(qpackEncoder, "qpackEncoder");
7780
checkNotNull(qpackDecoder, "qpackDecoder");
81+
checkPositive(maxHeaderListSize, "maxHeaderListSize");
82+
checkPositive(maxUnknownFramePayloadLength, "maxUnknownFramePayloadLength");
7883

7984
// QPACK decoder and encoder are shared between streams in a connection.
8085
return (validator, encodeState, decodeState,
8186
nonStandardSettingsValidator) -> new Http3FrameCodec(validator, qpackDecoder,
82-
maxHeaderListSize, qpackEncoder, encodeState, decodeState, nonStandardSettingsValidator);
87+
maxHeaderListSize, maxUnknownFramePayloadLength, qpackEncoder,
88+
encodeState, decodeState, nonStandardSettingsValidator);
8389
}
8490

8591
Http3FrameCodec(Http3FrameTypeValidator validator, QpackDecoder qpackDecoder,
86-
long maxHeaderListSize, QpackEncoder qpackEncoder, Http3RequestStreamCodecState encodeState,
92+
long maxHeaderListSize, int maxUnknownFramePayloadLength,
93+
QpackEncoder qpackEncoder, Http3RequestStreamCodecState encodeState,
8794
Http3RequestStreamCodecState decodeState,
8895
Http3Settings.NonStandardHttp3SettingsValidator nonStandardSettingsValidator) {
8996
this.validator = checkNotNull(validator, "validator");
9097
this.qpackDecoder = checkNotNull(qpackDecoder, "qpackDecoder");
9198
this.maxHeaderListSize = checkPositive(maxHeaderListSize, "maxHeaderListSize");
99+
this.maxUnknownFramePayloadLength = checkPositive(maxUnknownFramePayloadLength, "maxUnknownFramePayloadLength");
92100
this.qpackEncoder = checkNotNull(qpackEncoder, "qpackEncoder");
93101
this.encodeState = checkNotNull(encodeState, "encodeState");
94102
this.decodeState = checkNotNull(decodeState, "decodeState");
@@ -335,7 +343,8 @@ private int decodeFrame(ChannelHandlerContext ctx, long longType, int payLoadLen
335343
}
336344
// Handling reserved frame types
337345
// https://tools.ietf.org/html/draft-ietf-quic-http-32#section-7.2.8
338-
if (in.readableBytes() < payLoadLength) {
346+
if (!enforceMaxPayloadLength(ctx, in, type, payLoadLength,
347+
maxUnknownFramePayloadLength, Http3ErrorCode.H3_EXCESSIVE_LOAD)) {
339348
return 0;
340349
}
341350
out.add(new DefaultHttp3UnknownFrame(longType, in.readRetainedSlice(payLoadLength)));
Collapse file

‎codec-http3/src/main/java/io/netty/handler/codec/http3/Http3ServerConnectionHandler.java‎

Copy file name to clipboardExpand all lines: codec-http3/src/main/java/io/netty/handler/codec/http3/Http3ServerConnectionHandler.java
+31-1Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,38 @@ public Http3ServerConnectionHandler(ChannelHandler requestStreamHandler,
8787
@Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable,
8888
@Nullable Http3Settings.NonStandardHttp3SettingsValidator
8989
nonStandardSettingsValidator) {
90+
this(requestStreamHandler, inboundControlStreamHandler, unknownInboundStreamHandlerFactory, localSettings,
91+
disableQpackDynamicTable, nonStandardSettingsValidator,
92+
Http3CodecUtils.DEFAULT_MAX_UNKNOWN_FRAME_PAYLOAD_LENGTH);
93+
}
94+
95+
/**
96+
* Create a new instance.
97+
* @param requestStreamHandler the {@link ChannelHandler} that is used for each new request stream.
98+
* This handler will receive {@link Http3HeadersFrame} and
99+
* {@link Http3DataFrame}s.
100+
* @param inboundControlStreamHandler the {@link ChannelHandler} which will be notified about
101+
* {@link Http3RequestStreamFrame}s or {@code null} if the user is not
102+
* interested in these.
103+
* @param unknownInboundStreamHandlerFactory the {@link LongFunction} that will provide a custom
104+
* {@link ChannelHandler} for unknown inbound stream types or
105+
* {@code null} if no special handling should be done.
106+
* @param localSettings the local {@link Http3SettingsFrame} that should be sent to the
107+
* remote peer or {@code null} if the default settings should be used.
108+
* @param disableQpackDynamicTable If QPACK dynamic table should be disabled.
109+
* @param nonStandardSettingsValidator the {@link Http3Settings.NonStandardHttp3SettingsValidator} to
110+
* use when validating settings that are non-standard.
111+
* @param maxUnknownFramePayloadLength the maximum payload size of an unknown frame.
112+
*/
113+
public Http3ServerConnectionHandler(ChannelHandler requestStreamHandler,
114+
@Nullable ChannelHandler inboundControlStreamHandler,
115+
@Nullable LongFunction<ChannelHandler> unknownInboundStreamHandlerFactory,
116+
@Nullable Http3SettingsFrame localSettings, boolean disableQpackDynamicTable,
117+
@Nullable Http3Settings.NonStandardHttp3SettingsValidator
118+
nonStandardSettingsValidator,
119+
int maxUnknownFramePayloadLength) {
90120
super(true, inboundControlStreamHandler, unknownInboundStreamHandlerFactory, localSettings,
91-
disableQpackDynamicTable, nonStandardSettingsValidator);
121+
disableQpackDynamicTable, nonStandardSettingsValidator, maxUnknownFramePayloadLength);
92122
this.requestStreamHandler = ObjectUtil.checkNotNull(requestStreamHandler, "requestStreamHandler");
93123
}
94124

Collapse file

‎codec-http3/src/test/java/io/netty/handler/codec/http3/Http3FrameCodecTest.java‎

Copy file name to clipboardExpand all lines: codec-http3/src/test/java/io/netty/handler/codec/http3/Http3FrameCodecTest.java
+18-1Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public static Collection<Object[]> dataNoFragment() {
9494
private EmbeddedQuicStreamChannel codecChannel;
9595

9696
private void setUp(int maxBlockedStreams, boolean delayQpackStreams) throws Exception {
97+
setUp(maxBlockedStreams, delayQpackStreams, Integer.MAX_VALUE);
98+
}
99+
100+
private void setUp(int maxBlockedStreams, boolean delayQpackStreams, int maxUnknownFramePayloadLength)
101+
throws Exception {
97102
parent = new EmbeddedQuicChannel(true);
98103
qpackAttributes = new QpackAttributes(parent, false);
99104
Http3.setQpackAttributes(parent, qpackAttributes);
@@ -129,7 +134,8 @@ protected void initChannel(QuicStreamChannel ch) {
129134
Http3RequestStreamDecodeStateValidator decStateValidator =
130135
new Http3RequestStreamDecodeStateValidator();
131136
ch.pipeline().addLast(new Http3FrameCodec(Http3FrameTypeValidator.NO_VALIDATION, decoder,
132-
MAX_HEADER_SIZE, encoder, encStateValidator, decStateValidator, (id, v) -> false));
137+
MAX_HEADER_SIZE, maxUnknownFramePayloadLength, encoder,
138+
encStateValidator, decStateValidator, (id, v) -> false));
133139
ch.pipeline().addLast(encStateValidator);
134140
ch.pipeline().addLast(decStateValidator);
135141
}
@@ -374,6 +380,17 @@ public void testHttp3UnknownFrame(
374380
new DefaultHttp3UnknownFrame(Http3CodecUtils.MIN_RESERVED_FRAME_TYPE, Unpooled.buffer().writeLong(8)));
375381
}
376382

383+
@ParameterizedTest(name = "{index}: fragmented = {0}, maxBlockedStreams = {1}, delayQpackStreams = {2}")
384+
@MethodSource("data")
385+
public void testHttp3UnknownFrameWithInvalidPayloadLength(
386+
boolean fragmented, int maxBlockedStreams, boolean delayQpackStreams) throws Exception {
387+
setUp(maxBlockedStreams, delayQpackStreams, 127);
388+
assertThrows(Http3Exception.class, () ->
389+
testFrameEncodedAndDecoded(fragmented, maxBlockedStreams, delayQpackStreams,
390+
new DefaultHttp3UnknownFrame(Http3CodecUtils.MIN_RESERVED_FRAME_TYPE,
391+
Unpooled.buffer().writeZero(128))));
392+
}
393+
377394
// Reserved types that were used in HTTP/2 and should close the connection with an error
378395
@ParameterizedTest(name = "{index}: fragmented = {0}, maxBlockedStreams = {1}, delayQpackStreams = {2}")
379396
@MethodSource("data")

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.