-
Notifications
You must be signed in to change notification settings - Fork 524
Cookies with non-ASCII causing all endpoints to give status code 400 #1076
Comments
The message is accurate, HTTP does not allow non-ascii in header values. Enforcement of this varies somewhat from server-to-server. For reference, what's the raw byte sequence on the wire in this case? ANSI? UTF-8? |
I have used Fiddler to get the raw http request
I'm not sure where to specific find the byte sequence with Fiddler, or if I should use Wireshark instead? |
Unfortunately there's no workaround for this as we expect headers to be ASCII like @Tratcher said. |
@RagingRudolf cant you base64 instead? |
@OzieGamma unfortunately not. I will figure out what we will do. My best guess right now is that we will convert danish characters into the ascii equivalents. I understand the reason for why you throw an exception but would it make sense to allow exactly that error "bubble up" as an error in the logs? I used quite some time to figure out why the server just gave an error 400 (and we have been using the IIS before without any problems). It's almost by accident I figured out that the error only showed up in with logging level "Information". |
The "information" level logging is a tough issue. Previously we have logged some bad requests using the "warning" or worse "error" log level. There we some complaints, since developers don't always have full control the clients sending the bad requests. We settled on the information level to avoid noisy logs. In fact, in 1.1, there won't even be the "Connection processing ended abnormally" warning logged due to this change. The more detailed BadHttpRequestException will still be logged as information, and only logged once. |
A cookie value is a http header value which RFC 7230 Field Value Components specifies:
With the allowed characters in the value (token) being
So non ascii characters in the cookie are invalid. The usual approach is to URL encode or Base64 encode the value when setting it and then decode it when retrieving it. |
What @benaadams said :) |
Hi everyone,
I'm working on a AspNetCore project and I have run into a odd problem.
When I send cookies to Kestrel where the value of a cookie contains "æ" (a danish character) then the request will return a status code 400 and never reach my controller (used debugger).
With debugging level "Error" nothing is printed to the Kestrel console but if I change debugging level to "Information" I get the following information exception messsage:
The main problem is that the project we are working on is original a .NET 4.5 project so we can't just use "ae" instead (The cookie is set with clientside tracking).
If you need some more information to reproduce this just let me know.
Best regards Martin
The text was updated successfully, but these errors were encountered: