Looking at ASP.NET Identity (new membership implementation in ASP.NET), I came across this interface when implementing my own UserStore
:
//Microsoft.AspNet.Identity.Core.dll
namespace Microsoft.AspNet.Identity
{
public interface IUserSecurityStampStore<TUser> :
{
// Methods
Task<string> GetSecurityStampAsync(TUser user);
Task SetSecurityStampAsync(TUser user, string stamp);
}
}
IUserSecurityStampStore
is implemented by the default EntityFramework.UserStore<TUser>
which essentially get and set the TUser.SecurityStamp
property.
After some more digging, it appears that a SecurityStamp
is a Guid
that is newly generated at key points in the UserManager
(for example, changing passwords).
I can't really decipher much beyond this since I'm examining this code in Reflector. Almost all the symbol and async information has been optimized out.
Also, Google hasn't been much help.
Questions are:
- What is a
SecurityStamp
in ASP.NET Identity and what is it used for? - Does the
SecurityStamp
play any role when authentication cookies are created? - Are there any security ramifications or precautions that need to be taken with this? For example, don't send this value downstream to clients?
Update (9/16/2014)
Source code available here:
This is meant to represent the current snapshot of your user's credentials. So if nothing changes, the stamp will stay the same. But if the user's password is changed, or a login is removed (unlink your google/fb account), the stamp will change. This is needed for things like automatically signing users/rejecting old cookies when this occurs, which is a feature that's coming in 2.0.
Identity is not open source yet, its currently in the pipeline still.
Edit: Updated for 2.0.0. So the primary purpose of the
SecurityStamp
is to enable sign out everywhere. The basic idea is that whenever something security related is changed on the user, like a password, it is a good idea to automatically invalidate any existing sign in cookies, so if your password/account was previously compromised, the attacker no longer has access.In 2.0.0 we added the following configuration to hook the
OnValidateIdentity
method in theCookieMiddleware
to look at theSecurityStamp
and reject cookies when it has changed. It also automatically refreshes the user's claims from the database everyrefreshInterval
if the stamp is unchanged (which takes care of things like changing roles etc)If your app wants to trigger this behavior explicitly, it can call:
I observed the SecurityStamp to be required for token verification.
To repo: Set SecurityStamp to null in the databsae Generate a token (works ok) Verify token (fails)
The UseCookieAuthentication is deprecated by now. I managed to configure it using
Moved from reply to answer per request.