MDL Shield

Kahoodle

mod_kahoodle

Print Report
Plugin Information

Kahoodle is a live classroom quiz game activity, similar to Kahoot. A facilitator runs rounds of multiple-choice questions on a shared screen and participants answer in real time from their own devices. It has scoring by response speed, leaderboards and a podium, alias and fully anonymous identity modes, report-builder results, backup/restore, and a set of web services that AI agents can also use. Real-time messaging comes from the required tool_realtime plugin.

Version:2026111600
Release:4.5.3
Reviewed for:5.3
Privacy API
Unit Tests
Behat Tests
Reviewed:2026-11-17
148 files·31,466 lines
Grade Justification

No exploitable security vulnerabilities were found. Every entry point was traced, and each one handles access correctly:

  • Pages (view.php, questions.php, results.php, index.php) call require_login and the right capability checks. Their state-changing actions are sesskey-protected.
  • Web services all call validate_context() and require_capability() against the context of the object being loaded. Cross-activity references, such as the target round in duplicate_question, are checked.
  • The realtime callback checks facilitate for facilitator actions. Participant actions only work for an existing participant record, which in turn requires the participate capability.
  • kahoodle_pluginfile restricts each file area by capability, and avatars by participant ownership.
  • Output is escaped throughout. Every triple-brace template variable was traced to format_string/format_text, get_string, or an integer. User-controlled display names always go through {{ }} or s().

All SQL uses placeholders, and the Privacy API is fully implemented.

The only defects are two low-severity code-quality issues, both limited to teacher-level functionality or rare configurations:

  • The activity web services skip the numeric and enum checks that mod_form applies.
  • The backup step builds engine-specific LIMIT/TOP SQL, which fails on Oracle under Moodle 4.5, a version the plugin declares support for.
AI Summary

mod_kahoodle is a large, well-built activity module: about 70 PHP classes, six AMD modules and about 30 Mustache templates. It implements a live, Kahoot-style quiz game on top of the tool_realtime plugin, which it requires. It ships with an extensive PHPUnit and Behat test suite, a complete Privacy API provider, backup/restore, report-builder system reports, and a set of external functions intended for AI agents.

The security posture is strong:

  • Every page, web service, dynamic form, inplace-editable callback and realtime callback validates its context and checks capabilities against the object it actually loads.
  • State-changing GET actions carry a sesskey.
  • All SQL is parameterised.
  • Participant-supplied display names are escaped wherever they are rendered. That includes the rank sentences, which are pre-escaped with s() before being put into language strings.
  • Rich question text is cleaned on save and formatted on output.
  • The profile-picture download uses download_file_content() behind curl_security_helper, with timeouts set.

Two low-severity issues were found. The activity-level web services (create_modules, update_module) write timing, points and mode settings without the non-negative, range and maxpoints >= minpoints checks that the settings form enforces. The backup step also builds a LIMIT 1/TOP 1 subquery, which breaks backups without user data on Oracle under Moodle 4.5.

The realtime transport, including channel secrecy and the sesskey check on the push endpoint, lives in tool_realtime, which was not available for review. The plugin's own handler does its own authorisation, so this is noted as a dependency rather than a weakness.

Findings

code qualityLow
Activity web services skip the settings validation applied by mod_form

mod_kahoodle_create_modules and mod_kahoodle_update_module copy lobbyduration, questionpreviewduration, questionduration, questionresultsduration, maxpoints, minpoints, identitymode and questionformat straight into the module record. They then call add_moduleinfo()/update_moduleinfo(), which do not run mod_kahoodle_mod_form::validation(). As a result, values the form rejects are accepted: negative durations or points, maxpoints below minpoints, and an identitymode or questionformat outside the defined constants. The question-level services avoid this problem because they go through questions::validate_question_data().

Risk Assessment

Low risk. Only users who can already edit the activity (moodle/course:manageactivities or mod/kahoodle:addinstance) can reach this, and the effect is confined to that activity's scoring and timing. Nothing crosses a privilege boundary. Out-of-range identitymode values fall back to non-anonymous behaviour, so they do not expose anonymous participants.

Context

The settings form rejects negative numbers and maxpoints < minpoints. Scoring in responses::calculate_points() and stage durations in round_question::get_stage_duration() assume those checks have been applied. The web services are the second write path for the same fields, and they rely only on PARAM_INT typing.

Identified Code
foreach (array_keys(helper::settings_parameters(false)) as $field) {
    $moduleinfo->$field = $module[$field];
}
Suggested Fix

Validate the settings in one shared helper and call it from both the form and the web services:

$errors = helper::validate_settings((array)$moduleinfo);
if ($errors) {
    throw new \invalid_parameter_exception(implode('; ', $errors));
}

The helper should reject negative values, maxpoints < minpoints, and modes or formats that are not among the constants::IDENTITYMODE_* / QUESTIONFORMAT_* values.

Identified Code
foreach (array_keys(helper::settings_parameters(true)) as $field) {
    if (array_key_exists($field, $params)) {
        $data->$field = $params[$field];
    }
}
Suggested Fix

Call the same shared settings validation on $data before \update_moduleinfo(). Check against the merged values (stored + changed), so that maxpoints >= minpoints is enforced even when only one of them is passed.

code qualityLow
Backup step builds engine-specific LIMIT/TOP SQL

When a backup is made without user data, the backup structure step picks the "last round" with hand-written subqueries. These append LIMIT 1, or TOP 1 when the database family is mssql. That covers MySQL/MariaDB, PostgreSQL and SQL Server, but not Oracle. Oracle is still supported by Moodle 4.5, which version.php declares as supported (requires = 2024100700, supported = [405, 503]), and core only dropped Oracle in 5.0. On such a site, backing up, duplicating or importing a Kahoodle activity without user data fails with a SQL error. Moodle avoids engine-specific row limiting in SQL text: limits are meant to go through the $limitfrom/$limitnum arguments of the DML API.

Risk Assessment

Low risk. This is a portability defect, not a security issue. It only affects Moodle 4.5 sites running on Oracle, where backup, duplication or import of the activity without user data fails.

Context

The $top/$limit fragments go into three set_source_sql() calls: questions, question versions, and the round itself. These run only when the userinfo backup setting is off, which is the default for course duplication and import.

Identified Code
$ismssql = ($DB->get_dbfamily() === 'mssql');
$top = $ismssql ? 'TOP 1 ' : '';
$limit = $ismssql ? '' : ' LIMIT 1';
Suggested Fix

Work out the last round once in PHP using the portable DML limit, then pass its id as a plain parameter in the three source queries:

$activityid = $this->task->get_activityid();
$last = $DB->get_records_sql(
    "SELECT id FROM {kahoodle_rounds} WHERE kahoodleid = ?
      ORDER BY CASE WHEN currentstage = 'preparation' THEN 0 ELSE 1 END, timecreated DESC, id DESC",
    [$activityid], 0, 1);
$lastroundid = $last ? (int)reset($last)->id : 0;
// ... then use "r.id = ?" / "rq.roundid = ?" with $lastroundid.
Additional AI Notes

Dependency on tool_realtime (not available for review). All live gameplay goes through mod_kahoodle_realtime_event_received() in lib.php. Its docblock says that tool_realtime's push.php calls require_login() and require_sesskey() before invoking it, and that channel hashes are salted and never exposed to users who were not subscribed on the server.

The handler does its own authorisation:

  • It calls validate_context().
  • Facilitator actions need mod/kahoodle:facilitate.
  • Participant actions need an existing participant record, which in turn requires the participate capability.

CSRF protection for the push endpoint, and the confidentiality of facilitator and participant channel payloads, depend on tool_realtime behaving as documented. Sites should keep that plugin up to date.

Editing questions of finished rounds. The question form lets a user with mod/kahoodle:manage_questions edit questions of archived rounds. When content changes, questions::edit_question() creates a new version and repoints that archived round's kahoodle_round_questions row to it, so past results show the corrected text. This looks intentional (typo fixes, and the bundled AI skill describes it), and multichoice prevents changes to the option count or correct answer once responses exist. Still, it does rewrite what historical rounds display.

Anonymous mode identification. In fully anonymous mode, participants are identified by md5(userid . sesskey . roundid). This keeps participation unlinkable in the database. It also means one user can join the same round several times from separate sessions, which is inherent to the design rather than a defect.

Test coverage is extensive. PHPUnit tests cover the externals, entities, game logic, output classes, privacy provider, report builder and the ad-hoc task, alongside 12 Behat feature files and a CI workflow.

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