News for hackers. Stuff that matters.
Re:HTTP cookies, or how not to design protocols by Udo on Friday October 29, 2010 @10:11AM (#1847354)
That's a nice summary!

I still think allowing cookies to span more than one distinct domain was a mistake. If we had avoided that in the beginning, cookie scope implementations would be dead simple and not much functionality would be lost on the server side. Also, JavaScript cookie manipulation is something we could easily lose for the benefit of every user, web developer and server admin. I postulate there are very few legitimate uses for document.cookie

Re:HTTP cookies, or how not to design protocols by tptacek on Friday October 29, 2010 @11:29AM (#1847603)
There may be few legitimate uses for document.cookie, but eliminating it does very little to prevent cross-site scripting.
Re:HTTP cookies, or how not to design protocols by kls on Friday October 29, 2010 @05:42PM (#1849155)
Also, JavaScript cookie manipulation is something we could easily lose for the benefit of every user, web developer and server admin

With more and more apps moving to pure JS / CSS/ and HTML front ends the lack of being able to manipulate cookies would kill a good deal of in app storage abilities. Eliminating useful feature to make someone else's job easier is rarely ever a good solution.

Re:HTTP cookies, or how not to design protocols by mike-cardwell on Friday October 29, 2010 @01:30PM (#1848105)
You can use the HttpOnly flag with a cookie to prevent JavaScript being able to access it. Here's a good summary:

http://www.owasp.org/index.php/HttpOnly

If you are serving a cookie, and JavaScript doesn't need to be able to access it, you should set it to be HttpOnly to try and reduce the effects of an XSS.

Re:HTTP cookies, or how not to design protocols by tptacek on Friday October 29, 2010 @01:38PM (#1848130)
It doesn't seem like Michal is sold on HttpOnly and I definitely am not either; most everything you can do with a stolen cookie, you can also do quickly and silently using a captive browser during an XSS attack.
Re:HTTP cookies, or how not to design protocols by jacquesm on Friday October 29, 2010 @03:51PM (#1848749)
No cost, potential benefit. I've had to make harder decisions.
Re:HTTP cookies, or how not to design protocols by tptacek on Friday October 29, 2010 @03:53PM (#1848755)
The cost is "false sense of security", and believe me, from field work, that is a real cost. A majority of programmer applicants can't solve FizzBuzz, so you're deluded if you think that a good chunk of webdevs don't think "HttpOnly fixes XSS".

The potential benefit is... what, exactly?

Re:HTTP cookies, or how not to design protocols by Udo on Friday October 29, 2010 @05:11PM (#1849060)
It lessens your potential attack surface and comes at no cost. And as security-ignorant devs are concerned (which we all are from time to time) it doesn't magically fix vulnerabilities, but it can alleviate the magnitude of exploits. It's a good idea.
Re:HTTP cookies, or how not to design protocols by tptacek on Friday October 29, 2010 @05:15PM (#1849076)
Try to articulate how it lessens the attack surface. It means you can't bank up session tokens; instead, you're only able to do everything that a session token would do for you anyhow. Remember in your explanation that session tokens already expire anyways.
Re:HTTP cookies, or how not to design protocols by Udo on Friday October 29, 2010 @06:11PM (#1849262)
By sending the HttpOnly flag as a server application, I indicate to the browser that it should prevent client-side scripts from obtaining the actual value of the cookie. Hence, it is more difficult for a malicious little piece of smuggled-in XSS code to steal my session id and ship it off to some Nigerian server. Is it circumventable? Yes. Are different browser implementations subverting this scheme? Yes. But is the intention behind it worthwhile? ...I think so.

Of course, that kind of protection is superficial, but please try to remember in your rebuttal there are actual attacks still happening that could have been prevented by setting this simple flag. An insistence on always making secure code that won't have this problem anyway is honorable but not realistic. By the way, it happens on high profile sites, too. It shouldn't, and it makes us web devs uncomfortable even observing it from a distance, but it still happens.

Even disregarding this argument, for me HttpOnly is the way cookies should have been conceived by default. I believe accessing cookie values by JavaScript is pathological. The behavior HttpOnly attempts to trigger on the client seems like good practice to me, and given (again) the point that it comes at no cost to the reasonable developer, turning it on is really a no-brainer. In fact, browsers should turn it on whether the flag is set or not.

It means you can't bank up session tokens; instead, you're only able to do everything that a session token would do for you anyhow.

Oh, you can still use other exploits to bank up tokens, but yes this particular avenue is blocked. You're absolutely right, having the current session to work with is pretty destructive. But I think shipping off session IDs to a hostile server is worse than issuing false requests on behalf of the user in an already open browser window. That's because siphoning session IDs is silent and can lead to problems many days later when you're _not_ online.

Try to articulate [...] Remember in your explanation that session tokens already expire anyways.

Alright, I'll try not to drool and babble more than necessary: for the sake of convenience we are used to very long-lasting session tokens. So when you say they expire, yes, it limits the amount of damage somewhat, but not in any meaningful way considering the typical cookie-based account identifier lasts well beyond a week. Certainly for the purpose of completing my answer I can now say "I remembered" session expiration but it didn't really go anywhere.

Re:HTTP cookies, or how not to design protocols by mike-cardwell on Friday October 29, 2010 @01:43PM (#1848153)
True. Still, given the option of having it turned on or off, I'll turn it on. If only it makes an attack a little more difficult it's worth using.
Re:HTTP cookies, or how not to design protocols by pak on Friday October 29, 2010 @11:57AM (#1847723)
How about double-posting session ID's from the cookie within AJAX requests to prevent XSRF? I've certainly used document.cookie for that.

The only other scheme I know of to defend against XSRF is to generate secret values for every request, which is not always practical.

Re:HTTP cookies, or how not to design protocols by tptacek on Friday October 29, 2010 @01:42PM (#1848149)
I'm not sure I can think of one web app I've tested this year that overloaded the session cookie for an XSRF token; it is straightforward to just generate a random token and embed it in the page, and that also gives you fine-grained control over CSRF protection for forms where you want per-render instead of per-session protection.

You don't need to generate per-request tokens unless you want to; the token is simply yet another thing you stick into the session store and splash out onto the rendered page.

(Also, as my colleague Cory points out: if an attacker can influence the ACTION attribute of the form in any way, you've just coughed up your session token to an attacker in the name of blocking CSRF; is the risk worth the reward?).

Re:HTTP cookies, or how not to design protocols by pak on Saturday October 30, 2010 @06:03AM (#1850574)
Well, instead of generating two separate tokens, a simpler solution IMHO is overloading the cookie, and it's what I usually see and use.

What are you talking about "if an attacker can influence the ACTION attribute of the form"? If they are running JavaScript in your DOM you are already hosed, they can grab any token you put in your form. There is no sane reason for having ACTION change via request parameters: you would have bigger issues than session stealing. And in any other situation, you should be protected by the browser's cross domain restrictions. I don't understand what you are suggesting.

Re:HTTP cookies, or how not to design protocols by brlewis on Friday October 29, 2010 @03:40PM (#1848699)
I don't think an attacker can influence my ACTION attribute, but just in case, I use only 4 characters from my session token (1MM combinations). I don't think CSRF tokens are easy to brute-force, so that should be long enough.

I don't like keeping per-request state on the server, else I would use random CSRF tokens.

Re:HTTP cookies, or how not to design protocols by tptacek on Friday October 29, 2010 @03:46PM (#1848725)
It doesn't need to be per-request; it can just be another 128 bit random number, stored in the session, re-used for every request.