Skip to content

Commit

Permalink
Report HTTP/2 header parsing errors earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Feb 12, 2024
1 parent 2178bf6 commit 8e03be9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 6 additions & 5 deletions java/org/apache/coyote/http2/Http2Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down
5 changes: 5 additions & 0 deletions webapps/docs/changelog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@
<code>Content-Type</code> value to improve performance by reducing
repeated <code>byte[]</code> to <code>String</code> conversions. (markt)
</fix>
<fix>
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)
</fix>
</changelog>
</subsection>
<subsection name="Jasper">
Expand Down

0 comments on commit 8e03be9

Please sign in to comment.