MDL Shield

TinyMCE Word Limit

tiny_wordlimit

Print Report
Plugin Information

TinyMCE editor plugin (tiny_wordlimit) that adds a 'Maximum word limit' indicator to the editor status bar. It also colours the word count as the limit gets close and when it is exceeded. It works for essay questions in quiz attempts and question previews, and for assignment online-text submissions.

Privacy API
Unit Tests
Behat Tests
Reviewed:2026-11-17
16 files·744 lines
Grade Justification

The plugin has no security vulnerabilities. It has no endpoints, forms, database writes, file access or outbound requests. Its only server-side work reads word-limit integers that already exist on the current page and passes them to the editor as configuration.

  • The values injected into the DOM with insertAdjacentHTML are integers (DB column qtype_essay_options.maxwordlimit is int, and the assignment limit is cast with (int)), plus a core language string. There is no XSS path.
  • The privacy null provider is correct, because the plugin stores no data.

The two findings are low-severity functional and robustness defects:

  • The quiz-slot lookup is tied to a hard-coded /mod/quiz/ URL path, and it falls back to slot 1's limit for any editor it cannot match.
  • Limit detection depends on page-script global variables, so it is fragile across core versions and can attach an indicator to unrelated editors.

Neither defect affects confidentiality or integrity, and the plugin code is otherwise small and clean.

AI Summary

tiny_wordlimit is a small TinyMCE add-on: two PHP classes, a null privacy provider and five AMD modules. It shows the essay or assignment maximum word limit in the editor status bar and colours the word count as the user nears or passes it. It has no pages, web services, database tables or settings.

The security posture is clean. The only data sent to the browser are integer word limits that the current user can already see. The HTML that the JavaScript builds contains only those integers and a core language string, so there is no injection path.

The findings that matter are functional:

  • Wrong limits on some quiz pages. The quiz detection compares the page path against the literal /mod/quiz/. On a site installed in a subdirectory, every essay on a quiz page therefore gets slot 1's limit, or no limit at all, and students can be shown the wrong number.
  • Fragile detection. The server side finds limits by reading global variables left by core page scripts ($attemptobj, $slots, $assign, $question). This can break silently when core changes, and it can attach an indicator to unrelated editors, such as the teacher's feedback-comments editor on the assignment grading page.

Findings

code qualityLow
Quiz slot detection uses a hard-coded URL path and falls back to slot 1

isQuizQuestionEditor() only recognises a quiz essay editor when editor.documentBaseURI.path is exactly /mod/quiz/. TinyMCE derives that base from document.location, so on a site installed under a subdirectory (e.g. https://host/moodle/) the path is /moodle/mod/quiz/ and the check always fails. getWordLimit() then returns wordLimits[1] for every editor on the page, so all essays show slot 1's limit, or no indicator at all if slot 1 has no limit. The same fallback applies to any editor on a quiz page whose name does not match q<usage>:<slot>_answer. Students may be shown a word limit that does not apply to the question they are answering.

Risk Assessment

Low risk. This is a correctness defect, not a security issue: the displayed limit is advisory, and core still enforces the real limit on submission. However, students on affected installs see misleading guidance.

Context

plugininfo::get_plugin_configuration_for_context() sends an object of limits keyed by quiz slot (or {1: limit} for assignments and previews). The JS then selects the entry for each editor instance using the URL path and the editor's name attribute.

amd/src/options.js:92Source link unavailable — plugin was reviewed from zip without a matching git ref
Identified Code
const isQuizQuestionEditor = (editor) => {
    if (editor.documentBaseURI.path === MOD_QUIZ_ATTEMPT_PATH &&
        EDITOR_NAME_PATTERN_QUIZ.test(editor.targetElm.name)) {
        return true;
    }
    return false;
};
Suggested Fix

Key the lookup on the editor name alone, or compare with endsWith. Do not fall back to index 1 when a quiz-shaped wordLimits object is present:

const isQuizQuestionEditor = (editor) =>
    editor.documentBaseURI.path.endsWith(MOD_QUIZ_ATTEMPT_PATH) &&
    EDITOR_NAME_PATTERN_QUIZ.test(editor.targetElm.name);

A more robust option is to have PHP return keys that the JS can match exactly, such as the editor element id.

amd/src/options.js:79Source link unavailable — plugin was reviewed from zip without a matching git ref
Identified Code
        // Only one wordlimit per page (online submission within assignment).
        return wordLimits[1];
Suggested Fix

Return wordLimits[1] only when the server signalled a single-limit page, for example with a separate mode option or a dedicated key, rather than for every unmatched editor.

code qualityLow
Word limits are detected by reading core page-script global variables

wordlimit::detect_wordlimits_on_page() ignores the $context it is given. Instead it reads global $attemptobj, $slots, global $assign and global $question, which are local variables in core page scripts (mod/quiz/attempt.php, mod/assign/view.php, question/bank/previewquestion/preview.php) and not a public API. Any refactor that moves this code into a function or class makes the feature disappear silently. In addition, every editor rendered while those globals are set receives the limit. For example, the assignment grading form (view.php?action=grade) runs with $assign set, so the teacher's feedback-comments editor shows the student's online-text word limit and turns red past it. On the quiz review page, $attemptobj and $slots are also set.

Risk Assessment

Low risk. No data is exposed beyond what the user can already see. The impact is a maintenance hazard and cosmetic mis-labelling of unrelated editors. Over the plugin's supported range (4.5 to 5.3), a core change to any of these scripts would break detection with no error.

Context

Core calls get_plugin_configuration_for_context() for each TinyMCE instance on a page. The plugin calls unset() on most arguments and instead inspects whatever globals the calling page script happens to have defined.

classes/wordlimit.php:69Source link unavailable — plugin was reviewed from zip without a matching git ref
Identified Code
        global $attemptobj, $slots;

        if (!$attemptobj || !$slots) {
            return null;
        }
Suggested Fix

Derive the limits from the $context passed in (e.g. load the assign instance or quiz attempt from the module context) and also check $PAGE->pagetype (e.g. mod-quiz-attempt, mod-assign-editsubmission). That way only the intended pages and editors receive a limit.

classes/wordlimit.php:111Source link unavailable — plugin was reviewed from zip without a matching git ref
Identified Code
        global $assign;

        if (!$assign) {
            return null;
        }
Suggested Fix

Check the page type and the editor's identity (the $options/$editor arguments are available in get_plugin_configuration_for_context()), so the limit is applied only to the online-text submission editor.

Additional AI Notes

CHANGELOG mismatch: The 1.1.2 entry in CHANGELOG.md describes a "Setting to configure whether to use experimental features", but the plugin ships no settings.php and no matching language strings. Either the entry is stale or the feature was removed without a changelog note.

DOM injection reviewed: amd/src/ui.js builds the status-bar element with a template string and insertAdjacentHTML. All interpolated values are integer word limits from core (qtype_essay_options.maxwordlimit is an int column, and the assignment limit is cast with (int)) or the core qtype_essay/maxwordlimit language string, so this is not exploitable. Building the node with document.createElement and textContent would make that guarantee explicit.

Behat coverage only: tests/behat/wordlimit.feature covers assignments, quiz attempts and question preview well. There are no PHPUnit tests for wordlimit::detect_wordlimits_on_page(), which would catch the global-variable fragility as soon as core changes.

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