Skip to content

Commit 9a44908

Browse files
committed
#12690 cap MAX_HEADER_LIST_SIZE
Signed-off-by: Ludovic Orban <[email protected]>
1 parent 9761d61 commit 9a44908

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

jetty-core/jetty-http2/jetty-http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,14 @@ private void configure(Map<Integer, Integer> settings, boolean local)
464464
if (LOG.isDebugEnabled())
465465
LOG.debug("Updating {} max header list size to {} for {}", local ? "decoder" : "encoder", value, this);
466466
if (local)
467+
{
467468
parser.getHpackDecoder().setMaxHeaderListSize(value);
469+
}
468470
else
469-
generator.getHpackEncoder().setMaxHeaderListSize(value);
471+
{
472+
HpackEncoder hpackEncoder = generator.getHpackEncoder();
473+
hpackEncoder.setMaxHeaderListSize(Math.min(value, hpackEncoder.getMaxHeaderListSize()));
474+
}
470475
}
471476
case SettingsFrame.ENABLE_CONNECT_PROTOCOL ->
472477
{

jetty-core/jetty-http2/jetty-http2-hpack/src/main/java/org/eclipse/jetty/http2/hpack/HpackEncoder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public int getMaxHeaderListSize()
156156

157157
public void setMaxHeaderListSize(int maxHeaderListSize)
158158
{
159-
_maxHeaderListSize = maxHeaderListSize;
159+
_maxHeaderListSize = maxHeaderListSize > 0 ? maxHeaderListSize : HpackContext.DEFAULT_MAX_HEADER_LIST_SIZE;
160160
}
161161

162162
public HpackContext getHpackContext()

jetty-core/jetty-http2/jetty-http2-tests/src/test/java/org/eclipse/jetty/http2/tests/SettingsTest.java

+36
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,42 @@ public void onGoAway(Session session, GoAwayFrame frame)
446446
assertTrue(goAwayLatch.await(5, TimeUnit.SECONDS));
447447
}
448448

449+
@Test
450+
public void testMaxHeaderListSizeCappedByClient() throws Exception
451+
{
452+
int maxHeadersSize = 2 * 1024;
453+
CountDownLatch goAwayLatch = new CountDownLatch(1);
454+
start(new ServerSessionListener()
455+
{
456+
@Override
457+
public Map<Integer, Integer> onPreface(Session session)
458+
{
459+
return Map.of(SettingsFrame.MAX_HEADER_LIST_SIZE, maxHeadersSize);
460+
}
461+
462+
@Override
463+
public void onGoAway(Session session, GoAwayFrame frame)
464+
{
465+
goAwayLatch.countDown();
466+
}
467+
});
468+
http2Client.setMaxRequestHeadersSize(maxHeadersSize / 2);
469+
470+
Session clientSession = newClientSession(new Session.Listener() {});
471+
HttpFields requestHeaders = HttpFields.build()
472+
.put("X-Large", "x".repeat(maxHeadersSize - 256)); // 256 bytes to account for the other headers
473+
MetaData.Request request = newRequest("GET", requestHeaders);
474+
HeadersFrame frame = new HeadersFrame(request, null, true);
475+
476+
Throwable failure = assertThrows(ExecutionException.class,
477+
() -> clientSession.newStream(frame, new Stream.Listener() {}).get(5, TimeUnit.SECONDS))
478+
.getCause();
479+
// The HPACK context is compromised trying to encode the large header.
480+
assertThat(failure, Matchers.instanceOf(HpackException.SessionException.class));
481+
482+
assertTrue(goAwayLatch.await(5, TimeUnit.SECONDS));
483+
}
484+
449485
@Test
450486
public void testMaxHeaderListSizeExceededByServer() throws Exception
451487
{

0 commit comments

Comments
 (0)