From 7fe8b9e44833208f49b634366e97f6cd46ba245b Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Fri, 23 Feb 2024 15:40:37 +0700 Subject: [PATCH] MDL-81035 core: Fix redirect with sub-path --- lib/setuplib.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/setuplib.php b/lib/setuplib.php index 54098518464..f040944b32a 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -888,7 +888,13 @@ function initialise_fullme() { throw new moodle_exception('requirecorrectaccess', 'error', '', null, 'You called ' . $calledurl .', you should have called ' . $correcturl); } - redirect($CFG->wwwroot . $rurl['fullpath'], get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3); + $rfullpath = $rurl['fullpath']; + // Check that URL is under $CFG->wwwroot. + if (strpos($rfullpath, $wwwroot['path']) === 0) { + $rfullpath = substr($rurl['fullpath'], strlen($wwwroot['path']) - 1); + $rfullpath = (new moodle_url($rfullpath))->out(false); + } + redirect($rfullpath, get_string('wwwrootmismatch', 'error', $CFG->wwwroot), 3); } }