Kestrel should disallow trailers cited in rfc7230 section 4.1.2
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
Origin: https://stackoverflow.com/q/76780323/23354
Cross-reference relevant http.sys code: https://github.com/dotnet/aspnetcore/blob/main/src/Shared/HttpSys/RequestProcessing/HeaderCollection.cs#L21
Currently it appears that Kestrel can be coerced into adding H2 trailers that violate [RFC 7230 section 4.1.2](https://datatracker.ietf.org/doc/html/rfc7230#section-4.1.2), which states:
> A sender MUST NOT generate a trailer that contains a field necessary
> for message framing (e.g., Transfer-Encoding and Content-Length),
> routing (e.g., Host), request modifiers (e.g., controls and
> conditionals in [Section 5 of [RFC7231]](https://datatracker.ietf.org/doc/html/rfc7231#section-5)), authentication (e.g., see
> [[RFC7235](https://datatracker.ietf.org/doc/html/rfc7235)] and [[RFC6265](https://datatracker.ietf.org/doc/html/rfc6265)]),
response control data (e.g., see [Section](https://datatracker.ietf.org/doc/html/rfc7231#section-7.1)
> [7.1 of [RFC7231]](https://datatracker.ietf.org/doc/html/rfc7231#section-7.1)), or determining how to process the payload (e.g.,
> Content-Encoding, Content-Type, Content-Range, and Trailer).
This may or may not be limited to gRPC scenarios.
### Expected Behavior
An exception should be generated, to be consistent with the IIS/http.sys implementation
### Steps To Reproduce
From linked gRPC question (may also be possible without gRPC, to be investigated):
``` csharp
public override async Task ProduceBadTrailer(ProduceBadTrailerRequest request)
{
var status = new Status(StatusCode.Unauthenticated, "throwing on purpose");
var trailers = new Metadata() { new Metadata.Entry("www-authenticate", "auth failed on purpose") };
await Task.CompletedTask;
throw new RpcException(status, trailers);
}
```
### Exceptions (if any)
_No response_
### .NET Version
_No response_
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.