CVE-2019-3847
Description
Moodle before 3.6.3, 3.5.5, 3.4.8, 3.1.17 fails to escape user-added JavaScript on Dashboards, enabling stored XSS when administrators log in as other users.
AI Insight
LLM-synthesized narrative grounded in this CVE's description and references.
Moodle before 3.6.3, 3.5.5, 3.4.8, 3.1.17 fails to escape user-added JavaScript on Dashboards, enabling stored XSS when administrators log in as other users.
Vulnerability
A stored cross-site scripting (XSS) vulnerability exists in Moodle's Dashboard feature. Users can add custom content, including JavaScript, to their Dashboard. When a user with the "login as other users" capability (e.g., administrators or managers) logs in as another user and views that user's Dashboard, the JavaScript is not escaped, allowing it to execute in the privileged user's browser. Affected versions are Moodle before 3.6.3, 3.5.5, 3.4.8, and 3.1.17 [1].
Exploitation
An attacker (a regular user) can inject malicious JavaScript into their Dashboard, for example via a block that permits custom HTML or JavaScript. A privileged user then uses the "login as" feature to impersonate the attacker and navigates to the Dashboard. The injected script executes automatically in the context of the privileged user's session, without requiring any further interaction [1].
Impact
Successful exploitation allows the attacker to execute arbitrary JavaScript in the context of the privileged user's browser. This can lead to session hijacking, data theft, or performing administrative actions on behalf of the privileged user, potentially compromising the entire Moodle site [1].
Mitigation
The vulnerability is fixed in Moodle versions 3.6.3, 3.5.5, 3.4.8, and 3.1.17. The commits [2][3][4] introduce a $CFG->forceclean setting for "logged in as" sessions, which disables user-generated scripts during such sessions. Administrators should upgrade to the patched versions. No workaround is documented; upgrading is the recommended mitigation.
AI Insight generated on May 22, 2026. Synthesized from this CVE's description and the cited reference URLs; citations are validated against the source bundle.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
moodle/moodlePackagist | >= 3.6.0, < 3.6.3 | 3.6.3 |
moodle/moodlePackagist | >= 3.5.0, < 3.5.5 | 3.5.5 |
moodle/moodlePackagist | >= 3.2.0, < 3.4.8 | 3.4.8 |
moodle/moodlePackagist | < 3.1.17 | 3.1.17 |
Affected products
2Patches
5e836242e1c04MDL-63786 core_my: prevent dashboard access when logged in as
2 files changed · +8 −0
lang/en/my.php+1 −0 modified@@ -39,3 +39,4 @@ $string['resetpage'] = 'Reset page to default'; $string['reseterror'] = 'There was an error resetting your page'; $string['privacy:metadata:core_my:preference:user_home_page_preference'] = 'The user home page preference configured for the Dashboard page.'; +$string['unabletoaccess'] = 'As a security precaution, you may not access another user\'s dashboard';
my/index.php+7 −0 modified@@ -45,6 +45,13 @@ require_login(); +if (\core\session\manager::is_loggedinas()) { + // Disable access to the user's dashboard for "logged in as" sessions + // to mitigate risks associated with loading other users' JavaScript. + // See MDL-63786 for more information. + redirect(new moodle_url('/', ['redirect' => 0]), get_string('unabletoaccess', 'core_my')); +} + $hassiteconfig = has_capability('moodle/site:config', context_system::instance()); if ($hassiteconfig && moodle_needs_upgrading()) { redirect(new moodle_url('/admin/index.php'));
ec3b63c772d6MDL-63786 core_my: prevent dashboard access when logged in as
2 files changed · +8 −0
lang/en/my.php+1 −0 modified@@ -38,3 +38,4 @@ $string['reseteveryonesprofile'] = 'Reset profile for all users'; $string['resetpage'] = 'Reset page to default'; $string['reseterror'] = 'There was an error resetting your page'; +$string['unabletoaccess'] = 'As a security precaution, you may not access another user\'s dashboard';
my/index.php+7 −0 modified@@ -45,6 +45,13 @@ require_login(); +if (\core\session\manager::is_loggedinas()) { + // Disable access to the user's dashboard for "logged in as" sessions + // to mitigate risks associated with loading other users' JavaScript. + // See MDL-63786 for more information. + redirect(new moodle_url('/', ['redirect' => 0]), get_string('unabletoaccess', 'core_my')); +} + $hassiteconfig = has_capability('moodle/site:config', context_system::instance()); if ($hassiteconfig && moodle_needs_upgrading()) { redirect(new moodle_url('/admin/index.php'));
070f24d006eaMDL-63786 core: set $CFG->forceclean for logged in as sessions
3 files changed · +11 −0
course/loginas.php+3 −0 modified@@ -79,6 +79,9 @@ // Login as this user and return to course home page. \core\session\manager::loginas($userid, $context); +// Add a notification to let the logged in as user know that all content will be force cleaned +// while in this session. +\core\notification::info(get_string('sessionforceclean', 'core')); $newfullname = fullname($USER, true); $strloginas = get_string('loginas');
lang/en/moodle.php+1 −0 modified@@ -1799,6 +1799,7 @@ $string['separateandconnectedinfo'] = 'The scale based on the theory of separate and connected knowing. This theory describes two different ways that we can evaluate and learn about the things we see and hear.<ul><li><strong>Separate knowers</strong> remain as objective as possible without including feelings and emotions. In a discussion with other people, they like to defend their own ideas, using logic to find holes in opponent\'s ideas.</li><li><strong>Connected knowers</strong> are more sensitive to other people. They are skilled at empathy and tend to listen and ask questions until they feel they can connect and "understand things from their point of view". They learn by trying to share the experiences that led to the knowledge they find in other people.</li></ul>'; $string['servererror'] = 'An error occurred whilst communicating with the server'; $string['serverlocaltime'] = 'Server\'s local time'; +$string['sessionforceclean'] = 'As a security precaution, user generated scripts have been disabled within this session'; $string['setcategorytheme'] = 'Set category theme'; $string['setpassword'] = 'Set password'; $string['setpasswordinstructions'] = 'Please enter your new password below, then save changes.';
lib/moodlelib.php+7 −0 modified@@ -2693,6 +2693,13 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ // Make sure the USER has a sesskey set up. Used for CSRF protection. sesskey(); + if (\core\session\manager::is_loggedinas()) { + // During a "logged in as" session we should force all content to be cleaned because the + // logged in user will be viewing potentially malicious user generated content. + // See MDL-63786 for more details. + $CFG->forceclean = true; + } + // Do not bother admins with any formalities, except for activities pending deletion. if (is_siteadmin() && !($cm && $cm->deletioninprogress)) { // Set the global $COURSE.
93dda3bfd3caMDL-63786 core: set $CFG->forceclean for logged in as sessions
3 files changed · +11 −0
course/loginas.php+3 −0 modified@@ -79,6 +79,9 @@ // Login as this user and return to course home page. \core\session\manager::loginas($userid, $context); +// Add a notification to let the logged in as user know that all content will be force cleaned +// while in this session. +\core\notification::info(get_string('sessionforceclean', 'core')); $newfullname = fullname($USER, true); $strloginas = get_string('loginas');
lang/en/moodle.php+1 −0 modified@@ -1808,6 +1808,7 @@ $string['separateandconnectedinfo'] = 'The scale based on the theory of separate and connected knowing. This theory describes two different ways that we can evaluate and learn about the things we see and hear.<ul><li><strong>Separate knowers</strong> remain as objective as possible without including feelings and emotions. In a discussion with other people, they like to defend their own ideas, using logic to find holes in opponent\'s ideas.</li><li><strong>Connected knowers</strong> are more sensitive to other people. They are skilled at empathy and tend to listen and ask questions until they feel they can connect and "understand things from their point of view". They learn by trying to share the experiences that led to the knowledge they find in other people.</li></ul>'; $string['servererror'] = 'An error occurred whilst communicating with the server'; $string['serverlocaltime'] = 'Server\'s local time'; +$string['sessionforceclean'] = 'As a security precaution, user generated scripts have been disabled within this session'; $string['setcategorytheme'] = 'Set category theme'; $string['setpassword'] = 'Set password'; $string['setpasswordinstructions'] = 'Please enter your new password below, then save changes.';
lib/moodlelib.php+7 −0 modified@@ -2757,6 +2757,13 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ // Make sure the USER has a sesskey set up. Used for CSRF protection. sesskey(); + if (\core\session\manager::is_loggedinas()) { + // During a "logged in as" session we should force all content to be cleaned because the + // logged in user will be viewing potentially malicious user generated content. + // See MDL-63786 for more details. + $CFG->forceclean = true; + } + // Do not bother admins with any formalities, except for activities pending deletion. if (is_siteadmin() && !($cm && $cm->deletioninprogress)) { // Set the global $COURSE.
a37e26d2efe1MDL-63786 core: set $CFG->forceclean for logged in as sessions
3 files changed · +11 −0
course/loginas.php+3 −0 modified@@ -79,6 +79,9 @@ // Login as this user and return to course home page. \core\session\manager::loginas($userid, $context); +// Add a notification to let the logged in as user know that all content will be force cleaned +// while in this session. +\core\notification::info(get_string('sessionforceclean', 'core')); $newfullname = fullname($USER, true); $strloginas = get_string('loginas');
lang/en/moodle.php+1 −0 modified@@ -1804,6 +1804,7 @@ $string['separateandconnectedinfo'] = 'The scale based on the theory of separate and connected knowing. This theory describes two different ways that we can evaluate and learn about the things we see and hear.<ul><li><strong>Separate knowers</strong> remain as objective as possible without including feelings and emotions. In a discussion with other people, they like to defend their own ideas, using logic to find holes in opponent\'s ideas.</li><li><strong>Connected knowers</strong> are more sensitive to other people. They are skilled at empathy and tend to listen and ask questions until they feel they can connect and "understand things from their point of view". They learn by trying to share the experiences that led to the knowledge they find in other people.</li></ul>'; $string['servererror'] = 'An error occurred whilst communicating with the server'; $string['serverlocaltime'] = 'Server\'s local time'; +$string['sessionforceclean'] = 'As a security precaution, user generated scripts have been disabled within this session'; $string['setcategorytheme'] = 'Set category theme'; $string['setpassword'] = 'Set password'; $string['setpasswordinstructions'] = 'Please enter your new password below, then save changes.';
lib/moodlelib.php+7 −0 modified@@ -2757,6 +2757,13 @@ function require_login($courseorid = null, $autologinguest = true, $cm = null, $ // Make sure the USER has a sesskey set up. Used for CSRF protection. sesskey(); + if (\core\session\manager::is_loggedinas()) { + // During a "logged in as" session we should force all content to be cleaned because the + // logged in user will be viewing potentially malicious user generated content. + // See MDL-63786 for more details. + $CFG->forceclean = true; + } + // Do not bother admins with any formalities, except for activities pending deletion. if (is_siteadmin() && !($cm && $cm->deletioninprogress)) { // Set the global $COURSE.
Vulnerability mechanics
Generated on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
11- github.com/advisories/GHSA-qrcj-6fjw-3h9hghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2019-3847ghsaADVISORY
- www.securityfocus.com/bid/107489mitrevdb-entry
- bugzilla.redhat.com/show_bug.cgighsaWEB
- github.com/moodle/moodle/commit/070f24d006eab6b958eb083530de159b43c538edghsaWEB
- github.com/moodle/moodle/commit/93dda3bfd3caaaa8d23fe8ede543f27ef774958dghsaWEB
- github.com/moodle/moodle/commit/a37e26d2efe1ca0e4d8d69c611a748af35b33674ghsaWEB
- github.com/moodle/moodle/commit/e836242e1c04cd62d0afa4a790074fd245628e7aghsaWEB
- github.com/moodle/moodle/commit/ec3b63c772d6448765c68268234cf36c1a91bcacghsaWEB
- moodle.org/mod/forum/discuss.phpghsaWEB
- web.archive.org/web/20200227082922/http://www.securityfocus.com/bid/107489ghsaWEB
News mentions
0No linked articles in our index yet.