go to bug id or search bugs for
Please do correct me if I'm wrong, but it seems to me the documentation on session_regenerate_id is a bit dangerous and misleading.
It states that you should take additional precautions to avoid session loss, and the example basically gives the following pattern:
* start session
* if session ended in last 10 minutes, redirect to new session
* if session ended longer ago, remove authentication information
* create new session_id
* store new session_id in old session
* mark current session as destroyed
* start new session with new session_id
What my usual use case for using session_generate_id is that a user logged in or out. A new session ID is an additional precaution against session hijacking - if an attacker somehow manage to sneak in his own session id to his victim and convinces him to log in, his own session will be logged in because it's the same.
Given the pattern described in the documentation, this approach is void because even though a new session id is generated, it is stored in the old session. So if the attacker refreshes his page within 10 minutes after he convinces his victim to log in, he will be redirected to the new session, too, and still be logged in.
Unless I'm missing something here, I think the documentation is actually suggesting to introduce a session hijacking vulnerability to users.
While it is true that in bad network situations session loss may occur if the newly generated session ID never made it to the client, this risk does not seem worth the vulnerability introduced by work around, and at least there should be a big warning sign stating that this approach introduces other security risks.
This problem could be mitigated by at least adding a check for $_SERVER['REMOTE_ADDR'] and $_SERVER['HTTP_USER_AGENT'] before redirecting to the new session.
Add a Patch
Add a Pull Request
There should be window opened for "Legitimate Users".
The example code open window for 5 minutes for unstable networks. e.g. Subway, Elevator, etc.
The window should be shorter as much as it is possible. However, shorter window could results in lost sessions.
The example code in the manual page has invalid (old session ID access) session detection also. Either "Legitimate User" or "Attacker" will be notified invalid access. (If your app is smart enough, you can notify both. i.e. When the exception is raised, get the other session (or even better, get all user's sessions for the user) and set "Invalid Access Flag", then notify.)
More discussions and issues are described in
Although above RFCs are declined, OWASP seems to add many issues and aspects to reflect above.
I was intended to improve session documents when above RFCs are accepted, but they didn't. session_regenerate_id() documentation (as well as other docs) could be improved, so I keep this bug open for the time being.
"While it is true that in bad network situations session loss may occur if the newly generated session ID never made it to the client, this risk does not seem worth the vulnerability introduced by work around, and at least there should be a big warning sign stating that this approach introduces other security risks."
I suppose you think "session_regenerate_id(true)" is better. While it is true by ignoring risks of lost sessions, it can happen more often. For example, when I tried regenerate_id(true) for every requests, this caused "Client side race condition" and results in lost sessions in every few thousands requests in 2015. Likeness of lost sessions depends on "Web browser" since this is client side race condition.
This approach "session_regenerate_id(true)" has other issue. "Session hijack attack detection" is not possible by "session_regenerate_id(true)". Above my approach that "Open a little window and detect attack" is better because "Legitimate users" could know possible attacks.
"Open a little attack window and detect attack"(Best) provides much better security than "Leave old sessions behind"(The worst which is current session module default) or "Remove old session immediately"(Better, but far from optimal).
"For example, when I tried regenerate_id(true) for every requests, this caused "Client side race condition" and results in lost sessions in every few thousands requests in 2015. Likeness of lost sessions depends on "Web browser" since this is client side race condition."
This test was performed on "localhost"(127.0.0.1) which must be very stable network, BTW.