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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

276 Part III: Building Secure <strong>Web</strong> <strong>Application</strong>sInstall URLScan on Your <strong>Web</strong> ServerURLScan is an ISAPI filter that is installed when you run the IISLockdown tool. Thishelps mitigate the threat of XSS attacks by rejecting potentially malicious input. Formore information about IISLockdown <strong>and</strong> URLScan, see Chapter 16, “Securing Your<strong>Web</strong> Server.”Note IIS 6.0 on Windows Server 2003 has functionality equivalent to URLScan built in.Use the HttpOnly Cookie OptionInternet Explorer 6 Service Pack 1 supports a new HttpOnly cookie attribute, whichprevents client-side script from accessing the cookie from the document.cookieproperty. Instead, an empty string is returned. The cookie is still sent to the serverwhenever the user browses to a <strong>Web</strong> site in the current domain.Note <strong>Web</strong> browsers that do not support the HttpOnly cookie attribute either ignore the cookie orignore the attribute, which means it is still subject to XSS attacks.The System.Net.Cookie class does not currently support an HttpOnly property. Toadd an HttpOnly attribute to the cookie, you need to use an ISAPI filter, or if youwant a managed code solution, add the following code to your application’s<strong>Application</strong>_EndRequest event h<strong>and</strong>ler in Global.asax:protected void <strong>Application</strong>_EndRequest(Object sender, EventArgs e){string authCookie = FormsAuthentication.FormsCookieName;foreach (string sCookie in Response.Cookies){// Just set the HttpOnly attribute on the Forms authentication cookie// Skip this check to set the attribute on all cookies in the collectionif (sCookie.Equals(authCookie)){// Force HttpOnly to be added to the cookie headerResponse.Cookies[sCookie].Path += ";HttpOnly";}}}Note A future version of the .NET Framework is likely to have an HttpOnly property on theCookie class.

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

Saved successfully!

Ooh no, something went wrong!