-
Notifications
You must be signed in to change notification settings - Fork 17
Use TryAddWithoutValidation to prevent parsing potentially illegal headers #25
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
|
Sorry for the delay. |
|
I believe that |
|
I think that proper fix would entail implementing |
|
Thanks, Also - I don't recall any problem in my many tests so maybe the issue is limited to very special circumstances with specific server values that are uncommon - and not a common problem. At this point I have to ask myself whether the use case is too niche for me to spend time on, given that a perfect solution is not going to be easy. |
|
I believe that it's at least surprising that enabling support for compression in client breaks communication with servers that use documented header of "Expires: 0". Yes, REST API servers usually don't do that, but when downloading dynamically-generated content, it is quite common. As for the "lack of the validation" -- there is none in the first place in the current version of the code, it already skips validation of received headers. So the proposed change does not remove the validation that has any robustness or correctness value, it prevents accidental and unexpected breakage of already tested and working code when compression is enabled that is entirely dependent on the quirks of the server. |
|
You make a good case, I'll take another look. |
…vent parsing potentially illegal headers
|
I'm seeing that you also added dotnet/corefx#37391 - are you sure we must have both changes or none? why are those 2 in the same pull request? |
This is an example of my stupidity =) |
|
Thanks, and thanks for taking the time to explain. this change is included in v2.2.0.10 |
Hi!
Currently, when automatic decompression is used, the headers are copied between instances of
HttpContentto facilitate the decompression. Unfortunately, theHttpContentHeaders.Addmethod used inHttpContentHeadersExtensionsperforms header parsing, which tests whether the headers are valid. This leads to exceptions like "The format of value '0' is invalid." triggered by .NET Framework'sDateHeaderParserbeing too strict when parsing theExpires: 0header, while RFC 9111 explicitly mentions this:Also, this can lead to a misinterpretation of other header fields that do not perfectly roundtrip by a parse->convert step of
HttpContentHeaders.Add. I believe that decompression should not intervene into header processing and pass content headers as-is.To improve this, I propose using
HttpContentHeaders.TryAddWithoutValidationthat will copy the headers without any other processing. I'm not sure whether the result value should be checked and acted upon by, for example, throwing some kind of exception since this might defeat the original purpose.Thanks for looking into this.