DEV Community

Luuk Verhoeven
Luuk Verhoeven

Posted on

Moodle cron from the browser is a leftover attack surface

Moodle™ still ships a web entry for scheduled tasks: /admin/cron.php. Operators who upgraded the code and left the vhost alone still have it. The homepage can look fine. Cron from a browser is a different question.

The setting that closes it is $CFG->cronclionly. The proof is a GET from the public hostname, not a tick on the scheduled-tasks screen.

What the web cron actually is

Scheduled tasks and ad-hoc tasks are how Moodle sends mail, cleans sessions, processes course backups, pulls calendar events, and runs plugin jobs. CLI is the supported way:

php admin/cli/cron.php
# or, on 5.1 with the public/ restructure, from $CFG->root:
php public/admin/cli/scheduled_task.php --list | head
Enter fullscreen mode Exit fullscreen mode

/admin/cron.php is the old web wrapper. It runs the same work if the request is allowed. It is not a health check. It is execution.

A GET that returns 200 with Moodle's cron output means anyone who can reach the hostname can kick the job runner. That is noisy on a quiet site and useful on a site with a backup task, a mail dump, or a plugin that does work on first cron after deploy.

Prove it from the public hostname

HOST=https://lms.example.org

# web cron
curl -sI "$HOST/admin/cron.php" | head
curl -s "$HOST/admin/cron.php" | head -40

# same path under a 5.1 public/ document root still lives at /admin/cron.php
# because admin/cron.php moved into public/admin/cron.php
Enter fullscreen mode Exit fullscreen mode

Read the body, not only the status. A 200 with Cron execution not allowed or a redirect to login is different from a 200 that prints Scheduled task complete / Adhoc task complete. A 404 is the vhost you want if you deleted the script; Moodle still ships it, so 404 usually means a rewrite, not a missing file.

Then ask config what it thinks:

php -r 'define("CLI_SCRIPT", true); require "config.php";
echo "cronclionly="; var_export(!empty($CFG->cronclionly)); echo "\n";
echo "cronremotepassword=".(isset($CFG->cronremotepassword) && $CFG->cronremotepassword!=="" ? "set" : "empty"); echo "\n";
'
Enter fullscreen mode Exit fullscreen mode

$CFG->cronclionly = true; is the close. $CFG->cronremotepassword is the leftover: a query string that turns the web cron back on for anyone who has the password. Treat a password in a GET as a published secret. Do not add one to “keep monitoring working”. Monitor CLI instead.

nginx that refuses the script

A config flag is one control. The vhost is the one that still works if someone comments the flag out:

location = /admin/cron.php {
    return 404;
}
Enter fullscreen mode Exit fullscreen mode

Apache:

<Files cron.php>
    Require all denied
</Files>
Enter fullscreen mode Exit fullscreen mode

Keep CLI. systemd/timer or the host cron should call php admin/cli/cron.php as the moodle user, not as root, not via curl https://lms.example.org/admin/cron.php.

* * * * * /usr/bin/php /opt/moodle/admin/cli/cron.php >/dev/null 2>&1
Enter fullscreen mode Exit fullscreen mode

On 5.1 the CLI path is under the install root; public/admin/cli/cron.php is the one that matches $CFG->dirroot. Point the timer at the file that php -r can require next to config.php.

Two leftover traps

A plugin still documents “hit /admin/cron.php in a browser”. Old attendance, enrolment, and report plugins do this. The plugin is wrong. The site cron is CLI. If the plugin cannot run from CLI, that is a plugin bug, not a reason to open the web wrapper.

You already set cronclionly and the GET still runs. Then the request is not hitting the Moodle you edited. Staging vhost, a second document root, an old config.php on the origin behind the proxy. Curl the public hostname and the origin with Host: set. I have seen the proxy 404 and the origin 200.

Check it the week after go-live

Keep three curls next to the deploy ticket: /admin/cron.php, /admin/cli/cron.php (must 404 — CLI is not a web script), and /login/index.php (must 200, so you know you hit Moodle). Re-run after a plugin zip, after a theme deploy, after someone “temporarily” pointed an extra server at the checkout.

I built GuardLMS to notice when that web path comes back. Disclosure: I am the founder. The curls above do not require it. Moodle’s own note is to run cron from CLI.

Top comments (0)