Add an option to enable decoding null bytes from url encoded forms
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 276
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
While reading a form, there are [two code paths](https://github.com/dotnet/aspnetcore/blob/v10.0.0-preview.3.25172.1/src/Http/WebUtilities/src/FormPipeReader.cs#L392). One is active for UTF8 and ASCII, another is active for all other encodings. The former uses the `UrlDecoder` and that [throws](https://github.com/dotnet/aspnetcore/blob/v10.0.0-preview.3.25172.1/src/Shared/UrlDecoder/UrlDecoder.cs#L108) when it decodes a null byte (`%00`) from a form. The second path on the other hand treats the form as data url and accepts the null byte creating a string instance with a U+0000 code point.
### Describe the solution you'd like
I understand that [the RFC](https://www.rfc-editor.org/rfc/rfc3986#section-7.3) suggests not allowing null, but having the option in the first path to accept it anyways would certainly help.
### Additional context
As a workaround, it's possible to always force the second code path by registering an `EncodingProvider` and manipulating the request header to include a known charset value that maps to an instance of UTF8Encoding that isn't the `Encoding.UTF8` instance.
Contributor guide
Assessment
This issue has not been assessed yet.