Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PR feedback
  • Loading branch information
Tratcher authored and github-actions committed Oct 27, 2022
commit ef8b59bcb13e0a63abfa410cb76ad070ea40c48f
Original file line number Diff line number Diff line change
Expand Up @@ -1412,7 +1412,8 @@ private void OnHeaderCore(HeaderType headerType, int? staticTableIndex, ReadOnly

// https://tools.ietf.org/html/rfc7540#section-6.5.2
// "The value is based on the uncompressed size of header fields, including the length of the name and value in octets plus an overhead of 32 octets for each header field.";
_totalParsedHeaderSize += HeaderField.RfcOverhead + name.Length + value.Length;
// We don't include the 32 byte overhead hear so we can accept a little more than the advertised limit.
_totalParsedHeaderSize += name.Length + value.Length;
// Allow a 2x grace before aborting the connection. We'll check the size limit again later where we can send a 431.
if (_totalParsedHeaderSize > _context.ServiceContext.ServerOptions.Limits.MaxRequestHeadersTotalSize * 2)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Servers/Kestrel/Core/src/Internal/Http2/Http2Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ protected override bool TryParseRequest(ReadResult result, out bool endConnectio
endConnection = !TryValidatePseudoHeaders();

// 431 if the headers are too large
if (TotalParsedHeaderSize > _context.ServiceContext.ServerOptions.Limits.MaxRequestHeadersTotalSize)
if (TotalParsedHeaderSize > ServerOptions.Limits.MaxRequestHeadersTotalSize)
{
KestrelBadHttpRequestException.Throw(RequestRejectionReason.HeadersExceedMaxTotalSize);
}
Expand Down
9 changes: 5 additions & 4 deletions src/Servers/Kestrel/Core/src/Internal/Http3/Http3Stream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,12 @@ private void AppendHeader(ReadOnlySpan<byte> name, ReadOnlySpan<byte> value)

private void OnHeaderCore(HeaderType headerType, int? staticTableIndex, ReadOnlySpan<byte> name, ReadOnlySpan<byte> value)
{
// https://tools.ietf.org/html/rfc7540#section-6.5.2
// https://httpwg.org/specs/rfc9114.html#rfc.section.4.2.2
// "The value is based on the uncompressed size of header fields, including the length of the name and value in octets plus an overhead of 32 octets for each header field.";
_totalParsedHeaderSize += HeaderField.RfcOverhead + name.Length + value.Length;
// We don't include the 32 byte overhead hear so we can accept a little more than the advertised limit.
_totalParsedHeaderSize += name.Length + value.Length;
// Allow a 2x grace before aborting the stream. We'll check the size limit again later where we can send a 431.
if (_totalParsedHeaderSize > _context.ServiceContext.ServerOptions.Limits.MaxRequestHeadersTotalSize * 2)
if (_totalParsedHeaderSize > ServerOptions.Limits.MaxRequestHeadersTotalSize * 2)
{
throw new Http3StreamErrorException(CoreStrings.BadRequest_HeadersExceedMaxTotalSize, Http3ErrorCode.RequestRejected);
}
Expand Down Expand Up @@ -952,7 +953,7 @@ protected override bool TryParseRequest(ReadResult result, out bool endConnectio
endConnection = !TryValidatePseudoHeaders();

// 431 if the headers are too large
if (_totalParsedHeaderSize > _context.ServiceContext.ServerOptions.Limits.MaxRequestHeadersTotalSize)
if (_totalParsedHeaderSize > ServerOptions.Limits.MaxRequestHeadersTotalSize)
{
KestrelBadHttpRequestException.Throw(RequestRejectionReason.HeadersExceedMaxTotalSize);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ public async Task HEADERS_Received_MaxRequestHeadersTotalSize_431()
new KeyValuePair<string, string>("g", _4kHeaderValue),
new KeyValuePair<string, string>("h", _4kHeaderValue),
};
await InitializeConnectionAsync(_noopApplication);
await InitializeConnectionAsync(_notImplementedApp);

await StartStreamAsync(1, headers, endStream: true);

Expand Down Expand Up @@ -850,7 +850,7 @@ public async Task HEADERS_Received_MaxRequestHeaderCount_431()
var text = i.ToString(CultureInfo.InvariantCulture);
headers.Add(new KeyValuePair<string, string>(text, text));
}
await InitializeConnectionAsync(_noopApplication);
await InitializeConnectionAsync(_notImplementedApp);

await StartStreamAsync(1, headers, endStream: true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ protected static IEnumerable<KeyValuePair<string, string>> ReadRateRequestHeader
protected readonly TaskCompletionSource _closedStateReached = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

protected readonly RequestDelegate _noopApplication;
protected readonly RequestDelegate _notImplementedApp;
protected readonly RequestDelegate _readHeadersApplication;
protected readonly RequestDelegate _readTrailersApplication;
protected readonly RequestDelegate _bufferingApplication;
Expand Down Expand Up @@ -176,6 +177,7 @@ public Http2TestBase()
});

_noopApplication = context => Task.CompletedTask;
_notImplementedApp = _ => throw new NotImplementedException();

_readHeadersApplication = context =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ public async Task HEADERS_Received_HeaderBlockOverLimit_431()
new KeyValuePair<string, string>("h", _4kHeaderValue),
};

var requestStream = await Http3Api.InitializeConnectionAndStreamsAsync(_noopApplication, headers, endStream: true);
var requestStream = await Http3Api.InitializeConnectionAndStreamsAsync(_notImplementedApp, headers, endStream: true);

var receivedHeaders = await requestStream.ExpectHeadersAsync();

Expand Down Expand Up @@ -2376,7 +2376,7 @@ public async Task HEADERS_Received_TooManyHeaders_431()
headers.Add(new KeyValuePair<string, string>(i.ToString(CultureInfo.InvariantCulture), i.ToString(CultureInfo.InvariantCulture)));
}

var requestStream = await Http3Api.InitializeConnectionAndStreamsAsync(_noopApplication, headers, endStream: true);
var requestStream = await Http3Api.InitializeConnectionAndStreamsAsync(_notImplementedApp, headers, endStream: true);

var receivedHeaders = await requestStream.ExpectHeadersAsync();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public abstract class Http3TestBase : TestApplicationErrorLoggerLoggedTest, IDis
internal readonly Mock<ITimeoutHandler> _mockTimeoutHandler = new Mock<ITimeoutHandler>();

protected readonly RequestDelegate _noopApplication;
protected readonly RequestDelegate _notImplementedApp;
protected readonly RequestDelegate _echoApplication;
protected readonly RequestDelegate _readRateApplication;
protected readonly RequestDelegate _echoMethod;
Expand Down Expand Up @@ -79,6 +80,7 @@ protected static IEnumerable<KeyValuePair<string, string>> ReadRateRequestHeader
public Http3TestBase()
{
_noopApplication = context => Task.CompletedTask;
_notImplementedApp = _ => throw new NotImplementedException();

_echoApplication = async context =>
{
Expand Down