Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is HttpOnly get set for ASP.NET_SessionId cookie?

In my web project setting to turn on httpOnlyCookies is not there. It is false by default. Also there is no place in code where cookie is being set to HttpOnly. However, when I browse to the site I can see that ASP.NET_Session cookie is being passed as HttpOnly. How is it set to HttpOnly?

like image 371
dev.e.loper Avatar asked Feb 11 '10 19:02

dev.e.loper


2 Answers

ASP.NET session cookies are HTTP only, regardless of the httpOnlyCookies setting linked to in your question, because this is burned into ASP.NET. You can't override this.

If you dig into the System.Web.SessionState.SessionIDManager class in the System.Web assembly the code for creating the ASP.NET session cookie looks like:

private static HttpCookie CreateSessionCookie(string id)
{
    HttpCookie cookie = new HttpCookie(Config.CookieName, id);
    cookie.Path = "/";
    cookie.HttpOnly = true;   // <-- burned in
    return cookie;
}
like image 122
Kev Avatar answered Oct 02 '22 21:10

Kev


It is HttpOnly so your session cookie cannot be modified by the client with JavaScript.

like image 43
Shawn Steward Avatar answered Oct 02 '22 23:10

Shawn Steward