Skip to content

Fix stored XSS in renderer (mdlshield finding) - #138

Open
marcusgreen wants to merge 1 commit into
mainfrom
mdsh_renderer
Open

Fix stored XSS in renderer (mdlshield finding)#138
marcusgreen wants to merge 1 commit into
mainfrom
mdsh_renderer

Conversation

@marcusgreen

@marcusgreen marcusgreen commented Aug 12, 2026

Copy link
Copy Markdown
Owner

Fixes a stored XSS reported by the mdlshield automated review (HIGH severity). Teacher-authored gap content and correct-answer display text were concatenated into HTML in renderer.php without escaping, so a payload such as [<img src=x onerror=...>] executed in any student's browser.

Three paths fixed:

  • setup_answeroptions() - draggable answer list now built with html_writer::tag + s().
  • get_aftergap_text() - right-answer display now escaped with s().
  • get_feedback() - strip_tags left event-handler attributes (onclick, onerror, javascript: hrefs) on allowed tags; the output now runs through clean_text() which strips them.

Tests: added two walkthrough regression tests asserting an <img onerror> payload is escaped (raw payload absent, s()-escaped form present) in both the draggable list and the after-gap right-answer display. Full gapfill suite passes: walkthrough_test 24/24, plus question_test, questiontype_test, backup_test green.

Escape teacher-authored answer text before emitting it into HTML.
Three paths in renderer.php rendered raw content to students:
setup_answeroptions() draggable list and get_aftergap_text()
right-answer display are now escaped with s(), and get_feedback()
runs strip_tags output through clean_text() to remove event-handler
attributes and javascript: URLs that strip_tags leaves on allowed tags.

Add walkthrough regression tests asserting an <img onerror> payload
is escaped in the draggable list and the after-gap right-answer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant