Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoiding session hijacking in ASP.NET

I recently read an article on making ASP.NET sessions more secure here and at first it seems really useful.

Previously I had been storing the user's IP address in the session, then making sure in every subsequent request that the requesting IP was equal to the stored IP.

The code in the article also protects the session by checking the IP address, except it stores a hashed message authentication code containing the user's IP as part of the session cookie. It creates a hashed MAC twice every request, which I imagine would slow things down a little.

I can already see a potential flaw in their code: if you were to somehow get a hold of the key used to generate the MAC, you could then generate a valid MAC with your own IP - you wouldn't even have to fake the IP the session was started on.

It seems like an overly-complex solution to a simple problem which not only incurs a larger overhead but also is more susceptible to attack than the trivial method - unless I'm completely missing the point.

So, why would this approach be any more secure than the more simple approach that I had been using?

As a slight aside, the author also states that you shouldn't use the whole IP address in the comparison, as some user's IPs change every request if they are behind a proxy. Is this still the case if you check X_FORWARDED_FOR?

Thanks!

like image 951
sjmeverett Avatar asked Feb 24 '11 16:02

sjmeverett


People also ask

How can session hijacking be prevented?

There are several things you can do to prevent session hijacking and protect your data and identity online, including: Use a VPN. A high-quality VPN can mask your IP address and keep your online activity private and secure. Avoid public or unsecure Wi-Fi networks.

What is the best defense against session hijacking?

The best defense against session hijacking is to force secure, encrypted communications over TLS/SSL. This is also sometimes called "HTTPS". Cookies will still be sent with every request but their contents will not be visible because the entire communication will be encrypted while in transit.

What are the two main types of session hijacking?

There are two types of session hijacking depending on how they are done. If the attacker directly gets involved with the target, it is called active hijacking, and if an attacker just passively monitors the traffic, it is passive hijacking.

What is session hijacking and how is it achieved?

A session hijacking attack happens when an attacker takes over your internet session — for instance, while you're checking your credit card balance, paying your bills, or shopping at an online store. Session hijackers usually target browser or web application sessions.


1 Answers

See this post: What is the best way to prevent session hijacking?

Basically, you should use HTTPS on your login page and any other "sensitive areas".

like image 188
Jonathan Nesbitt Avatar answered Nov 07 '22 02:11

Jonathan Nesbitt