-
Notifications
You must be signed in to change notification settings - Fork 193
Comma's in cookie value #535
Comments
This is for |
Yes |
Moving this to Backlog as we will be in RC2 ask mode very soon. If you feel strongly about this issue, please ping me. |
Yes, this seems like an important issue to understand why it's happening and get fixed. |
Yep, looks like a bug. Though we are crammed on time and we will revisit backlog bugs after RC2. |
This bug is affecting my use of IdentityServer4 and presumably everyone else's too. Given Dominick Baier's blog post paragraph: "One year ago the ASP.NET team decided to discontinue that middleware and rather focus on consuming tokens instead. They also asked us if IdentityServer can be the replacement going forward." - this is needs fixing. |
@leastprivilege, can you elaborate on how this affects IdentiyServer? |
We put the client id the user has logged into into a cookie. This is used for single sign out. |
In a json format? or does the client id happen to contain a comma? |
We serailize to json and it's an array of strings. It's the exact same code in IdentityServer3 and that works under katana :) Basically, the APIs to add the cookie seem to automatically URL encode the value. In ASP.NET Core it's odd that the value is encoded, but there's a "," left in the middle. |
Here's a link with the sample text that's being put into the cookie: IdentityServer/IdentityServer3#2446 (comment) |
Right, so why is the default url encoder putting a comma in there? I can try to test it in better isolation. |
oh or are you showing that this was added recently? |
I was just citing the problematic line of code. |
hmm, ok. i'll see if i can repro in a stand alone project |
This program:
Emits this (notice the comma): The correct value should be: So it's a bug in the |
Commas are actually allowed in urls for some reason, so this is more of an issue that we're using an encoder that doesn't quite fit our needs. Adding an extra |
How did Katana do this? Perhaps there's precedent? |
|
The reason the Uri.Escape and Unescape are used is there was an attempt at sharing the ParseDelimited method between Query string, form values, and cookies. Except Cookies have no requirement to be encoded and in fact that breaks base64 for interop between normal frameworks. The real solution here is to remove the Uri.Escape and Unescape and + with ' ' replacement from cookies at all. A middleware could optionally do that if desired, but baking that requirement into the framework makes no sense. |
No, the reason there's encoding here is because people pass in arbitrary values without an knowledge of what's allowed in the spec and expect it to work. See the user's original (invalid) data input. |
Fixed via 765a520 |
Very happy -- thank you all! |
I've had an issue where I wanted to store a serialized json array in a cookie. This is not allowed anymore because of the comma that appears in the serialized representation (e.g. "["value 1","value 2"]").
Comma's are indeed not supported in cookies, but in the past (System.Web, Owin), these were always encoded and this does not seem to be the case anymore.
I wonder, should we encode and decode these values ourselves or should the framework do that automatically.
The text was updated successfully, but these errors were encountered: