Guest Redirect
local_guestredirect
Local plugin that provides a shareable URL (/local/guestredirect/index.php?id=<courseid>) which, when the plugin's kill switch is enabled and the course has an enabled guest access enrolment instance, logs a not-logged-in visitor in as the site guest user and redirects them to the course page — without relying on the global autologinguests setting or the guest login button.
The review found no security, compliance or code-quality defects.
- The only entry point,
index.php, reads a singlePARAM_INTparameter. It only creates a guest session when three conditions all hold: the admin kill switch is on, the visitor is not logged in, and the course has an enabled guest enrolment instance.enrol_get_instances($courseid, true)checks both the instance status and the site-level enabled-plugin list. - Course access is then enforced by
require_login($course, true). Core's session handling regenerates the session ID duringcomplete_user_login(), which prevents session fixation. - Already-authenticated users are never affected. The plugin cannot raise anyone above the zero-privilege site guest account.
- The plugin includes a correct null privacy provider and a site-config-gated settings page. It has PHPUnit and Behat coverage, and it ships no third-party code.
local_guestredirect is a very small plugin: one redirect page, a helper class with four static methods, a settings page with a single on/off switch, a null privacy provider, and PHPUnit and Behat tests. Its job is to let a not-logged-in visitor follow a link and land in a course as the site guest user, without turning on autologinguests for the whole site.
The guest login logic matches core's own autologinguests path in require_login(). It calls guest_user() and complete_user_login(), which regenerates the session ID. After that, require_login($course, true) enforces course visibility, guest enrolment passwords and the other access checks. The plugin only acts when the admin has turned on the kill switch, the visitor is anonymous and the course has an enabled guest enrolment instance. The highest privilege anyone can get through it is the zero-privilege guest account.
The review produced no findings. The page accepts a plain GET with no CSRF token, which the authors document as intentional because the link is meant to be shared. The worst that does is move an anonymous visitor into a guest session they could have opened themselves. More detail is under the additional notes.
Findings
GET-triggered guest login (intentional, no sesskey). helper::login_as_guest() runs on a plain GET with no require_sesskey(). A third-party page could therefore make an anonymous visitor's browser open a guest session. This has no practical impact:
should_login_as_guest()returns false for anyone already logged in, so an existing session is never replaced.- The resulting account is the site guest, the same outcome as core's
autologinguests.
The authors document this decision in the code comment above the call.
Bypasses the guest login button by design. Once enabled, the redirect works even when $CFG->guestloginbutton is off. Core's login/index.php refuses guest logins in that case. The behaviour is clearly stated in the setting description (setting_enable_note). Admins should know that the effective control is then the per-course Guest access enrolment instance plus this plugin's kill switch.
Unknown course IDs. index.php calls get_course($courseid) before any login check, so a non-existent ID ends in a standard dml_missing_record_exception. This matches course/view.php, which also loads the course with MUST_EXIST before require_login(). Course existence is not sensitive, so this is not reported as an issue.