EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
url check webhook
Yurii50f07e2da1c0
diff --git a/application/Espo/Core/Utils/Security/UrlCheck.php b/application/Espo/Core/Utils/Security/UrlCheck.phpindex 2a12ea00fc..8ddd937173 100644--- a/application/Espo/Core/Utils/Security/UrlCheck.php+++ b/application/Espo/Core/Utils/Security/UrlCheck.php@@ -130,14 +130,17 @@ class UrlCheck/*** @param string[] $resolve+ * @param string[] $allowed An allowed address list in the `{host}:{port}` format.* @internal*/- public function validateCurlResolveNotInternal(array $resolve): bool+ public function validateCurlResolveNotInternal(array $resolve, array $allowed = []): bool{if ($resolve === []) {return false;}+ $ipAddresses = [];+foreach ($resolve as $item) {$arr = explode(':', $item, 3);@@ -146,11 +149,21 @@ class UrlCheck}$ipAddress = $arr[2];+ $port = $arr[1];+ $domain = $arr[0];++ if (in_array("$ipAddress:$port", $allowed) || in_array("$domain:$port", $allowed)) {+ return true;+ }if (str_starts_with($ipAddress, '[') && str_ends_with($ipAddress, ']')) {$ipAddress = substr($ipAddress, 1, -1);}+ $ipAddresses[] = $ipAddress;+ }++ foreach ($ipAddresses as $ipAddress) {if (!$this->hostCheck->ipAddressIsNotInternal($ipAddress)) {return false;}diff --git a/application/Espo/Core/Webhook/Sender.php b/application/Espo/Core/Webhook/Sender.phpindex b810449033..55a7827840 100644--- a/application/Espo/Core/Webhook/Sender.php+++ b/application/Espo/Core/Webhook/Sender.php@@ -100,6 +100,19 @@ class Senderthrow new Error("URL '$url' points to an internal host, not allowed.");}+ $resolve = $this->urlCheck->getCurlResolve($url);++ if ($resolve === []) {+ throw new Error("Could not resolve the host.");+ }++ /** @var string[] $allowedAddressList */+ $allowedAddressList = $this->config->get('webhookAllowedAddressList') ?? [];++ if ($resolve !== null && !$this->urlCheck->validateCurlResolveNotInternal($resolve, $allowedAddressList)) {+ throw new Error("Forbidden host.");+ }+$handler = curl_init($url);if ($handler === false) {@@ -118,6 +131,10 @@ class Sendercurl_setopt($handler, \CURLOPT_HTTPHEADER, $headerList);curl_setopt($handler, \CURLOPT_POSTFIELDS, $payload);+ if ($resolve) {+ curl_setopt($handler, CURLOPT_RESOLVE, $resolve);+ }+curl_exec($handler);$code = curl_getinfo($handler, \CURLINFO_HTTP_CODE);