-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I want to echo this Open issue:
#53048
DuendeArchive/Support#1044
as we might experience the same
Also posted on Microsoft Stackoverflow:
https://stackoverflow.microsoft.com/questions/431264
Expected Behavior
Those correlation cookie/nonce cookie should disappear after login and not accumulating in browser
Steps To Reproduce
TL,DR:
When Cookie Timeout, we can not delete the
.AspNetCore.Correlation.xxx and .AspNetCore.OpenIdConnect.Nonce.xxx cookies
(Correlation cookie and Nonce cookie)
1st login (successful):
just 3 cookies:
Then, we could modify the value to be expired (or just simply delete this cookie) - to simulate Customer having idle browser activity overnight. And next day when Customer clicked/refreshed the webpage, they will have issues with: 400 Bad Request Request Header Or Cookie Too Large
To simulate/reproduce, we could edit this AspNet Cookie to be an expired timestamp or simply delete the AspNet cookie
Then, refresh the page, login still successful, but there are extra 2 cookies:
Note: these nonce cookie and correlation cookie just add another 15mins(see Expire/Max-Age) to Last Accessed Timestamp
correlation/nonce cookie will accumulate each time you delete the one liner .ASP NET cookie and then refresh/click the page
And Eventually the nonce/correlation cookie accummulated and resulted in 400 Bad Request Request Header Or Cookie Too Large
Code:
services.Configure<CookieAuthenticationOptions>(CookieAuthenticationDefaults.AuthenticationScheme, options =>
{
options.Cookie.Domain = Configuration.GetValue<string>("App:CookieDomain");
options.Cookie.HttpOnly = true;
options.SlidingExpiration = true;
options.ExpireTimeSpan = TimeSpan.FromHours(1);
options.Cookie.MaxAge = TimeSpan.FromHours(8);
options.EventsType = typeof(CookieEventHandler); // custom cookie event handler to implement back-channel logout
// options.DataProtectionProvider = DataProtectionProvider.Create(Constants.DataProtectionServiceName); // Include DataProtectionProvider
options.Events.OnSigningOut = async context =>
{
// Delete the OIDC Nonce cookies
foreach (var cookie in context.HttpContext.Request.Cookies)
{
if (cookie.Key.StartsWith(".AspNetCore.OpenIdConnect.Nonce."))
{
context.HttpContext.Response.Cookies.Delete(cookie.Key);
}
// Delete the Correlation cookies
if (cookie.Key.StartsWith(".AspNetCore.Correlation."))
{
context.HttpContext.Response.Cookies.Delete(cookie.Key);
}
}
await Task.CompletedTask;
};
});
options.Events.OnRemoteFailure += context =>
{
if (context.Request.Cookies.Count > 3)
{
var cookies = context.Request.Cookies.Where(c => c.Key.StartsWith(".AspNetCore.OpenIdConnect.Nonce"));
var keyValuePairs = cookies as KeyValuePair<string, string>[] ?? cookies.ToArray();
foreach (var cookie in keyValuePairs)
{
context.Response.Cookies.Delete(cookie.Key);
}
context.Response.Redirect("/");
context.HandleResponse();
return Task.CompletedTask;
}
return Task.CompletedTask;
};
Reference:
I believe this issue is similar to:
Exceptions (if any)
No response
.NET Version
8.0.403