views:

151

answers:

4

I note that some sites (such as gmail) allow the user to authenticate over https and then switch to http with non-secure cookies for the main use of the site.

How is it possible to have http access to a session but this still be secure? Or is it not secure and hence this is why gmail gives the option to have the entire session secured using https?

Please give an example of how this works and avoids session hijacking attacks, whilst still allowing access to authenticated content over http. I want to be able to implement such a scheme if it's secure, to avoid having to have a whole site as https for performance reasons.

+2  A: 

It is only secure insofar as the password is not transmitted in the clear. It is possible (and has been done) to intercept and abuse the GMail session cookie in HTTP mode.

To avoid session hijacking, you need to stay in HTTPS mode (which GMail now offers, I think).

Thilo
Well, it will mitigate certain types of session hijacking, but it's not a silver bullet.
Bob Somers
HTTPS: No silver bullet, but a necessary first step?
Thilo
+2  A: 

This is just a tiny bit more secure than plain HTTP - the login name/password doesn't go over the wire in plaintext. Apart from that, it works exactly like a normal HTTP cookie-based session (because that's what it is); therefore, all the session hijacking issues apply.

Piskvor
+1  A: 

It's not really possible and not secure. That's why we got "secure cookies". Although it's good against passive sniffing attacks because username/password won't be exposed however session hijacking is still possible.

Also check out this SSL Implementation Security FAQ paper.

dr. evil
+2  A: 

As Thilo said, but I'll explain a little further :)

A webserver is stateless! This is really the problem of the authentication-case. You can't just log in, and then say "from now in, this user is logged in" - you need some way to identify which user it is that's requesting a new site this time.

A common way of doing this is by implementing sessions. If you packet-sniff your network traffic while logging into, and then browsing a site you'll commonly notice something like this:

Logging in: You will transmit your username and password to the server. Completely unencrypted! (SSL / HTTPS will encrypt this request for you to avoid man-in-the-middle attacks)

Response: You will receive a randomly generated string of a lot of weird characters. These will typically be stored in a cookie.

Request of some site only you should have access to: You will transmit the randomly generated string to the server. The server will look this string up, and see that it's associated with your session. This allows the server to identify you, and grant you access to your sites.

.. Now, HTTP in itself is not secure. This means that your password and your session-cookie (the randomly generated string) will be transmitted completely un-encrypted. If someone has access to your traffic (through trojans, router hijacking, whatever), he will be able to see your username / password when you log in, if you're not using HTTPS. This will grant him access to your site untill you change your password (unless he changes it first :P ). In the rest of the requests he will be able to get your session cookie, which means he could steal your identity for the rest of that cookie lifecycle ('till you log out, or the session expires on the server).

If you want to feel secure, use HTTPS. Realistically though, it's a lot easier to social engineer a keylogger into your computer than it is to read all your traffic :)

(Or as others have pointed out, use cross-site-scripting to read your session cookie)

cwap
> "Realistically though, it's a lot easier to social engineer a keylogger into your computer than it is to read all your traffic." Well, with wireless networks it seems very doable (think conferences or cafes).
Thilo
True that.. Especially on public hotspots
cwap
@Meeh: Correction in fourth para: SSL won't hash, it'll encrypt. The difference being mostly that SSL is vulnerable to another set of attacks based on the decryption key leaking, whereas a hash is reversible only if the hash algorithm is found to be weak.
Pontus Gagge
Yes, important point. I knew that, but was typing too fast :) Sorry about that..
cwap