Skip to content

Commit

Permalink
[UNDERTOW-2281] At Http2FrameHeaderParser, throw a protocol error whe…
Browse files Browse the repository at this point in the history
…n END_STREAM is absent only when:request does not contain Expect:100-continue header; or response contains a positive content-length indicating the presence of a content.

Signed-off-by: Flavia Rainone <[email protected]>
  • Loading branch information
fl4via committed Jun 27, 2023
1 parent 212e6e4 commit b7454f9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import static io.undertow.protocols.http2.Http2Channel.HEADERS_FLAG_END_HEADERS;
import static org.xnio.Bits.allAreClear;
import static org.xnio.Bits.allAreSet;
import static org.xnio.Bits.anyAreClear;
import static org.xnio.Bits.anyAreSet;

/**
Expand Down Expand Up @@ -233,6 +234,11 @@ int getActualLength() {
} else if(type == FRAME_TYPE_HEADERS) {
final Http2StreamSourceChannel channel = http2Channel.getIncomingStream(streamId);
if(channel != null) {
if(anyAreClear(flags, Http2Channel.HEADERS_FLAG_END_STREAM) && !((Http2HeadersParser) parser).isContentExpected()) {
//this is a protocol error
io.undertow.UndertowLogger.REQUEST_IO_LOGGER.debug("Received HTTP/2 trailers header without end stream set");
http2Channel.sendGoAway(Http2Channel.ERROR_PROTOCOL_ERROR);
}
if (!channel.isHeadersEndStream() && allAreSet(flags, Http2Channel.HEADERS_FLAG_END_HEADERS | Http2Channel.HEADERS_FLAG_END_STREAM)) {
http2Channel.removeStreamSource(streamId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.HashSet;
import java.util.Set;

import io.undertow.server.protocol.http.HttpContinue;
import org.xnio.Bits;
import io.undertow.UndertowLogger;

Expand Down Expand Up @@ -138,6 +139,18 @@ HeaderMap getHeaderMap() {
return headerMap;
}

boolean isContentExpected() {
if (HttpContinue.requiresContinueResponse(headerMap)) {
return true;
}
String contentLengthString = headerMap.getFirst(Headers.CONTENT_LENGTH);
try {
return contentLengthString != null ? Long.parseLong(contentLengthString) > 0 : false;
} catch (NumberFormatException e) {
return false;
}
}

@Override
public void emitHeader(HttpString name, String value, boolean neverIndex) throws HpackException {
if(maxHeaderListSize > 0) {
Expand Down

0 comments on commit b7454f9

Please sign in to comment.