MDL-83762 core_files: Bind resolve IPs and ports to cURL calls

This commit is contained in:
Michael Hawkins
2025-06-05 12:09:50 +07:00
committed by Huong Nguyen
parent ac62ce580c
commit 4ecfbc393d
2 changed files with 64 additions and 2 deletions
+13
View File
@@ -3169,6 +3169,8 @@ class curl {
private $ignoresecurity;
/** @var array $mockresponses For unit testing only - return the head of this list instead of making the next request. */
private static $mockresponses = [];
/** @var array $curlresolveinfo Resolve addresses for the URL that have passed cuRL security checks, in a CURLOPT_RESOLVE compatible format. */
private $curlresolveinfo = [];
/** @var array temporary params value if the value is not belongs to class stored_file. */
public $_tmp_file_post_params = [];
@@ -3766,6 +3768,9 @@ class curl {
return $this->error;
}
// Set allowed resolve info if the URL is not blocked.
$this->curlresolveinfo = $this->securityhelper->get_resolve_info();
return null;
}
@@ -3802,6 +3807,10 @@ class curl {
// Set the URL as a curl option.
$this->setopt(array('CURLOPT_URL' => $url));
// Force cURL to only resolve the URL from IP/port combinations that were validated by the security helper.
// This prevents re-fetching DNS data on subsequent requests, which could return un-validated hosts/ports.
$this->setopt(['CURLOPT_RESOLVE' => $this->curlresolveinfo]);
// Create curl instance.
$curl = curl_init();
@@ -3913,6 +3922,10 @@ class curl {
curl_setopt($curl, CURLOPT_URL, $redirecturl);
// Force cURL to only resolve the URL from IP/port combinations that were validated by the security helper.
// This prevents re-fetching DNS data on subsequent requests, which could return un-validated hosts/ports.
$this->setopt(['CURLOPT_RESOLVE' => $this->curlresolveinfo]);
// If CURLOPT_UNRESTRICTED_AUTH is empty/false, don't send credentials to other hosts.
// Ref: https://curl.se/libcurl/c/CURLOPT_UNRESTRICTED_AUTH.html.
$isdifferenthost = parse_url($currenturl)['host'] !== parse_url($redirecturl)['host'];