Contents
Another more recent scheme in this area is SCS: Secure Cookie Sessions for HTTP, which is a solid scheme, very well thought-out. I recommend reading the security discussion of that document to get a good sense of what the security threats may be.
Cookie is not dependent on session, but Session is dependent on Cookie. Cookie expires depending on the lifetime you set for it, while a Session ends when a user closes his/her browser. The maximum cookie size is 4KB whereas in session, you can store as much data as you like.
Which is more secure, cookies or session variables?
Ideally you should redirect the user browser to access an authenticated user to SSL encrypted version of your site pages, but even SSL can be worked around with sophisticated tricks. Nevertheless using sessions (if possible over SSL) is more secure than just using cookies to store user sensitive data.
How are cookies used to identify a user?
Sessions in reality also use cookies to identify an user that keeps accessing a site, request after request. But what session cookies store is just an identifier string that is used as key to store and retrieve session variables on the server side.
When a cookie authentication scheme isn’t provided to AddCookie, it uses CookieAuthenticationDefaults.AuthenticationScheme (“Cookies”). The authentication cookie’s IsEssential property is set to true by default.
There are 3 very important directives ( Secure, HttpOnly , and SameSite) that should be understood before using cookies, as they heavily impact how cookies are stored and secured. Cookies contain very sensitive information: if attackers can get a hold of a session ID, they can impersonate users by hijacking their sessions.
What happens to Cookie authentication when user is disabled?
If a user account is disabled in back-end systems: The app’s cookie authentication system continues to process requests based on the authentication cookie. The user remains signed into the app as long as the authentication cookie is valid. The ValidatePrincipal event can be used to intercept and override validation of the cookie identity.