Skip to content

Commit

Permalink
MDL-61143 core_files: Check all A records when testing blocked IPs
Browse files Browse the repository at this point in the history
  • Loading branch information
cameorn1730 authored and Mr. Jenkins (CiBoT) committed Jan 9, 2018
1 parent 01a79b4 commit cae2eb3
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/classes/files/curl_security_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,19 @@ protected function host_is_blocked($host) {

// Only perform a forward lookup if there are IP rules to check against.
if ($blacklistedhosts['ipv4'] || $blacklistedhosts['ipv6']) {
$hostip = gethostbyname($host); // DNS forward lookup - only returns IPv4 addresses!
if ($hostip !== $host && $this->address_explicitly_blocked($hostip)) {
$hostips = gethostbynamel($host); // DNS forward lookup - returns a list of only IPv4 addresses!

// If we don't get a valid record, bail (so curl is never called).
if (!$hostips) {
return true;
}

// If any of the returned IPs are in the blacklist, block the request.
foreach ($hostips as $hostip) {
if ($this->address_explicitly_blocked($hostip)) {
return true;
}
}
}
}
return false;
Expand Down

0 comments on commit cae2eb3

Please sign in to comment.