Skip to content

Commit

Permalink
MDL-67861 core: Use last ip in X-Forwarded-For list
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanheywood authored and stronk7 committed Mar 5, 2020
1 parent eeaf8e0 commit 67c44eb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/moodlelib.php
Expand Up @@ -9037,7 +9037,10 @@ function getremoteaddr($default='0.0.0.0') {
if (!($variablestoskip & GETREMOTEADDR_SKIP_HTTP_X_FORWARDED_FOR)) {
if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$forwardedaddresses = explode(",", $_SERVER['HTTP_X_FORWARDED_FOR']);
$address = $forwardedaddresses[0];

// 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);

if (substr_count($address, ":") > 1) {
// Remove port and brackets from IPv6.
Expand Down

0 comments on commit 67c44eb

Please sign in to comment.