MDL Shield

Maintenance mode (live check)

local_maintenance_livecheck

Print Report
Plugin Information

Local plugin that adds a client-side live check for Moodle's maintenance mode. It injects an AMD module into every page through the before_footer_html_generation output hook. The module polls a lightweight, sessionless ajax.php endpoint and shows the maintenance countdown or notice without a full page reload. Admins can restrict polling to certain weekdays and time slots, and set a back-off delay.

Privacy API
Unit Tests
Behat Tests
Reviewed:2026-11-20
10 files·907 lines
Grade Justification

No security vulnerabilities were found, and the only finding is an informational note about how the JavaScript polling is scheduled.

  • Unauthenticated endpoint: ajax.php is public by design and runs without a session. It only returns whether maintenance is scheduled or active, and how many seconds remain. Moodle core already shows this to anonymous visitors through core_renderer::maintenance_warning() and the maintenance page title set in moodle_page. It reads no user input, changes no state and accesses no user data.
  • Correct use of core APIs: the plugin uses the 5.x hook API instead of a legacy callback, standard admin settings, a correct null_provider, and preloaded strings via strings_for_js(). The time-slot logic uses core_date, usergetdate() and make_timestamp() with the server timezone passed in explicitly.
  • Tests and hygiene: a PHPUnit data-provider test covers the weekday and time-slot logic, Behat scenarios cover the main user stories, the AMD build matches its source, and there is no third-party code or database access.

The one observation is that the poll loop uses setInterval with no request timeout. That is a robustness suggestion, not a defect that can be exploited.

AI Summary

local_maintenance_livecheck is a small local plugin (about 10 source files). It shows Moodle's maintenance announcement without a page reload. A hook callback adds an AMD module to every page, and the module polls a sessionless ajax.php endpoint for the maintenance status.

The security posture is clean. ajax.php is deliberately unauthenticated and sets NO_MOODLE_COOKIES, so polling does not keep sessions alive. It reads no request parameters and returns only the maintenance timing, which core already shows to anonymous visitors. On the client, the only data inserted into the page is fixed markup and preloaded core language strings with numeric countdown values, so there is no XSS path. Admin settings use the standard admin setting classes, and the Privacy API is correctly declared as a null_provider.

The only finding is informational. The poller fires on a fixed setInterval with no request timeout, so on a slow server, requests from one tab can overlap. Chaining each check from the previous response's completion would cap this at one request in flight per tab. Nothing in the review requires urgent action.

Findings

best practiceInfo
Live-check polling can overlap and has no request timeout

checkStatus() runs on a fixed setInterval, and the $.ajax call sets no timeout. Core does not set a global $.ajaxSetup default, so a request can stay pending indefinitely. If ajax.php takes longer than the configured interval (minimum 10 seconds), the browser starts another request before the previous one has finished. When the server is slow or overloaded, each open tab can therefore have several live-check requests in flight at once, adding load at exactly the moment the plugin's own settings text warns about. Starting the next check only after the previous one completes, and adding a timeout, would cap this at one request per tab.

Risk Assessment

Informational. This is not a security issue. Overlap only happens when a response takes longer than the interval, and browser per-host connection limits cap concurrency per tab. The benefit is lower load during server stress, which is when maintenance announcements matter most.

Context

init() runs on every page that renders the standard footer, for every visitor, logged in or not. Each tab polls ajax.php, which loads the full Moodle bootstrap but no session. The interval (10–300 s) and back-off are admin settings.

Identified Code
        $.ajax({
            url: config.wwwroot + '/local/maintenance_livecheck/ajax.php',
            dataType: 'json',
            type: 'POST',
            data: {
                // Add a query string to prevent older versions of IE from using the cache.
                'time': Date.now()
            },
Suggested Fix

Add a timeout and schedule the next check from the complete callback (store the interval in a module-level variable during init):

        $.ajax({
            url: config.wwwroot + '/local/maintenance_livecheck/ajax.php',
            dataType: 'json',
            type: 'POST',
            timeout: checkIntervalMs,
            data: {
                'time': Date.now()
            },
            // ... headers, success, error unchanged ...
            complete: function() {
                setTimeout(checkStatus, checkIntervalMs);
            }
        });
Identified Code
                    setTimeout(function() {
                        setInterval(checkStatus, params.checkinterval * 1000);
                    }, params.backoff * 1000);

                    // Otherwise if no back off time is set.
                } else {
                    // Check status every params.checkinterval seconds.
                    setInterval(checkStatus, params.checkinterval * 1000);
                }
Suggested Fix

Replace both setInterval calls with a single delayed first check, then rebuild amd/build with Grunt:

                checkIntervalMs = params.checkinterval * 1000;
                var backoffMs = (params.backoff !== null && params.backoff > 0) ? params.backoff * 1000 : 0;
                setTimeout(checkStatus, backoffMs + checkIntervalMs);
Additional AI Notes

Unauthenticated status endpoint is intentional. ajax.php deliberately skips require_login() and sets NO_MOODLE_COOKIES. It reads no request parameters, changes no state, and returns only timeleftinsec (null, 0 or a positive integer). Core already exposes the same information to anonymous visitors:

  • core_renderer::maintenance_warning() shows the scheduled countdown on every page.
  • moodle_page sets the Maintenance mode page title when legacy maintenance is enabled.

As with any other Moodle request, a poll that arrives after maintenance_later has passed triggers core's switch to CLI maintenance in lib/setup.php. This is core behaviour, not something the plugin adds.

Admin setting class names in Moodle 5.3. Core 5.3 moved the admin setting classes into \core_admin\setting\... (for example \core_admin\setting\setting\configmulticheckbox2 and \core_admin\setting\settingpage\settingpage). It keeps class_alias shims for the old names, and admin/UPGRADING.md says existing classes are currently unaffected, so settings.php is not using anything deprecated. The plugin only supports 5.3 ($plugin->supported = [503, 503]), so it could switch to the new names now and avoid a future deprecation cycle.

CI workflow pinning. Both .github/workflows files call reusable workflows from moodle-an-hochschulen/moodle-workflows at @main, and the release workflow passes MOODLE_ORG_TOKEN to one of them. This is not part of the plugin's runtime code, but pinning the reusable workflows to a commit SHA would stop an unreviewed change on that branch from being able to access the release token.

This review was generated by an AI system and may contain inaccuracies. Findings should be verified by a human reviewer before acting on them.