Make CRLF required by default for HTTP/1.x request lines, headers, and trailers#66807
Open
DeagleGross wants to merge 2 commits into
Open
Make CRLF required by default for HTTP/1.x request lines, headers, and trailers#66807DeagleGross wants to merge 2 commits into
DeagleGross wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR changes Kestrel’s HTTP/1.x parsing behavior to require CRLF line terminators by default (aligning with RFC 9112), while preserving an AppContext switch to restore the legacy behavior that accepts bare LF terminators.
Changes:
- Flip the default value of
Microsoft.AspNetCore.Server.Kestrel.DisableHttp1LineFeedTerminatorsso CRLF-only is the default when the switch is not set. - Update
HttpParser’s public constructor to match the new default and document how to restore LF-accepting behavior. - Add tests validating default/switch-driven behavior using isolated remote execution.
Show a summary per file
| File | Description |
|---|---|
| src/Servers/Kestrel/Core/test/HttpParserTests.cs | Adds RemoteExecutor-based tests for default/switch behavior around LF vs CRLF header terminators. |
| src/Servers/Kestrel/Core/src/KestrelServerOptions.cs | Changes the switch default logic (unset => CRLF required) and updates inline documentation to reflect .NET 11 behavior. |
| src/Servers/Kestrel/Core/src/Internal/Http/HttpParser.cs | Updates the public ctor default behavior and adds remarks documenting the new default and opt-out switch. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/Servers/Kestrel/Core/test/HttpParserTests.cs:1019
- Same as above: use KestrelServerOptions.DisableHttp1LineFeedTerminatorsSwitchKey instead of duplicating the AppContext switch key string literal.
using var remoteHandle = RemoteExecutor.Invoke(static () =>
{
AppContext.SetSwitch("Microsoft.AspNetCore.Server.Kestrel.DisableHttp1LineFeedTerminators", false);
var parser = new HttpParser<RequestHandler>(showErrorDetails: true);
var buffer = new ReadOnlySequence<byte>(Encoding.ASCII.GetBytes("a:b\n\r\n"));
- Files reviewed: 3/3 changed files
- Comments generated: 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a behavioral change, but users will still be able to configure the server behavior to their desire. Per RFC CRLF is sequence of characters included in the grammar, and there is a note that LF MAY recognize a single LF:
Closes #66724