Security

Shrinking the ASP.NET Core auth cookie with ITicketStore

Cookie authentication in ASP.NET Core serializes the whole AuthenticationTicket into the cookie, so large claim sets can push it past WAF limits. Implementing ITicketStore keeps the ticket on the server and leaves only a session key in the cookie. The article compares an in-memory store with a distributed cache version and discusses the scaling and revocation trade-offs.

Published
Reading time
4 min read
agent run #8
agent run #8
Go to original bartwullems.blogspot.com

Report this story

Is something wrong with the summary, or do you own this content? Your message comes straight to my inbox.

Type of message

Key points

  • ITicketStore has four methods: StoreAsync, RenewAsync, RetrieveAsync and RemoveAsync.
  • The store is attached via CookieAuthenticationOptions.SessionStore, resolved from DI with an options Configure call.
  • An in-memory store works only on a single instance and signs everyone out on restart.
  • For scaled-out apps, IDistributedCache with TicketSerializer.Default keeps tickets in a shared cache such as Redis.
  • Server-side tickets allow revoking sessions by removing the key, at the cost of a lookup per request.

A team testing a new WAF saw requests blocked before reaching their servers. The culprit was cookie size: by default, ASP.NET Core cookie authentication packs the whole ticket, claims included, into the cookie, so richer identities mean bigger cookies.

ITicketStore, set through CookieAuthenticationOptions.SessionStore, offers the fix: the ticket stays on the server and the cookie holds only a key. It starts with an IMemoryCache version, which fails across multiple instances and loses sessions on restart, then moves to a distributed cache using TicketSerializer. That cache now holds user claims and tokens, so it needs restricted access and encryption. Each request then needs a lookup, but sessions can be revoked by deleting their key.

Real-world use

  • An enterprise app with many roles and claims must keep its cookie under a WAF size limit.
  • A web app running on several Azure Container Apps replicas shares sessions through Redis.
  • An internal portal where admins must be able to end a user's session immediately.

Why it matters

If your cookies grow with claims or saved tokens, moving the ticket server-side keeps them small and makes sessions revocable. The cost is a cache that every request and every sign-in depends on.

This summary was generated by the agent from the original post on Bart Wullems (The Art of Simplicity). The full text and all rights belong to its author and publisher. Go to original

Related stories

Feedback

Found a bug or have an idea? Your message lands straight in my inbox.

Type of message