最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

What is the content of the ASP.NET Core Identity authentication cookie? - Stack Overflow

programmeradmin3浏览0评论

I've implemented ASP.NET Core Identity for authentication in my application, and during the login process, an authentication cookie is created in the user's browser. The value of this cookie appears to be encrypted, which makes it difficult to inspect directly.

What exactly is stored in this cookie apart from the claims (such as user information and roles)?

Are there any documented cases or known methods where someone has been able to decode or extract the full content of this authentication cookie created by ASP.NET Identity in the browser?

I understand that the value is encrypted, but what components can be inferred or extracted, if any, in a typical implementation?

Additionally, is there any specific structure or data other than Claims that is stored in this cookie (e.g., expiration date, issued time, etc.)?

I've implemented ASP.NET Core Identity for authentication in my application, and during the login process, an authentication cookie is created in the user's browser. The value of this cookie appears to be encrypted, which makes it difficult to inspect directly.

What exactly is stored in this cookie apart from the claims (such as user information and roles)?

Are there any documented cases or known methods where someone has been able to decode or extract the full content of this authentication cookie created by ASP.NET Identity in the browser?

I understand that the value is encrypted, but what components can be inferred or extracted, if any, in a typical implementation?

Additionally, is there any specific structure or data other than Claims that is stored in this cookie (e.g., expiration date, issued time, etc.)?

Share Improve this question edited Feb 17 at 21:10 marc_s 755k184 gold badges1.4k silver badges1.5k bronze badges asked Feb 17 at 19:05 SadeghSadegh 93 bronze badges New contributor Sadegh is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 1
  • 1 Fortunately ASP.NET Core Identity is open source, so you can browse it yourself and see exactly how it's implemented. – mason Commented Feb 17 at 21:53
Add a comment  | 

1 Answer 1

Reset to default 0

You could only decrypt the cookie in the server machine because of the protection key. After login, switching to this "privacy" page would log the cookie content. (expiration date, issued time are included).

public IActionResult Privacy()
{
    var cookie = Request.Cookies[".AspNetCore.Identity.Application"];
    var dataProtector = HttpContext.RequestServices
        .GetRequiredService<IDataProtectionProvider>()
        .CreateProtector("Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware", "Identity.Application", "v2"); 
            
    byte[] protectedData = Base64UrlTextEncoder.Decode(cookie);
    byte[] unprotectedData = dataProtector.Unprotect(protectedData);

    string decryptedText = Encoding.UTF8.GetString(unprotectedData);
    Console.WriteLine("Decrypted Cookie Data:");
    Console.WriteLine(decryptedText);
    return View();
}
发布评论

评论列表(0)

  1. 暂无评论