From 8e03be9f2698f2da9027d40b9e9c0c9429b74dc0 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Thu, 25 Jan 2024 12:13:55 +0000 Subject: [PATCH] Report HTTP/2 header parsing errors earlier --- java/org/apache/coyote/http2/Http2Parser.java | 11 ++++++----- webapps/docs/changelog.xml | 5 +++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/java/org/apache/coyote/http2/Http2Parser.java b/java/org/apache/coyote/http2/Http2Parser.java index 5053a219bea0..c1f85422273e 100644 --- a/java/org/apache/coyote/http2/Http2Parser.java +++ b/java/org/apache/coyote/http2/Http2Parser.java @@ -283,6 +283,9 @@ protected void readHeadersFrame(int streamId, int flags, int payloadSize, ByteBu swallowPayload(streamId, FrameType.HEADERS.getId(), padLength, true, buffer); + // Validate the headers so far + hpackDecoder.getHeaderEmitter().validateHeaders(); + if (Flags.isEndOfHeaders(flags)) { onHeadersComplete(streamId); } else { @@ -446,6 +449,9 @@ protected void readContinuationFrame(int streamId, int flags, int payloadSize, B readHeaderPayload(streamId, payloadSize, buffer); + // Validate the headers so far + hpackDecoder.getHeaderEmitter().validateHeaders(); + if (endOfHeaders) { headersCurrentStream = -1; onHeadersComplete(streamId); @@ -637,11 +643,6 @@ protected void onHeadersComplete(int streamId) throws Http2Exception { Http2Error.COMPRESSION_ERROR); } - // Delay validation (and triggering any exception) until this point - // since all the headers still have to be read if a StreamException is - // going to be thrown. - hpackDecoder.getHeaderEmitter().validateHeaders(); - synchronized (output) { output.headersEnd(streamId, headersEndStream); diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 0aa6868e7083..f6cf372b9a31 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -171,6 +171,11 @@ Content-Type value to improve performance by reducing repeated byte[] to String conversions. (markt) + + Improve error reporting to HTTP/2 clients for header processing errors + by reporting problems at the end of the frame where the error was + detected rather than at the end of the headers. (markt) +