Redirection bug #2
Current behavior / Resultado actual / Résultat actuel
User accesses a course folder with URL GET ...main/document/document.php?cidReq=COURSEXX&id_session=0&gidReq=0&gradebook=0&origin= But the next request Chamilo does is to another course COURSEYY: GET .../courses/COURSEYY/ And this confuses this user of course
Expected behavior / Resultado esperado / Résultat attendu
A Document.php request should show the documents of the course mentioned in the URL GET parameter (cidReq=COURSEXX)
Steps to reproduce / Pasos para reproducir / Étapes pour reproduire
Unclear when this happens.
Chamilo Version / Versión de Chamilo / Version de Chamilo
1.11.2 with patch https://github.com/chamilo/chamilo-lms/issues/1545
This occurs when you copy a course content to another course, and when this copied content (in HTML) contains links to other resources in the initial course. This is a long story which I have described in another issue somewhere here. It should happen less and less with time (we improve the algorithm to detect and transform more of these internal links over time), but until we catch them all, this will continue to happen.
So here the trick is to catch the precise HTML tag that contains a URL to the older course (that provokes a context change in the Chamilo session) and give it to us so we can fix it in time for the next version of Chamilo. However, this will not fix links in documents that have already been copied from one course to another.
In Chamilo 2.0, links to other documents should be absolute and not contain the ID of the course, which could have the right effect on copied courses as well.
If the ...main/document/document.php?cidReq=COURSEXX URL points to a folder and not a document, where should I find this 'old' HTML tag that causes this error and why doesn't it happen every time I open this URL? I love algorithms.
Whether it's pointing at a document or a folder doesn't really matter. What matters is the "cidReq=COURSEXX" where COURSEXX is not the current course.
It might not happen each time because all resources linked from an HTML document are loaded asynchronously, so some requests might get executed in a different order between two full document loads, or the requested resources might already be in your browser's cache, so they're not loaded from the server anymore, which means they won't affect your session either.
In the first case (different load order), what matters is the last request to execute fetching a resource that is part of your current document. If the last request goes to COURSEXX, then your context changes to COURSEXX. If this is not the last request to be treated by the server (with your session cookie), then another request might come after that one and change the context back to your current course, so you don't notice the context change (but it happens for a brief moment).
And there people thought coding in Chamilo was easy...
Just now a teacher complained about an incorrect redirect after login, viewing course XXX, clicking ANNOUNCEMENTS in course XXX and being redirected to the main page of another course YYY. In the HTTP logs can be found that course YYY is fetched while announcements in course XXX were asked.
"GET /courses/COURSEXXX/index.php?id_session=0 HTTP/1.1" 200 59407 ….. "GET /main/img/icons/64/backup.png "GET /main/announcements/announcements.php?cidReq=COURSEXXX&id_session=0&gidReq=0&gradebook=0&origin= "GET /courses/COURSEYYYY/ HTTP/1.1" 200 59358
Our problem is not caused by links to documents to other courses. It seems it is a php-session problem where the course ID is not correctly updated. The document.php file relies on the _cid sessionvariable in the php session and apparently this contains an old value.
I will look into local.inc.php where these variables are set:
Session::write('_real_cid', $_real_cid);
Session::write('_cid', $_cid);
Session::write('_course', $_course);
Somehow the cidReq in the URL and the _cid course ID in the php session get out of sync.
We are progressively getting rid of cids defined in the session to rely (at least for all resources loaded through URLs) exclusively on the URL.
Another thing I noticed: om chamilo.org and localhost testsites a user stays logged in "forever", but on our production site with F5 loadbalancer and multiple webservers the sessions do timeout. What is the session lifetime on chamilo.org? Can it be forever?
Yes. The session lifetime is mostly dictated by Chamilo's $_configuration['session_lifetime'] (which dictates the cookie storage life after the last interaction), PHP's garbage collector, and by wathever stores the sessions.
So even if your cookie says "24h", if you don't connect for 12h and the garbage collector is set to dump session files more than 10h old (for example session.gc_maxlifetime = 36000), your cookie won't be useful when you reconnect after 20h. And whatever the setting of session.gc_maxlifetime, you might still have an additional sessions cleaner if you use a cluster with a shared session manager like memcached...).
So yes, they can be very long, but not forever (unless you prevent your garbage collector from cleaning session files, but that would be a bad idea in the long term - including at a security level).
I don't see any ini_set using the session_lifetime config value to set the gc_maxlifetime session lifetime search
https://github.com/chamilo/chamilo-lms/blob/1.11.x/main/inc/lib/chamilo_session.class.php#L54 The session_lifetime is not used to set gs_maxlifetime, but only to check, when starting a new connection, whether the current session has expired or not: https://github.com/chamilo/chamilo-lms/blob/1.11.x/main/inc/lib/chamilo_session.class.php#L112
The gc_maxlifetime setting must be set as a system administrator on your Linux (or other) server in the php.ini config (or vhost or other, depending on how you work on your server).
I cannot change the system php.ini but adding this line to chamilo_session.class.php helps a lot: ini_set('session.gc_maxlifetime', 3600243); // 3 days
Now sessions are kept for 3 days so a user that does not close the browser seldomly has to log in again. It may be a security risk on shared laptops but I think the redirection bug will now happen less frequent. That doesn't mean it is gone. I will check the logs after a few weeks of running with this gc_maxlifetime setting.
Many improvements have been added to Chamilo 1.11.6 to make sure the cidReq parameter is sent as often as possible to avoid session variables lingering. Considering that we don't have a particular environment or procedure to reproduce that easily, I am considering this issue fixed by the changes we made over the last 6 months. Please don't hesitate to re-open if you can still observe this issue.