Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Laravel regenerate the Session ID? (compared to CodeIgniter)

CodeIgniter 2 regenerates the session id on every http-call. This leads to problems with concurrent ajax calls. This makes it possible that client and server get out of sync and the session is lost. A Fix to this is not updating the session on ajax-calls (see Codeigniter session bugging out with ajax calls). But if you use CodeIgniter as an API for a single page application, where every call is ajax, this just leads to the session never being updated at all. The user just get logged out after the session timeout (default 5 minutes).

In CodeIgniter 3 they attempted to fix this by using a write lock (see https://github.com/bcit-ci/CodeIgniter/issues/3073) on session storage. Because this relies on a Database-Feature it is only possible to safely store session information in MySQL and PostgreSQL. Redis for example can not be used (see http://www.codeigniter.com/userguide3/installation/upgrade_300.html#step-6-update-your-session-library-usage).

Finally my question is: How does Laravel handle this Problem? Laravel can use Redis for session storage. So when does laravel regenerate the session id? And if Laravel doesnt regenerate it automatically on every http request, how can this be judged in context of security aspects?

like image 217
Alex Avatar asked Nov 10 '22 13:11

Alex


1 Answers

Like pstephan1187 noted, "Laravel only regenerates the session ID when you sign in and sign out". CSRF Protection is used against cross-site request forgeries, and it consists of a field that is required by default (Laravel 5) in POST, PUT and DELETE requests.

Handling this in ajax-calls is outside the functionality offered by Laravel, but can be worked around pretty easily.

For more information about Laravel sessions, see the official documentation (Which, by the way, is a very nice and easy-to-understand read).

like image 192
OskarD90 Avatar answered Nov 15 '22 07:11

OskarD90