Repository navigation
Improve CRLF / LF line terminators observability in HTTP/1.x request - #66807
Merged
Merged
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
halter73
approved these changes
May 26, 2026
cincuranet
approved these changes
Jun 1, 2026
Open
3 tasks
Member
Author
|
Lets see if we agree on the metric name before merging: #66724 (comment) UPD: it was approved |
…and logging Roll back the strict-by-default flip so HTTP/1.x bare LF terminators are accepted by default again; strict mode remains opt-in via the DisableHttp1LineFeedTerminators AppContext switch. Add network.protocol.name/version tags to the kestrel.bare_line_feed_requests metric and a Debug-level Http1BareLineFeedTerminator log so operators can measure and identify bare-LF traffic before opting in. Co-authored-by: Copilot <[email protected]>
Member
Author
|
Tried locally, metric and log looks like this: |
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.
HTTP/1.1 (RFC 9112 §2.2) requires
CRLFas the line terminator but permits recipients to accept a bareLF. Kestrel has historically accepted bareLFfrom NET7 (#43228). This PR improves observability for CRLF/LF introducing a metric & log.How to use it
Measure bare-LF volume while in the default (permissive) mode:
Once you decide to enforce strict mode, set the switch and watch the rejected split:
Closes #66724