Skip to content

Kestrel's ParseHeaders throws an ArgumentOutOfRange exception on certain headers #61245

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

Closed
1 task done
WereWind1 opened this issue Mar 31, 2025 · 4 comments · Fixed by #61316
Closed
1 task done

Kestrel's ParseHeaders throws an ArgumentOutOfRange exception on certain headers #61245

WereWind1 opened this issue Mar 31, 2025 · 4 comments · Fixed by #61316
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-kestrel help wanted Up for grabs. We would accept a PR to help resolve this issue
Milestone

Comments

@WereWind1
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I have been fuzzing some of the Kestrel methods and ran into a part where in crashes on certain multi-span headers. The issue seems to be in the fact that on multispan headers where one section ends with cr kestrel tries to see if there is data after cr inside the whole header (there is) and then when it rejects the header it tries to grab extra data from the specific span it inspects (and there is no data) so it throws

Expected Behavior

ParseHeaders module cleanly rejects the problematic header without exceptions

Steps To Reproduce

https://github.com/WereWind1/KestrelHttpParserExceptionMinimal

Exceptions (if any)

ArgumentOutOfRange

.NET Version

6.0.36 8.0.14 9.0.3

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Mar 31, 2025
@BrennanConroy
Copy link
Member

Looks like

// Include the thing after the CR in the rejection exception.
var stopIndex = crIndex + 2;
RejectRequestHeader(span[..stopIndex]);
assumes the data was in a single span.

Would you be interested in contributing a fix?
We'd also want to improve test coverage, new test likely would go in https://github.com/dotnet/aspnetcore/blob/main/src/Servers/Kestrel/Core/test/HttpParserTests.cs

@WereWind1
Copy link
Contributor Author

Yes, I would like to do so. I just have a question if I can submit the fix into the 6.0 version as well as in the later ones? I can't seem to find the branch for this one

@BrennanConroy
Copy link
Member

6.0 is out of support, so definitely no.

@BrennanConroy BrennanConroy added the help wanted Up for grabs. We would accept a PR to help resolve this issue label Apr 3, 2025
Copy link
Contributor

Looks like this issue has been identified as a candidate for community contribution. If you're considering sending a PR for this issue, look for the Summary Comment link in the issue description. That comment has been left by an engineer on our team to help you get started with handling this issue. You can learn more about our Help Wanted process here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions feature-kestrel help wanted Up for grabs. We would accept a PR to help resolve this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants