From 1983718149b5daadf193babf3ac408eb501330a5 Mon Sep 17 00:00:00 2001 From: Dmitri Pisarev Date: Tue, 22 Jan 2019 11:09:26 +0300 Subject: [PATCH 1/2] MDL-63770 core: Fix a false-positive in `reverseproxyabused` check A `reverseproxyabused` error is wrongly triggered when external port number doesn't equal internal. --- lib/setuplib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/setuplib.php b/lib/setuplib.php index da146429b41..64dba6498fd 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -899,7 +899,7 @@ function initialise_fullme() { // hopefully this will stop all those "clever" admins trying to set up moodle // with two different addresses in intranet and Internet - if (!empty($CFG->reverseproxy) && $rurl['host'] === $wwwroot['host']) { + if (!empty($CFG->reverseproxy) && $rurl['host'] === $wwwroot['host'] && (empty($wwwroot['port']) || $rurl['port'] === $wwwroot['port'])) { print_error('reverseproxyabused', 'error'); } From 7910fa322acade7210aa55e577f81509d3cd8faa Mon Sep 17 00:00:00 2001 From: Matteo Scaramuccia Date: Sun, 3 May 2020 23:46:18 +0200 Subject: [PATCH 2/2] MDL-63770 core: 'port' should be an integer like in parse_url() Plus trivial comment cleanup. --- lib/setuplib.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/setuplib.php b/lib/setuplib.php index 64dba6498fd..2af28136af9 100644 --- a/lib/setuplib.php +++ b/lib/setuplib.php @@ -897,8 +897,9 @@ function initialise_fullme() { $_SERVER['SERVER_PORT'] = 443; // Assume default ssl port for the proxy. } - // hopefully this will stop all those "clever" admins trying to set up moodle - // with two different addresses in intranet and Internet + // Hopefully this will stop all those "clever" admins trying to set up moodle + // with two different addresses in intranet and Internet. + // Port forwarding is still allowed! if (!empty($CFG->reverseproxy) && $rurl['host'] === $wwwroot['host'] && (empty($wwwroot['port']) || $rurl['port'] === $wwwroot['port'])) { print_error('reverseproxyabused', 'error'); } @@ -950,7 +951,7 @@ function setup_get_remote_url() { } else { $rurl['host'] = null; } - $rurl['port'] = $_SERVER['SERVER_PORT']; + $rurl['port'] = (int)$_SERVER['SERVER_PORT']; $rurl['path'] = $_SERVER['SCRIPT_NAME']; // Script path without slash arguments $rurl['scheme'] = (empty($_SERVER['HTTPS']) or $_SERVER['HTTPS'] === 'off' or $_SERVER['HTTPS'] === 'Off' or $_SERVER['HTTPS'] === 'OFF') ? 'http' : 'https';