-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Need Urgent fix for CookieHeaderParserShared throws exception when last cookie contains invalid character in .NET7 #45665
Comments
CC: @cnblogs-dudu |
This null checking is still present in.NET 6. |
We found many cookies with
|
We have applied the following workaround in the dedicated middleware. public class CheckCookiesMiddleware
{
private readonly RequestDelegate _next;
public CheckCookiesMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext httpContext)
{
try
{
var cookies = httpContext.Request.Cookies;
}
catch (Exception ex) when (ex.Message.Contains("Nullable object must have a value"))
{
var logger = httpContext.RequestServices.GetRequiredService<ILogger<CheckCookiesMiddleware>>();
var cookies = httpContext.Request.Headers[HeaderNames.Cookie];
logger.LogInformation("Removing invalid Cookies: \n{cookies}", cookies);
httpContext.Request.Headers[HeaderNames.Cookie] = string.Empty;
}
await _next(httpContext);
}
} |
@cnblogs-dudu In my case, it is exactly the same. :) |
Moving the discussion from #45014 Noisy error logs are not sufficient justification for a patch. There needs to be a functional business impact. A) What impact is this having on your business? It should be possible to work around this by checking the cookie header first for known invalid data and removing it or terminating the request. |
@Tratcher
It should be possible to work around this by checking the cookie header first for known invalid data and removing it or terminating the request. IMO,Our code is web gateway If we use a cookie sanitizer, our performance may suffer |
@Tratcher I believe it would be beneficial if you could restore this code. |
@davidfowl @Tratcher FYI. |
@Tratcher if this is common, we might want to revert this change. I’m thinking about the YARP scenario and people using ASP.NET Core as a gateway |
@kchinburarat good find, I hadn't realized this was a regression. That does qualify for a patch then. I'll get it started. |
Is there an existing issue for this?
Describe the bug
#45127 related to this issue
Fix CookieHeaderParserShared throws exception when last cookie contains invalid character
and this #45014
I confirm that there is an issue in NET 7 and that the Asp.net core code has to be fixed. We cannot wait for the release of NET 8.
Expected Behavior
CookieHeaderParserShared.CookieHeaderParserShared Shoul not return true from this line
https://github.com/dotnet/aspnetcore/blob/v7.0.1/src/Http/Shared/CookieHeaderParserShared.cs#L75
because it will make this code thrown the exception
Steps To Reproduce
Change ParseManyCookies unit test to below code
Exceptions (if any)
unit test : https://github.com/dotnet/aspnetcore/blob/v7.0.1/src/Http/Http/test/RequestCookiesCollectionTests.cs#L43
.NET Version
7.0
Anything else?
No response
The text was updated successfully, but these errors were encountered: