Why can't the Yesod session cookie be hijacked?

2.3k Views Asked by At

The Yesod book says

The encryption prevents the user from inspecting the data, and the signature ensures that the session can be neither hijacked nor tampered with.

It's not clear to me why this is the case. If an eavesdropper gets hold of the cookie as it is sent from the server and uses it before the legitimate user makes another request, won't the session end up being hijacked?

It seems to me that the only way to really prevent session hijacking is to use SSL throughout. But if I do so then the signing and encryption done by Yesod ends up being unnecessary overhead (EDIT: overhead as far as preventing hijacking is concerned. As @sr_ points out in the comments, it is still useful otherwise).

1

There are 1 best solutions below

4
On BEST ANSWER

That's a good catch. This used to be more accurate, when we would include the IP address of the client in the cookie to prevent hijacking. Combined with the anti-tampering protections, this made it basically impossible for a MITM attack to work unless you were NATed behind the same router or using the same proxy.

Unfortunately, we had to disable that protection due to concerns about proxies as well. It's possible for a single user's requests to come from multiple IP addresses due to intermediate proxy servers. I don't have data to tell how often this happens, but there was enough concern about this security feature causing breakage that we disabled it.

Thank you for bringing this up, I've corrected the book.