What is the "best practice" to prevent a valid cookie from being used by more than one client at a time in ASP.NET MVC?
In this scenario, we are using all the OWASP tricks.
- Strict HSTS: HTTPS/SSL on every page
- Cookies are listed as HTTPS-only
- Cookies are marked secure
- Cookies have a short expiration
- There is also code to prevent cross-site request forgery (XSRF) from altering values page to page.
That's all great and prevents users from changing values, but it doesn't prevent a bad actor from stealing the entire cookie and re-using it elsewhere while it is still valid ("cookie replay," or "session fixation," depending on who you ask). As far as I can tell, there is no standard .NET configuration or boilerplate to prevent this.
For example, User A logs in and their auth cookie is good for t minutes. Malware on that user's PC ignores the HTTP-only/secure setting on the cookie and is able to retrieve the actual stored cookie, sending it to our bad actor. The bad actor is then able use a cookie-editing tool to add it to their browser and connect to the site as User A, until the cookie expires or User A signs out (invalidating the session).
Ideally, can .NET be configured so that a session is invalidated if the cookie is found to be in use from two clients at the same time?
Similar items reviewed:
Oh, S.O. community, we know how much you love "duplicates."
- Asp.net - Using SSL to prevent cookie replay attack: SSL does not prevent cookie replay, only mid-transmission tampering.
- Prevent re-use of authentication cookie in ASP.NET: Specific to cookie use after user-logout; here, the user is still logged in while the bad actor has access.
- ASP.NET cookie replay fix without storing auth-token in server?: Specifically requests not storing tokens on the server, I won't rule that out as an answer
External fix suggestions:
- This page suggests setting a
boolvalue server-side when the user logs in. Wrong-- that would only prevent the bad actor from using the cookie after the intended user logs out. It does nothing to prevent the bad actor from poking around at the same time as the intended user. - This page on StackExchange takes the same approach, setting a session value. It suffers the same problem.
- Even Troy Hunt's oft-cited OWASP top 10 common security fixes helps you secure cookies, but doesn't demonstrate a way to prevent simultaneous use of a valid cookie.