Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encrypt session id in cookie?

While I was reading about session hijacking articles, i learned that it would be nice to encrypt session id value that is stored in a cookie.

As far as I know, when I start a session by calling session_start(), PHP does not encrypt session id value in a cookie.

How do I encrypt session id value and then initialize session with it?

like image 834
Moon Avatar asked Apr 11 '10 00:04

Moon


2 Answers

Encrypting won't help. The session cookie is just a magic number anyway. Encrypting it just means there's a different magic number to hijack. Depending on what hijacking scenarios you have in mind, there are other possible mitigations. For example, you can limit sessions to a single IP. That poses some issues though, e.g. people switching between wireless points.

like image 71
Matthew Flaschen Avatar answered Oct 20 '22 05:10

Matthew Flaschen


It's more important that your session IDs are random (that is, someone can't use their session ID to guess another person's), as the real danger is somebody getting their hands on another user's session ID. As long as you keep them truly random, there's no reason to or utility in encrypting it

like image 35
Michael Mrozek Avatar answered Oct 20 '22 04:10

Michael Mrozek