-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Add general property bag to cookies to support potential new cookie "standards" #39968
Comments
Design point: both |
Thanks for contacting us. We're moving this issue to the |
@adityamandaleeka weve been asked by a couple of internal teams to make this available, rather than it just being me planning. Please assign to a milestone coming soon so it doesn't get lost and adjust priority upwards as you see fit. |
A contributor added SetCookieHeaderValue.Extensions back in 5.0 that should work for this. This covers the lowest layer that parses and serializes cookies. The next layer up that we need to add this to is CookieOptions and then CookieBuilder: These two APIs are used most places we work with cookies, like HttpResponse.Cookies.Append and CookieAuthenticationOptions, so we shouldn't have to do much additional work to expose it on individual components. |
Proposed APInamespace Microsoft.AspNetCore.Http;
public class CookieOptions
{
+ public CookieOptions(CookieOptions options); // Copy constructor, avoids manual copying when needing to change something.
+ public IList<string> Extensions { get; };
+ public SetCookieHeaderValue CreateCookie(string name, string value); // Factory, avoids manual copying when creating the header
}
public class CookieBuilder
{
+ public IList<string> Extensions { get; };
} Usage ExampleshttpContext.Response.Cookies.Append(testCookie, "value", new CookieOptions()
{
Extensions = { "simple", "key=value" }
});
var sharedOptions = new CookieOptions() { Secure = true };
httpContext.Response.Cookies.Append(testCookie, "value", new CookieOptions(sharedOptions)
{
Extensions = { "simple", "key=value" }
}); services.AddAuthentication().AddCookie(o =>
{
o.Cookie.Extensions.Add("extension");
}); |
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
API review notes:
namespace Microsoft.AspNetCore.Http;
public class CookieOptions
{
+ public CookieOptions(CookieOptions options); // Copy constructor, avoids manual copying when needing to change something.
+ public IList<string> Extensions { get; };
+ public SetCookieHeaderValue CreateCookieHeader(string name, string value); // Factory, avoids manual copying when creating the header
}
public class CookieBuilder
{
+ public IList<string> Extensions { get; };
} API approved! |
Problem
Google in their quest to remove third party cookies are proposing moving to yet another cookie standard.
It's both better than, and worse than the same site changes we had to go through before to keep oauth's lights on for IdPs that couldn't support more modern flows.
The CHIPS proposal adds new attributes to cookies, and as we've traditionally had strong properties on cookies any new cookie property needs a lot of work to support, and we end up having a slow reaction.
Potential solution
I propose a general property bag of names and values (with values allowing for NULL) for outbound cookie properties, which would allow customers to be more flexible in what gets added as a cookie property and not have to wait for us to push new code to test out a standard which may, or may not get ratified.
Of course the property bag would have to nicely sync with the existing "strong" properties.
The text was updated successfully, but these errors were encountered: