dotnet / dotnet/aspnetcore

Add an option to enable decoding null bytes from url encoded forms

Open
#61,968 0 comments 0 reactions 0 assignees View on GitHub
area-mvc
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.