Skip to content

HTTP/3: Add unit test for MaxRequestLineSize limit #31963

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
2 commits merged into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ private bool TryValidatePseudoHeaders()
var requestLineLength = _methodText!.Length + Scheme!.Length + hostText.Length + path.Length;
if (requestLineLength > ServerOptions.Limits.MaxRequestLineSize)
{
Abort(new ConnectionAbortedException(CoreStrings.BadRequest_RequestLineTooLong), Http3ErrorCode.ProtocolError);
Abort(new ConnectionAbortedException(CoreStrings.BadRequest_RequestLineTooLong), Http3ErrorCode.RequestRejected);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Servers/Kestrel/Core/src/KestrelServerLimits.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public long? MaxRequestBufferSize
/// Defaults to 8,192 bytes (8 KB).
/// </summary>
/// <remarks>
/// For HTTP/2 this measures the total size of the required pseudo headers
/// For HTTP/2 and HTTP/3 this measures the total size of the required pseudo headers
/// :method, :scheme, :authority, and :path.
/// </remarks>
public int MaxRequestLineSize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,24 @@ await ExpectAsync(Http2FrameType.HEADERS,
await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);
}

[Fact]
public async Task HEADERS_Received_RequestLineLength_StreamError()
{
var headers = new[]
{
new KeyValuePair<string, string>(HeaderNames.Method, new string('A', 8192 / 2)),
new KeyValuePair<string, string>(HeaderNames.Path, "/" + new string('A', 8192 / 2)),
new KeyValuePair<string, string>(HeaderNames.Scheme, "http")
};

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

await WaitForStreamErrorAsync(1, Http2ErrorCode.PROTOCOL_ERROR, CoreStrings.BadRequest_RequestLineTooLong);

await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);
}

[Fact]
public async Task PRIORITY_Received_StreamIdZero_ConnectionError()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ public async Task MaxRequestLineSize_Reset()
var requestStream = await InitializeConnectionAndStreamsAsync(_noopApplication);
await requestStream.SendHeadersAsync(headers, endStream: true);

await requestStream.WaitForStreamErrorAsync(Http3ErrorCode.ProtocolError,
await requestStream.WaitForStreamErrorAsync(Http3ErrorCode.RequestRejected,
CoreStrings.BadRequest_RequestLineTooLong);
}

Expand Down Expand Up @@ -2358,5 +2358,18 @@ public async Task MaxRequestBodySize_AppCanRaiseLimit(bool includeContentLength)
Assert.Equal("200", receivedHeaders[HeaderNames.Status]);
Assert.Equal("0", receivedHeaders[HeaderNames.ContentLength]);
}

[Fact]
public Task HEADERS_Received_RequestLineLength_Error()
{
var headers = new[]
{
new KeyValuePair<string, string>(HeaderNames.Method, new string('A', 8192 / 2)),
new KeyValuePair<string, string>(HeaderNames.Path, "/" + new string('A', 8192 / 2)),
new KeyValuePair<string, string>(HeaderNames.Scheme, "http")
};

return HEADERS_Received_InvalidHeaderFields_StreamError(headers, CoreStrings.BadRequest_RequestLineTooLong, Http3ErrorCode.RequestRejected);
}
}
}