-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Fix CookieHeaderParserShared throws exception when last cookie contains invalid character #45014 #45127
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
Conversation
….TryParseValues() method to prevent parsing strings wrong which contain separator characters. Reported by this issue: dotnet#45014
Thanks for your PR, @korteksz. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
I don't think this is the right aproach, it seems to have caused many cookie related failures in the SignalR tests. supportsMultipleValues means that a single header string might contain multiple cookies. That's fine, especially since it's common for cookie headers to be concatenated incorrectly. I think there's a lower issue where something is returning true but null, where it should be returning false. Probably here:
|
…erShared.TryParseValues() method to prevent parsing strings wrong which contain separator characters. Reported by this issue: dotnet#45014" This reverts commit a5ee158.
Can you please review and sign the CLA? #45127 (comment) |
@BrennanConroy @dnfadmin I have already signed the CLA from my mobile phone and when I try to do it from the desktop, then I got Edit |
@Tratcher Thanks for pointing this out. I assumed that this won't be the right solution. That changeset is revoked now and I've got a different one commited and the pipelines are green as well. The problem is that if you have a cookie like errorcookie=dd,:("sa; then it gets parsed currently like: |
Co-authored-by: Chris Ross <Tratcher@Outlook.com>
Co-authored-by: Chris Ross <Tratcher@Outlook.com>
This PR disappeared in the release .NET 7.0.1, please see CookieHeaderParserShared.cs#L29 |
Hi @cnblogs-dudu. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
/backport to release/7.0 |
Started backporting to release/7.0: https://github.com/dotnet/aspnetcore/actions/runs/3751657045 |
@Tratcher backporting to release/7.0 failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Remove supportsMultipleValues parameter from CookieHeaderParserShared.TryParseValues() method to prevent parsing strings wrong which contain separator characters. Reported by this issue: #45014
Using index info to reconstruct a base tree...
M src/Http/Http/src/Internal/RequestCookieCollection.cs
M src/Http/Http/test/RequestCookiesCollectionTests.cs
M src/Http/Shared/CookieHeaderParserShared.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Http/Shared/CookieHeaderParserShared.cs
CONFLICT (content): Merge conflict in src/Http/Shared/CookieHeaderParserShared.cs
Auto-merging src/Http/Http/test/RequestCookiesCollectionTests.cs
Auto-merging src/Http/Http/src/Internal/RequestCookieCollection.cs
CONFLICT (content): Merge conflict in src/Http/Http/src/Internal/RequestCookieCollection.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Remove supportsMultipleValues parameter from CookieHeaderParserShared.TryParseValues() method to prevent parsing strings wrong which contain separator characters. Reported by this issue: #45014
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@Tratcher an error occurred while backporting to release/7.0, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
I believe this pull request introduced a small breaking change. I did not test on this repo source directly but from my own code. Here is a repro: [Fact]
public void Repro()
{
var type = Type.GetType("Microsoft.Net.Http.Headers.CookieHeaderParserShared, Microsoft.Net.Http.Headers");
var method = type.GetMethod("TryParseValues", BindingFlags.Public | BindingFlags.Static);
var strValue = new StringValues("cookie1=123;cookie2="); // <- last cookie has no value
var dic = new Dictionary<string, string>();
method.Invoke(null, [strValue, dic, true]);
Assert.True(dic.Count == 2);
} This code passes in .NET 6 and .NET 7, but does not on .NET 8. I am not sure what the behaviour should be to match the W3C as close as possible but:
|
Comments on closed issues are not tracked, please open a new issue with the details for your scenario. |
Remove supportsMultipleValues parameter from CookieHeaderParserShared.TryParseValues() method to prevent parsing strings wrong which contain separator characters. Reported by this issue: #45014
Fix CookieHeaderParserShared throws exception when last cookie contains invalid character #45014
Summary of the changes (Less than 80 chars)
Description
Remove supportsMultipleValues parameter from CookieHeaderParserShared.TryParseValues() method to prevent parsing strings wrong (partly) which contain separator characters.
More details about the problem: #45014 (comment)
Fixes #45014