Skip to content

Commit

Permalink
MDL-67861 core: Added $CFG->reverseproxyignore IP subnet list
Browse files Browse the repository at this point in the history
If your server is behind multiple reverse proxies that append to the
X-Forwarded-For header then you will need to specify a comma separated
list of ip addresses or subnets of the reverse proxies to be ignored
in order to find the users correct IP address.
  • Loading branch information
brendanheywood authored and stronk7 committed Mar 5, 2020
1 parent e6e07e0 commit 7251f15
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions admin/settings/server.php
Expand Up @@ -101,6 +101,7 @@
$temp->add(new admin_setting_configselect('getremoteaddrconf', new lang_string('getremoteaddrconf', 'admin'),
new lang_string('configgetremoteaddrconf', 'admin'),
GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR|GETREMOTEADDR_SKIP_HTTP_CLIENT_IP, $options));
$temp->add(new admin_setting_configtext('reverseproxyignore', new lang_string('reverseproxyignore', 'admin'), new lang_string('configreverseproxyignore', 'admin'), ''));

$temp->add(new admin_setting_heading('webproxy', new lang_string('webproxy', 'admin'), new lang_string('webproxyinfo', 'admin')));
$temp->add(new admin_setting_configtext('proxyhost', new lang_string('proxyhost', 'admin'), new lang_string('configproxyhost', 'admin'), '', PARAM_HOST));
Expand Down
2 changes: 2 additions & 0 deletions lang/en/admin.php
Expand Up @@ -315,6 +315,7 @@
$string['configrequestedstudentsname'] = 'Word for students used in requested courses';
$string['configrequestedteachername'] = 'Word for teacher used in requested courses';
$string['configrequestedteachersname'] = 'Word for teachers used in requested courses';
$string['configreverseproxyignore'] = 'If your server is behind multiple reverse proxies that append to the X-Forwarded-For header then you will need to specify a comma separated list of ip addresses or subnets of the reverse proxies to be ignored in order to find the users correct IP address.';
$string['configuserquota'] = 'The maximum number of bytes that a user can store in their own private file area. {$a->bytes} bytes == {$a->displaysize}';
$string['configsectioninterface'] = 'Interface';
$string['configsectionmail'] = 'Mail';
Expand Down Expand Up @@ -988,6 +989,7 @@
$string['restorernewroleid'] = 'Restorers\' role in courses';
$string['restorernewroleid_help'] = 'If the user does not already have the permission to manage the newly restored course, the user is automatically assigned this role and enrolled if necessary. Select "None" if you do not want restorers to be able to manage every restored course.';
$string['reverseproxy'] = 'Reverse proxy';
$string['reverseproxyignore'] = 'Ignore reverse proxies';
$string['riskconfig'] = 'Users could change site configuration and behaviour';
$string['riskconfigshort'] = 'Configuration risk';
$string['riskdataloss'] = 'Users could destroy large amounts of content or information';
Expand Down
5 changes: 5 additions & 0 deletions lib/moodlelib.php
Expand Up @@ -9028,6 +9028,11 @@ function getremoteaddr($default='0.0.0.0') {
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$forwardedaddresses = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);

$forwardedaddresses = array_filter($forwardedaddresses, function($ip) {
global $CFG;
return !\core\ip_utils::is_ip_in_subnet_list($ip, $CFG->reverseproxyignore, ',');
});

// Multiple proxies can append values to this header including an
// untrusted original request header so we must only trust the last ip.
$address = end($forwardedaddresses);
Expand Down

0 comments on commit 7251f15

Please sign in to comment.