Moodle™ ships a guest user. Courses can enrol it. The login screen can show “Log in as a guest”. Autologin can put that user on every unauthenticated hit. None of that is a welcome banner. It is a second, named account that bypasses the login you think you have.
The pentest that only tries /login/index.php with a staff user will pass. The course that still has guest enrolment will still serve the PDF.
What guest actually is
Guest is a real user in mdl_user (id 1 on a default install). It is not “anonymous”. Capabilities still run. They run as guest. Site administration → Users → Permissions → Define roles → Guest is the role. Course enrolment method Guest access (enrol_guest) is the door.
Three independent switches:
-
Guest login button — Site administration → Plugins → Authentication → Manage authentication → Guest login button. Show means
/login/index.phpoffers the guest path. - Auto-login guests — Site administration → Users → Permissions → User policies → Auto-login guests. On means an unauthenticated request that hits a guest-open course becomes a guest session without a click.
- Force users to log in — Site administration → General → Security → Site security settings. On means almost every page redirects to login. Guest enrolment can still win on a course that allowed it before you ticked this, so do not treat the tick as the whole control.
Teachers turn guest on per course. Admins turn the site-wide buttons. The two layers disagree more often than the security report admits.
Prove it from the public hostname
Do this on a throwaway course, not a live exam.
HOST=https://lms.example.org
# no cookie
curl -sI "$HOST/" | head
curl -sI "$HOST/login/index.php" | head
curl -sI "$HOST/course/view.php?id=2" | head
curl -sI "$HOST/mod/resource/view.php?id=10" | head
Read Location and Set-Cookie. A 303 to /login/index.php with no MoodleSession is the closed site. A 200 on the course, or a 303 that still sets MoodleSession for guest, is the open one.
Then ask config:
php -r 'define("CLI_SCRIPT", true); require "config.php";
echo "forcelogin="; var_export(!empty($CFG->forcelogin)); echo "\n";
echo "guestloginbutton="; var_export($CFG->guestloginbutton ?? null); echo "\n";
echo "autologinguests="; var_export(!empty($CFG->autologinguests)); echo "\n";
echo "forceloginforprofiles="; var_export(!empty($CFG->forceloginforprofiles)); echo "\n";
'
guestloginbutton is 0 hidden, 1 shown. Autologin is the one that surprises procurement: the login form can look closed while /course/view.php?id= still 200s.
List the courses that still enrol guest:
php -r 'define("CLI_SCRIPT", true); require "config.php";
global $DB;
$rows = $DB->get_records_sql("
SELECT c.id, c.shortname, e.status, e.password
FROM {enrol} e
JOIN {course} c ON c.id = e.courseid
WHERE e.enrol = ?
", ["guest"]);
foreach ($rows as $r) {
$pw = ($r->password === "" || $r->password === null) ? "none" : "set";
printf("course=%d\t%s\tstatus=%s\tkey=%s\n", $r->id, $r->shortname, $r->status, $pw);
}
'
status=0 is enabled. A guest enrolment with no key is world-readable course content for anyone who can guess or be sent the URL. A key that teachers recycle across terms is a shared password on a GET form.
Close the three doors, then re-curl
Hide the guest login button. Untick auto-login guests. Tick force users to log in. Disable enrol_guest on every course that does not have a written exception (open prospectus, public MOOC). Disable the enrolment plugin itself if the estate has no such exception.
# after the change
curl -sI "$HOST/course/view.php?id=2" | head
curl -sI -c /tmp/guest.jar -b /tmp/guest.jar "$HOST/login/index.php" | head
You want 303 to login, and no guest session created by a GET to a course URL.
Front-page files still leak through pluginfile.php when the context is the site and the file is public. Guest off does not hide a file you marked as everyone. Curl the file URL from an incognito window after you close guest. That is a separate control.
Exam week is when guest comes back
A lecturer enables guest “so the inspector can click around without an account”. The inspector leaves. The method stays. Next Monday the assignment PDF is indexed. Re-run the enrol SQL after every term start, after every restore from a template course that had guest on, and after anyone asks for “just a preview link”.
I built GuardLMS to notice when guest enrolment and autologin come back. Disclosure: I am the founder. The curls above do not require it. Moodle’s own guest role is read-only by design. Read-only still includes the file.
Top comments (0)