11.07.2015 Views

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

Improving Web Application Security: Threats and - CGISecurity

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

280 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>sSecure the Authentication CookieTo prevent session hijacking <strong>and</strong> cookie replay attacks, secure the cookie by makingsure that it is only passed over SSL connections using the HTTPS protocol. Foradditional risk mitigation, encrypt the cookie before sending it to the client <strong>and</strong> limitthe period for which the cookie is valid. To secure the authentication cookie:●●●●●●●Restrict the authentication cookie to HTTPS connections.Encrypt the cookie.Limit cookie lifetime.Consider using a fixed expiration period.Do not persist authentication cookies.Keep authentication <strong>and</strong> personalization cookies separate.Use distinct cookie names <strong>and</strong> paths.Restrict the Authentication Cookie-to-HTTPS ConnectionsCookies support a “secure” property that determines whether or not browsers shouldsend the cookie back to the server. With the secure property set, the cookie is sent bythe browser only to a secure page that is requested using an HTTPS URL.If you are using .NET Framework version 1.1, set the secure property by usingrequireSSL=“true” on the element as follows:If you are using .NET Framework version 1.0, set the secure property manually in the<strong>Application</strong>_EndRequest event h<strong>and</strong>ler in Global.asax using the following code:protected void <strong>Application</strong>_EndRequest(Object sender, EventArgs e){string authCookie = FormsAuthentication.FormsCookieName;}foreach (string sCookie in Response.Cookies){if (sCookie.Equals(authCookie)){// Set the cookie to be secure. Browsers will send the cookie// only to pages requested with httpsResponse.Cookies[sCookie].Secure = true;}}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!