Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to secure the ASP.NET_SessionId cookie?

I have set the .ASPXAUTH cookie to be https only but I am not sure how to effectively do the same with the ASP.NET_SessionId.

The entire site uses HTTPS so there is no need for the cookie to work with both http and https.

like image 520
Pete Avatar asked May 12 '11 13:05

Pete


People also ask

How do I mark session cookies as secure?

Mark cookies as Secure Cookies. Add( new HttpCookie("key", "value") { Secure = true, }); That's it! Cookies are now only sent over HTTPS, making it impossible to intercept any cookies accidentally sent over HTTP (you still want to eliminate those calls if any).

What does ASP NET_SessionId cookie do?

Net_SessionId is a cookie which is used to identify the users session on the server. The session being an area on the server which can be used to store data in between http requests.

Are cookie based sessions secure?

The cookie allows the server to identify the user and retrieve the user session from the session database, so that the user session is maintained. A cookie-based session ends when the user logs off or closes the browser. Cookie-based session management is secure and has performance benefits over alternatives.

Where is ASP NET_SessionId set?

That SessionID is set in the Response Header along with a reponse from a web server. Now you can see that an ASP. NET_SessionId has been created by the server and set in the Response Header.


1 Answers

To add the ; secure suffix to the Set-Cookie http header I simply used the <httpCookies> element in the web.config:

<system.web>   <httpCookies httpOnlyCookies="true" requireSSL="true" /> </system.web> 

IMHO much more handy than writing code as in the article of Anubhav Goyal.

See: http://msdn.microsoft.com/en-us/library/ms228262(v=vs.100).aspx

like image 86
Marcel Hoyer Avatar answered Sep 21 '22 14:09

Marcel Hoyer