First time here? Check out the site's "greatest hits" or read a post from the archives. Feel free to leave a comment or ask a question, and consider subscribing to the latest posts via RSS or e-mail. Thanks for visiting!
« Presentation Tips PPT | Main | Introducing WatirMaker - Recording for R... »

Internet Explorer 6 SP1 supports an extra "HttpOnly" cookie attribute, that prevents client-side script from accessing the cookie via the document.cookie property. Cookies still round trip.

The value of this property is questionable since any sniffer or Fiddler could easily remove it. That said, it could slow down the average script kiddie for 15 seconds.

You can do it a few ways. I added this to the Global.asax and catch all the cookies on the way out the door. You could choose to do this to specific cookies if you like.

protected void Application_EndRequest(Object sender, EventArgs e)
{
    foreach(string cookie in Response.Cookies)
    {
        const string HTTPONLY = ";HttpOnly";
        string path = Response.Cookies[cookie].Path;
        if (path.EndsWith(HTTPONLY) == false)
        {
            //force HttpOnly to be added to the cookie
            Response.Cookies[cookie].Path += HTTPONLY;
        }
    }
}

Of course, ASP.NET 2.0 can do all this for you via a Web.config setting.

SILLY GOTCHA: If you do this in your ASP.NET 1.1 app and then run your 1.1 app under 2.0 without changes, be aware that ASP.NET 2.0 will blindly append ANOTHER HttpOnly after every cookie giving you the value TWICE. You'll then need to turn if off in web.config as your code would be handling it.

<httpCookies httpOnlyCookies="false" requireSSL="false" domain="" />

Tracked by:
Daniel Fisher(lennybacon) on C# and .Net from Wuppertal [Trackback]
"RE: httpOnly cookies in ASP.NET 1.1" (Daniel Fisher(lennybacon) on C# and .Net ... [Trackback]
"“HttpOnly Cookies on ASP.NET 1.1″ - A little added security" (Capta... [Trackback]
"Cookies, Sistemas Distribu" (Rui Quintino) [Trackback]
"HTTP - Set-Cookie - HttpOnly" (Good news everyone!) [Trackback]
"How to force all cookies to Secure under ASP.NET 1.1" (Scott Hanselman's Comput... [Trackback]


Thursday, July 21, 2005 10:24:51 PM (Pacific Standard Time, UTC-08:00)
"That said, it could slow down the average script kiddie for 15 seconds"

to what kind of attack/threat are you referring here??
which sniffer will remove that on a XSS victim's PC?

dominick
Friday, July 22, 2005 5:32:28 AM (Pacific Standard Time, UTC-08:00)
What about doin' it all in the code to have no need to hassle with versions or touching config files.

protected void Application_EndRequest(Object sender, EventArgs e)
{
if(System.Environment.Version.Major<2)
{
foreach(string cookie in Response.Cookies)
{
const string HTTPONLY = ";HttpOnly";
string path = Response.Cookies[cookie].Path;
if (path.EndsWith(HTTPONLY) == false)
{
//force HttpOnly to be added to the cookie
Response.Cookies[cookie].Path += HTTPONLY;
}
}
}
}
Friday, July 22, 2005 5:50:01 AM (Pacific Standard Time, UTC-08:00)
I guess it's for html-script-injection-to-expose-session-id-or-stored-password attacks, e.g. for forums.
Anonymous
Friday, July 22, 2005 8:10:49 AM (Pacific Standard Time, UTC-08:00)
Daniel. Nice! I totally forgot about System.Environment. Thanks!
Friday, July 22, 2005 10:06:42 AM (Pacific Standard Time, UTC-08:00)
What's with declaring the const inside of the loop? Would it make more sense to declare it once above the foreach?
Anon
Friday, July 22, 2005 11:40:54 AM (Pacific Standard Time, UTC-08:00)
That's just me being sloppy. The JIT fixes that kind of sloppiness though.
Comments are closed.

Contact

Sponsors

Hosting By

On this page...

Tags

Calendar

<November 2008>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

Archives

Google Ads