netty-codec-http2 denial of service
Description
A Netty HTTP/2 endpoint retains 6 bytes of per-connection state for every SETTINGS_HEADER_TABLE_SIZE value change a remote peer sends — unbounded, never coalesced, and drained only when the local endpoint writes a HEADERS or PUSH_PROMISE block. Each changed value appends a dynamic-table-size-update into DefaultHttp2HeadersEncoder.tableSizeChangeOutput, an unpooled heap ByteBuf with no capacity ceiling, so an unauthenticated peer that simply never sends a request grows it without limit. Default-configured servers reach java.lang.OutOfMemoryError after ~232 MiB of SETTINGS traffic in ~11–14 s at -Xmx192m, on both 4.1.137.Final and 4.2.17.Final, with numActiveStreams() == 0 — no stream is ever opened; the full documented hardening configuration does not change this. Every frame is protocol-legal — RFC 9113 §6.5: a SETTINGS frame "MAY be sent at any other time by either endpoint over the lifetime of the connection."
Root cause
DefaultHttp2HeadersEncoder.java is byte-identical at netty-4.1.137.Final and netty-4.2.17.Final (diff-verified). An exhaustive grep of both official sources jars finds tableSizeChangeOutput in exactly one file, with exactly 10 occurrences — all of them here, so no other append, drain, or release site exists in the module:
32 private ByteBuf tableSizeChangeOutput;
71 if (tableSizeChangeOutput != null && tableSizeChangeOutput.isReadable()) { // in encodeHeaders(...)
72 buffer.writeBytes(tableSizeChangeOutput);
73 tableSizeChangeOutput.clear(); // <-- THE ONLY DRAIN
85 public void maxHeaderTableSize(long max) throws Http2Exception {
87 tableSizeChangeOutput = Unpooled.buffer(); // <-- UNPOOLED HEAP, NO CAPACITY CEILING
89 hpackEncoder.setMaxHeaderTableSize(tableSizeChangeOutput, max); // <-- THE APPEND SITE
118 tableSizeChangeOutput.release(); // <-- ONLY RELEASE, in close(), at teardownAppend site — HpackEncoder.java:234-246, identical lines and content at both tags:
239 if (this.maxHeaderTableSize == maxHeaderTableSize) {
240 return; // <-- unchanged value: no append. This is the CONTROL.
242 this.maxHeaderTableSize = maxHeaderTableSize;
245 encodeInteger(out, 0x20, 5, maxHeaderTableSize); // <-- 1..6 bytes per CHANGED valueNo coalescing, no cap; the :235 bounds check rejects nothing a peer can send — Http2CodecUtil.MAX_HEADER_TABLE_SIZE = MAX_UNSIGNED_INT (4.1.137 :90, 4.2.17 :91) and MIN_HEADER_TABLE_SIZE = 0 (4.1.137 :97, 4.2.17 :98); content identical, lines differ per branch.
The peer's value is applied unconditionally on servers. autoAckSettings (the default) nulls settingsReceivedConsumer (DefaultHttp2ConnectionDecoder.java:169-170, both tags), so onSettingsRead calls encoder.remoteSettings(settings) directly (4.1.137 :605-615; 4.2.17 :598-608). In DefaultHttp2ConnectionEncoder.java, identical lines at both tags:
100 if (headerTableSize != null) {
101 outboundHeaderConfig.maxHeaderTableSize(headerTableSize); // <-- NO GUARD
105 if (maxHeaderListSize != null && !connection.isServer()) { // <-- GUARDED (the neighbour)RFC 7541 §4.2:
"Multiple updates to the maximum table size can occur between the transmission of two header blocks. In the case that this size is changed more than once in this interval, the smallest maximum table size that occurs in that interval MUST be signaled in a dynamic table size update. The final maximum size is always signaled, resulting in at most two dynamic table size updates."
A conforming encoder therefore emits at most two updates between header blocks (~12 bytes); Netty emits one per distinct change, without limit. RFC 9113 §6.5 adds that a receiver need not accumulate anything:
"Each parameter in a SETTINGS frame replaces any existing value for that parameter. Settings are processed in the order in which they appear, and a receiver of a SETTINGS frame does not need to maintain any state other than the current value of each setting."
Netty keeps O(number of changes) state where the specification says O(1) suffices.
Proof of concept
Live and end-to-end over real TCP sockets — not EmbeddedChannel, not a mirrored algorithm. Victim: a stock Http2FrameCodecBuilder.forServer().build() plus Http2MultiplexHandler, zero options set, against unmodified Maven Central jars. Attacker: a plain java.net.Socket sending the preface and hand-assembled 15-byte SETTINGS frames (h2c prior knowledge); instrumentation is read-only reflection on the live field. The finder ran both sides in one JVM under a single -Xmx; an independent verifier re-ran it with victim (-Xmx192m) and attacker (-Xmx256m) in separate JVMs — removing any objection that the attacker's own allocations caused the OOM — and reproduced it identically.
ATTACK alternates 0xFFFFFFFF/0xFFFFFFFE, always a change, so it appends at :245; CONTROL repeats 0xFFFFFFFF and early-returns at :239-241. Identical frame count, frame size, and total wire bytes — only the low byte of every second value differs.
netty 4.1.137.Final, default config, -Xmx512m
CONTROL frames=200000 wire=3000033 readableBytes=6 ratio=0.000 0 active streams
ATTACK frames=200000 wire=3000033 readableBytes=1200000 ratio=0.400 0 active streams
netty 4.2.17.Final, same A/B: CONTROL 6 / 0.000 ; ATTACK 1200000 / 0.400Escalation to actual JVM death — 4.1.137.Final, DEFAULT config, -Xmx192m:
t= 14s wire= 232 MiB retained= 91 MiB heapUsed= 125 MiB
[SERVER THROWABLE] java.lang.OutOfMemoryError: Java heap space
at io.netty.buffer.AbstractByteBuf.ensureWritable0(AbstractByteBuf.java:305)
at io.netty.buffer.AbstractByteBuf.writeByte(AbstractByteBuf.java:984)
[client] connection died after 232 MiB of SETTINGS frames in 14s: SocketException: Broken pipeTerminal frame: HpackEncoder.encodeInteger writing into tableSizeChangeOutput. 4.2.17.Final on DEFAULT config reproduces it (232 MiB / 12 s). Control at OOM scale, sending more traffic than killed the attack run: mode=oomcontrol wireMiB=300 retainedBytes=6 serverAlive=true — alive on 6 bytes, which refutes any bandwidth- or frame-rate-DoS reading.
Why configuration does not close it
Re-run with every documented hardening knob on — maxConcurrentStreams(100), maxHeaderListSize(8192), maxFrameSize(16384), initialWindowSize(65535), headerTableSize(4096), validateHeaders(true), validateRequiredPseudoHeaders(true), encoderEnforceMaxQueuedControlFrames(100), decoderEnforceMaxRstFramesPerWindow(20, 30), decoderEnforceMaxConsecutiveEmptyDataFrames(2), decoderEnforceMaxSmallContinuationFrames(4), gracefulShutdownTimeoutMillis(1000) — the hardened server died with the same terminal frame (t=13s wire=225 MiB retained=88 MiB; client saw death after 234 MiB / 13 s), indistinguishable from default (232 MiB / 14 s). No knob closes it: (1) there is no API to cap, clamp, or ignore a peer-supplied SETTINGS_HEADER_TABLE_SIZE, nor to bound tableSizeChangeOutput — the exhaustive grep establishes this; (2) initialSettings().headerTableSize(4096) is an operator trap, configuring the server's own HPACK decoder via applyLocalSettings → Http2HeadersDecoder.Configuration (4.1.137 :566/:585, 4.2.17 :559/:578), not the encoder; (3) encoderEnforceMaxQueuedControlFrames bounds only frames queued but unwritten, and the attacker paces so SETTINGS ACKs flush normally — as the hardened run shows.
Impact
Availability. Any remote peer that can open one TCP connection and complete an HTTP/2 handshake (TLS-ALPN h2 or h2c prior knowledge) — no credentials, no request, no stream ever opened (numActiveStreams() was 0 in every run, which is exactly what keeps the drain at :71-73 unreachable) — drives an unbounded per-connection heap buffer to OutOfMemoryError in seconds at a modest heap, on default and fully-hardened configuration, on both maintained branches. The arithmetic closes: encodeInteger(out, 0x20, 5, 0xFFFFFFFF) emits a 1-byte prefix plus 5 continuation octets = 6 bytes per changed value, × 200,000 = 1,200,000 retained against 3,000,033 wire bytes (6/15 = 0.400, the measured ratio), and 232 MiB × 0.400 = 92.8 MiB, consistent with the 91 MiB sampled just before death. A:H rests on sustained scalable retention — 24 idle, unauthenticated, zero-stream connections held 184 MiB of a 192 MiB heap indefinitely (184/192 = 95.8%) — on linearity in connection count, and on the absence of any bounding API.
Suggested fix
Primary — make the encoder RFC 7541 §4.2 compliant, bounding the buffer to ~12 bytes and removing an existing spec violation: record the pending change rather than appending, and serialize at drain time.
private long pendingMinTableSize = -1; // smallest value seen since the last header block
private long pendingFinalTableSize = -1; // most recent value seen
@Override
public void maxHeaderTableSize(long max) throws Http2Exception {
// Validate exactly as HpackEncoder.setMaxHeaderTableSize does today (lines 235-238),
// so a bad value still raises a connection error at the same point.
if (max < MIN_HEADER_TABLE_SIZE || max > MAX_HEADER_TABLE_SIZE) {
throw connectionError(PROTOCOL_ERROR, "Header Table Size must be >= %d and <= %d but was %d",
MIN_HEADER_TABLE_SIZE, MAX_HEADER_TABLE_SIZE, max);
}
pendingMinTableSize = pendingMinTableSize < 0 ? max : min(pendingMinTableSize, max);
pendingFinalTableSize = max;
}Then in encodeHeaders(...) emit at most the two required updates and clear the pending state: O(1) per connection, at most 12 bytes on the wire. Alternatives, any of which also closes it: hard-cap the buffer with Unpooled.buffer(initial, maxCapacity) at :87 — 64 bytes suffices, since a compliant encoder needs ~12 — erroring or dropping the excess on overflow (the one-line minimal patch); extend the !connection.isServer() pattern at :104-108 to lines 99–102 by clamping or rate-limiting (a behaviour change: unlike SETTINGS_MAX_HEADER_LIST_SIZE this setting is not advisory, so simply ignoring it is not obviously correct); or coalesce in HpackEncoder.setMaxHeaderTableSize, rewriting an already-pending unflushed update in place. Regression test: N distinct values with no intervening header block, asserting tableSizeChangeOutput.readableBytes() <= 12 for N = 1, 100, and 100,000 — today that fails at N = 100,000 with 600,000 bytes retained.
Prior art / relationship to previous fixes
Not fix-introduced, and not an incomplete fix of any advisory: the codec-http2 tree was diffed across 4.1.131 → 4.1.132 → 4.1.134 → 4.1.135 → 4.1.136 → 4.1.137 and DefaultHttp2HeadersEncoder.java is byte-identical across that range. It is the direct sibling of a recently patched issue: GHSA-563q-j3cm-6jxm / CVE-2026-50560 concerns the other advisory SETTINGS value, SETTINGS_MAX_HEADER_LIST_SIZE, and its published remediation text reads, verbatim:
"It would be best to ignore the SETTINGS_MAX_HEADER_LIST_SIZE setting from clients (or ignore it when sending to clients)."
Netty implemented exactly that — the !connection.isServer() guard now at DefaultHttp2ConnectionEncoder.java:104-108, first patched in 4.1.135.Final / 4.2.15.Final. The adjacent block at lines 99–102 received no such guard, and that neighbouring setting is strictly worse because it additionally accumulates unbounded state. CVE-2026-50560 is itself rated 5.3 Moderate (A:L) and is cited here only as evidence that Netty accepts peer-controlled-SETTINGS hardening as in scope — not as the severity comparator. The severity comparator is GHSA-93wv-jw9v-4972 / CVE-2026-56819, a comparable HTTP/2 memory-exhaustion DoS carrying the identical CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H at 7.5 (verified from OSV).
Sweep and duplicate check. The only issues/PRs touching this area — #13589 (lazy allocation, a performance change), #13870 (unpooled memory metrics), #12781 (a netty5 buffer-API leak fix on a deprecated branch), #12981/#12988 (HPACK decoder placement validation) — none bounds this buffer. OSV version-pinned reports 0 vulnerabilities at 4.1.137.Final and 4.2.17.Final; all 11 package-level advisories were enumerated, and none concerns SETTINGS_HEADER_TABLE_SIZE, the HPACK encoder, or this buffer. Http2ControlFrameLimitEncoder (the 2019-era SETTINGS-flood mitigation) bounds queued outbound control frames and is empirically not a mitigation here: the control sent identical frame and ACK volume, yet stayed flat at 6 bytes.
---
PoC sources are retained and can be provided in whatever form the Netty security team prefers:
- Finder's end-to-end PoC — modes
control/attack/oomcontrol/oom, plus an optionalhardenedargument that swaps in the fully-hardened server (Poc.java,pom.xml, resolved classpathscp.txt/cp42.txt). - Verifier's two-JVM rerun — separate victim/attacker JVMs, default and hardened servers, negative controls (
Server.java,ServerHardened.java,Client.java,MultiClient.java,Negatives.java).
Happy to supply sources, complete logs, a container image, or a patch plus regression test on request.