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 — Auto-port 4.2: Limit the number of Continuation frames per HTTP2 Headers by netty-project-bot · Pull Request #16536 · netty/netty

Auto-port 4.2: Limit the number of Continuation frames per HTTP2 Headers #16536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
normanmaurer merged 1 commit into 4.2 from auto-port-pr-13969-to-4.2
Mar 24, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Auto-port 4.2: Limit the number of Continuation frames per HTTP2 Headers #16536

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
c85facf
Limit the number of Continuation frames per HTTP2 Headers (#13969)
normanmaurer Mar 24, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Limit the number of Continuation frames per HTTP2 Headers (#13969)
Motivation:

We should limit the number of continuation frames that the remote peer
is allowed to sent per headers.

Modifications:

- Limit the number of continuation frames by default to 16 and allow the
user to change this.
- Add unit test

Result:

Do some more validations to guard against resource usage

---------

Co-authored-by: Bryce Anderson <[email protected]>
Co-authored-by: Chris Vest <[email protected]>
(cherry picked from commit 9f47a7b)
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@normanmaurer @bryce-anderson
@chrisvest @netty-project-bot
3 people authored and netty-project-bot committed Mar 24, 2026
commit c85facf14cb2752896fac365309c79d3ddf4dc11

There are no files selected for viewing

29 changes: 27 additions & 2 deletions 29 ...tp2/src/main/java/io/netty/handler/codec/http2/AbstractHttp2ConnectionHandlerBuilder.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* License for the specific language governing permissions and limitations
* under the License.
*/

package io.netty.handler.codec.http2;

import io.netty.channel.Channel;
Expand Down Expand Up @@ -113,6 +112,8 @@ public abstract class AbstractHttp2ConnectionHandlerBuilder<T extends Http2Conne
private int maxDecodedRstFramesSecondsPerWindow = 30;
private Integer maxEncodedRstFramesPerWindow;
private int maxEncodedRstFramesSecondsPerWindow = 30;
private int maxSmallContinuationFrames = Http2CodecUtil.DEFAULT_MAX_SMALL_CONTINUATION_FRAME;

/**
* Sets the {@link Http2Settings} to use for the initial connection settings exchange.
*/
Expand Down Expand Up @@ -466,6 +467,30 @@ protected B encoderEnforceMaxRstFramesPerWindow(int maxRstFramesPerWindow, int s
return self();
}

/**
* Returns the maximum number of small CONTINUATION frames per HEADERS block that are allowed
* before the connection is closed. Small is defined as 8 KiB, half the minimum allowed HTTP2 frame size.
* This setting is to protect against the remote peer flooding us with such frames.
*
* {@code 0} means no protection is in place.
*/
protected int decoderEnforceMaxSmallContinuationFrames() {
return maxSmallContinuationFrames;
}

/**
* Returns the maximum number of small CONTINUATION frames per HEADERS block that are allowed
* before the connection is closed. Small is defined as 8 KiB, half the minimum allowed HTTP2 frame size.
* This setting is to protect against the remote peer flooding us with such frames.
* {@code 0} means no protection should be applied.
*/
protected B decoderEnforceMaxSmallContinuationFrames(int maxSmallContinuationFrames) {
enforceNonCodecConstraints("maxSmallContinuationFrames");
this.maxSmallContinuationFrames = checkPositiveOrZero(
maxSmallContinuationFrames, "maxSmallContinuationFrames");
return self();
}

/**
* Determine if settings frame should automatically be acknowledged and applied.
* @return this.
Expand Down Expand Up @@ -571,7 +596,7 @@ private T buildFromConnection(Http2Connection connection) {
Long maxHeaderListSize = initialSettings.maxHeaderListSize();
Http2FrameReader reader = new DefaultHttp2FrameReader(new DefaultHttp2HeadersDecoder(isValidateHeaders(),
maxHeaderListSize == null ? DEFAULT_HEADER_LIST_SIZE : maxHeaderListSize,
/* initialHuffmanDecodeCapacity= */ -1));
/* initialHuffmanDecodeCapacity= */ -1), maxSmallContinuationFrames);
Http2FrameWriter writer = encoderIgnoreMaxHeaderListSize == null ?
new DefaultHttp2FrameWriter(headerSensitivityDetector()) :
new DefaultHttp2FrameWriter(headerSensitivityDetector(), encoderIgnoreMaxHeaderListSize);
Expand Down
46 changes: 43 additions & 3 deletions 46 codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameReader.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http2.Http2FrameReader.Configuration;
import io.netty.util.internal.ObjectUtil;
import io.netty.util.internal.PlatformDependent;

import static io.netty.handler.codec.http2.Http2CodecUtil.CONNECTION_STREAM_ID;
import static io.netty.handler.codec.http2.Http2CodecUtil.DEFAULT_MAX_FRAME_SIZE;
import static io.netty.handler.codec.http2.Http2CodecUtil.FRAME_HEADER_LENGTH;
import static io.netty.handler.codec.http2.Http2CodecUtil.INT_FIELD_LENGTH;
import static io.netty.handler.codec.http2.Http2CodecUtil.MAX_FRAME_SIZE_LOWER_BOUND;
import static io.netty.handler.codec.http2.Http2CodecUtil.PING_FRAME_PAYLOAD_LENGTH;
import static io.netty.handler.codec.http2.Http2CodecUtil.PRIORITY_ENTRY_LENGTH;
import static io.netty.handler.codec.http2.Http2CodecUtil.SETTINGS_INITIAL_WINDOW_SIZE;
import static io.netty.handler.codec.http2.Http2CodecUtil.SETTING_ENTRY_LENGTH;
import static io.netty.handler.codec.http2.Http2CodecUtil.headerListSizeExceeded;
import static io.netty.handler.codec.http2.Http2CodecUtil.isMaxFrameSizeValid;
import static io.netty.handler.codec.http2.Http2CodecUtil.readUnsignedInt;
import static io.netty.handler.codec.http2.Http2Error.ENHANCE_YOUR_CALM;
import static io.netty.handler.codec.http2.Http2Error.FLOW_CONTROL_ERROR;
import static io.netty.handler.codec.http2.Http2Error.FRAME_SIZE_ERROR;
import static io.netty.handler.codec.http2.Http2Error.PROTOCOL_ERROR;
Expand All @@ -51,6 +54,7 @@
* A {@link Http2FrameReader} that supports all frame types defined by the HTTP/2 specification.
*/
public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSizePolicy, Configuration {
private static final int FRAGMENT_THRESHOLD = MAX_FRAME_SIZE_LOWER_BOUND / 2;
private final Http2HeadersDecoder headersDecoder;

/**
Expand All @@ -67,7 +71,8 @@ public class DefaultHttp2FrameReader implements Http2FrameReader, Http2FrameSize
private Http2Flags flags;
private int payloadLength;
private HeadersContinuation headersContinuation;
private int maxFrameSize;
private int maxFrameSize = DEFAULT_MAX_FRAME_SIZE;
private final int maxSmallContinuationFrames;

/**
* Create a new instance.
Expand All @@ -88,8 +93,13 @@ public DefaultHttp2FrameReader(boolean validateHeaders) {
}

public DefaultHttp2FrameReader(Http2HeadersDecoder headersDecoder) {
this.headersDecoder = headersDecoder;
maxFrameSize = DEFAULT_MAX_FRAME_SIZE;
this(headersDecoder, Http2CodecUtil.DEFAULT_MAX_SMALL_CONTINUATION_FRAME);
}

public DefaultHttp2FrameReader(Http2HeadersDecoder headersDecoder, int maxSmallContinuationFrames) {
this.headersDecoder = ObjectUtil.checkNotNull(headersDecoder, "headersDecoder");
this.maxSmallContinuationFrames = ObjectUtil.checkPositiveOrZero(
maxSmallContinuationFrames, "maxSmallContinuationFrames");
}

@Override
Expand Down Expand Up @@ -390,6 +400,12 @@ private void verifyContinuationFrame() throws Http2Exception {
throw connectionError(PROTOCOL_ERROR, "Continuation stream ID does not match pending headers. "
+ "Expected %d, but received %d.", headersContinuation.getStreamId(), streamId);
}

if (headersContinuation.numSmallFragments() >= maxSmallContinuationFrames) {
throw connectionError(ENHANCE_YOUR_CALM,
"Number of small consecutive continuations frames %d exceeds maximum: %d",
headersContinuation.numSmallFragments(), maxSmallContinuationFrames);
}
}

private void verifyUnknownFrame() throws Http2Exception {
Expand Down Expand Up @@ -645,6 +661,15 @@ private abstract class HeadersContinuation {
*/
abstract int getStreamId();

/**
* Return the number of fragments that were used so far.
*
* @return the number of fragments
*/
final int numSmallFragments() {
return builder.numSmallFragments();
}

/**
* Processes the next fragment for the current header block.
*
Expand Down Expand Up @@ -673,6 +698,7 @@ final void close() {
*/
protected class HeadersBlockBuilder {
private ByteBuf headerBlock;
private int numSmallFragments;

/**
* The local header size maximum has been exceeded while accumulating bytes.
Expand All @@ -683,6 +709,15 @@ private void headerSizeExceeded() throws Http2Exception {
headerListSizeExceeded(headersDecoder.configuration().maxHeaderListSizeGoAway());
}

/**
* Return the number of fragments that was used so far.
*
* @return number of fragments.
*/
int numSmallFragments() {
return numSmallFragments;
}

/**
* Adds a fragment to the block.
*
Expand All @@ -694,6 +729,11 @@ private void headerSizeExceeded() throws Http2Exception {
*/
final void addFragment(ByteBuf fragment, int len, ByteBufAllocator alloc,
boolean endOfHeaders) throws Http2Exception {
if (maxSmallContinuationFrames > 0 && !endOfHeaders && len < FRAGMENT_THRESHOLD) {
// Only count of the fragment is not the end of header and if its < 8kb.
numSmallFragments++;
}

if (headerBlock == null) {
if (len > headersDecoder.configuration().maxHeaderListSizeGoAway()) {
headerSizeExceeded();
Expand Down
2 changes: 1 addition & 1 deletion 2 codec-http2/src/main/java/io/netty/handler/codec/http2/Http2CodecUtil.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public final class Http2CodecUtil {
public static final int SMALLEST_MAX_CONCURRENT_STREAMS = 100;
static final int DEFAULT_MAX_RESERVED_STREAMS = SMALLEST_MAX_CONCURRENT_STREAMS;
static final int DEFAULT_MIN_ALLOCATION_CHUNK = 1024;

static final int DEFAULT_MAX_SMALL_CONTINUATION_FRAME = 16;
/**
* Calculate the threshold in bytes which should trigger a {@code GO_AWAY} if a set of headers exceeds this amount.
* @param maxHeaderListSize
Expand Down
14 changes: 13 additions & 1 deletion 14 codec-http2/src/main/java/io/netty/handler/codec/http2/Http2FrameCodecBuilder.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,17 @@ public Http2FrameCodecBuilder encoderEnforceMaxRstFramesPerWindow(
return super.encoderEnforceMaxRstFramesPerWindow(maxRstFramesPerWindow, secondsPerWindow);
}

@Override
public int decoderEnforceMaxSmallContinuationFrames() {
return super.decoderEnforceMaxSmallContinuationFrames();
}

@Override
public Http2FrameCodecBuilder decoderEnforceMaxSmallContinuationFrames(
int maxConsecutiveContinuationsFrames) {
return super.decoderEnforceMaxSmallContinuationFrames(maxConsecutiveContinuationsFrames);
}

/**
* Build a {@link Http2FrameCodec} object.
*/
Expand All @@ -216,7 +227,8 @@ public Http2FrameCodec build() {
Long maxHeaderListSize = initialSettings().maxHeaderListSize();
Http2FrameReader frameReader = new DefaultHttp2FrameReader(maxHeaderListSize == null ?
new DefaultHttp2HeadersDecoder(isValidateHeaders()) :
new DefaultHttp2HeadersDecoder(isValidateHeaders(), maxHeaderListSize));
new DefaultHttp2HeadersDecoder(isValidateHeaders(), maxHeaderListSize),
decoderEnforceMaxSmallContinuationFrames());

if (frameLogger() != null) {
frameWriter = new Http2OutboundFrameLogger(frameWriter, frameLogger());
Expand Down
14 changes: 13 additions & 1 deletion 14 codec-http2/src/main/java/io/netty/handler/codec/http2/Http2MultiplexCodecBuilder.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ public Http2MultiplexCodecBuilder encoderEnforceMaxRstFramesPerWindow(
return super.encoderEnforceMaxRstFramesPerWindow(maxRstFramesPerWindow, secondsPerWindow);
}

@Override
public int decoderEnforceMaxSmallContinuationFrames() {
return super.decoderEnforceMaxSmallContinuationFrames();
}

@Override
public Http2MultiplexCodecBuilder decoderEnforceMaxSmallContinuationFrames(
int maxConsecutiveContinuationsFrames) {
return super.decoderEnforceMaxSmallContinuationFrames(maxConsecutiveContinuationsFrames);
}

@Override
public Http2MultiplexCodec build() {
Http2FrameWriter frameWriter = this.frameWriter;
Expand All @@ -231,7 +242,8 @@ public Http2MultiplexCodec build() {
Long maxHeaderListSize = initialSettings().maxHeaderListSize();
Http2FrameReader frameReader = new DefaultHttp2FrameReader(maxHeaderListSize == null ?
new DefaultHttp2HeadersDecoder(isValidateHeaders()) :
new DefaultHttp2HeadersDecoder(isValidateHeaders(), maxHeaderListSize));
new DefaultHttp2HeadersDecoder(isValidateHeaders(), maxHeaderListSize),
decoderEnforceMaxSmallContinuationFrames());

if (frameLogger() != null) {
frameWriter = new Http2OutboundFrameLogger(frameWriter, frameLogger());
Expand Down
53 changes: 53 additions & 0 deletions 53 codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2FrameReaderTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,59 @@ public void readHeaderFrameAndContinuationFrame() throws Http2Exception {
}
}

@Test
public void readHeaderFrameAndContinuationFrameExceedMax() throws Http2Exception {
frameReader = new DefaultHttp2FrameReader(new DefaultHttp2HeadersDecoder(true), 2);
final int streamId = 1;

final ByteBuf input = Unpooled.buffer();
try {
Http2Headers headers = new DefaultHttp2Headers()
.authority("foo")
.method("get")
.path("/")
.scheme("https");
writeHeaderFrame(input, streamId, headers,
new Http2Flags().endOfHeaders(false).endOfStream(true));
writeContinuationFrame(input, streamId, new DefaultHttp2Headers().add("foo", "bar"),
new Http2Flags().endOfHeaders(false));
writeContinuationFrame(input, streamId, new DefaultHttp2Headers().add("foo2", "bar2"),
new Http2Flags().endOfHeaders(false));

Http2Exception ex = assertThrows(Http2Exception.class, new Executable() {
@Override
public void execute() throws Throwable {
frameReader.readFrame(ctx, input, listener);
}
});
assertEquals(Http2Error.ENHANCE_YOUR_CALM, ex.error());
} finally {
input.release();
}
}

@Test
public void readHeaderFrameAndContinuationFrameDontExceedMax() throws Http2Exception {
frameReader = new DefaultHttp2FrameReader(new DefaultHttp2HeadersDecoder(true), 2);
final int streamId = 1;

final ByteBuf input = Unpooled.buffer();
try {
Http2Headers headers = new DefaultHttp2Headers()
.authority("foo")
.method("get")
.path("/")
.scheme("https");
writeHeaderFrame(input, streamId, headers,
new Http2Flags().endOfHeaders(false).endOfStream(true));
writeContinuationFrame(input, streamId, new DefaultHttp2Headers().add("foo", "bar"),
new Http2Flags().endOfHeaders(false));
frameReader.readFrame(ctx, input, listener);
} finally {
input.release();
}
}

@Test
public void readUnknownFrame() throws Http2Exception {
ByteBuf input = Unpooled.buffer();
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
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.