I have an IdentityServer4 that when users have about 10 roles the cookie seems to grow exponentially. Everytime I try to log in now I get greeted with a 400 error request too long due to how large the cookie is.
The cookie I receive is split up to 5 chunks of around 4008 in size:
these cookies seem to be set on the signin-oidc endpoint of the application.
I am using the default cookie settings in identity server - no changes there.
Any ideas what could cause these cookies to grow so quickly? The size of the Id_token and Access_token seem to be substantially smaller than these cookies.
Edit: Each role I assign to the user in addition seems to add 400 size to the last cookie in the chunk which seems very large to me?
Edit 2: I am using a custom profile service would this impact the size of the final cookie:
public async Task GetProfileDataAsync(ProfileDataRequestContext context)
{
var subjectId = context.Subject.GetSubjectId();
var user = await _userManager.FindByIdAsync(subjectId);
if (user == null) return;
var claims = new List<Claim>
{
new Claim("username", user.UserName),
new Claim("email", user.Email),
new Claim("firstname", user.FirstName),
new Claim("lastname", user.LastName)
};
var roles = await _userManager.GetRolesAsync(user);
foreach (var role in roles)
{
claims.Add(new Claim("role", role));
}
var userClaims = await _userManager.GetClaimsAsync(user);
foreach (var userClaim in userClaims)
{
claims.Add(new Claim(userClaim.Type, userClaim.Value));
}
context.IssuedClaims = claims;
}