The vulnerability is a Cross-Site Scripting (XSS) issue in the Moodle TinyMCE equation editor, caused by insufficient sanitization of user-provided data in the preview feature. The analysis of the patch commit c85f153068a717a3b28bc122e75154bac99e67e1 reveals the exploitation path and the subsequent fix.
The vulnerable workflow is as follows:
- On the client side, the
updatePreview function in ui.js captures user input from the equation editor to generate a live preview.
- It calls the
filterEquation function in repository.js, which sends the input to the server via an AJAX call.
- The AJAX request is handled by the
execute method of the \tiny_equation\external\filter class in filter.php.
- Critically, before the patch, this
execute method passed the user's raw input directly to the filter_manager::instance()->filter_text() function without any sanitization. This allowed malicious HTML and JavaScript to be processed as part of the equation.
- The server returned the processed string, including the malicious script, back to the client.
- The
updatePreview function then used innerHTML to inject this returned content into the preview area, causing the script to execute in the browser.
The patch rectifies this by introducing a sanitization step. A new boolean parameter, $striptags, is added to the execute method. When this parameter is true, the server uses clean_param($content, PARAM_NOTAGS) to strip all HTML tags from the input before it is processed. The client-side updatePreview function is also modified to call filterEquation with this new parameter set to true, ensuring that all content rendered in the preview is properly sanitized, thus mitigating the XSS risk.