📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

A user changes their password or an admin disables their account. How do you make existing authentication cookies stop working straight away?

Junior Theory Beginner

🎯 Key points

  • Self-contained cookie valid until expiry
  • OnValidatePrincipal for custom per-request checks with RejectPrincipal and SignOutAsync
  • SecurityStampValidator compares the stamp every ValidationInterval (30 min default)
  • Update the stamp on password, MFA change and admin disable
  • SessionStore (ITicketStore) server-side tickets for instant revocation

⏱ 30-second answer

A self-contained cookie stays valid until it expires, so you add a server-side check. CookieAuthenticationEvents.OnValidatePrincipal runs on every authenticated request and is where custom checks go: look up the user (cached) and call context.RejectPrincipal() plus SignOutAsync if they are disabled or their session was revoked. ASP.NET Core Identity's SecurityStampValidator plugs into that event: every ValidationInterval (30 minutes by default; lower it for sensitive apps) it compares the cookie's security stamp with the database and rejects the cookie if the stamp changed. Identity changes the stamp on password, MFA and email changes; call UpdateSecurityStampAsync when an admin disables a user. For truly immediate revocation, set CookieAuthenticationOptions.SessionStore to an ITicketStore backed by a distributed cache: the cookie then holds only a session key, and deleting the server-side entry ends the session on the next request.

🔍 What the interviewer is checking

Checks they understand revocation of bearer credentials

↩ Usually asked after

More in Authentication

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me