Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is regenerating the session id after login a good practice?

I'm wondering if regenerating the session id after a successful login really a good practice and not just sort of a cargo cult behavior.

If I understand the theory correctly it should prevent session hijacking (or at least make it harder), but I can't really see that if someone could steal the pre-login session what would stop the phisher doing it again with the regenerated one.

I'm not focusing on Spring (I don't even use Java currently), I'm interested in the pros and cons.

like image 692
Wabbitseason Avatar asked May 26 '11 09:05

Wabbitseason


2 Answers

Yes. You should regenerate the session on login, to help defend against session fixation and login CSRF.

See OWASP's recommendation for more.

like image 148
D.W. Avatar answered Oct 22 '22 15:10

D.W.


You regenerate to prevent session hijacking when the pre-login is http and the post-login is https. That is what stops the attacker doing it again with the regenerated one.

It is relatively easy to steal a session identifier for an http session, assuming you are near the victim, or in the path somewhere, or have phished etc - and if this session identifier is also viable in the encrypted session it can make the attacker's job quite easy.

like image 33
Rory Alsop Avatar answered Oct 22 '22 17:10

Rory Alsop