EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
rename
Yuriif6c4839b1d0c
diff --git a/application/Espo/Classes/FieldValidators/Common/Host/NotInternal.php b/application/Espo/Classes/FieldValidators/Common/Host/NotInternal.phpindex 9e9a15c956..93785fe217 100644--- a/application/Espo/Classes/FieldValidators/Common/Host/NotInternal.php+++ b/application/Espo/Classes/FieldValidators/Common/Host/NotInternal.php@@ -53,7 +53,7 @@ class NotInternal implements Validatorreturn null;}- if (!$this->hostCheck->isNotInternalHost($value)) {+ if (!$this->hostCheck->isHostAndNotInternal($value)) {return Failure::create();}diff --git a/application/Espo/Classes/FieldValidators/Webhook/Url/NotInternal.php b/application/Espo/Classes/FieldValidators/Webhook/Url/NotInternal.phpindex 5dcdf31122..35c9f9c48a 100644--- a/application/Espo/Classes/FieldValidators/Webhook/Url/NotInternal.php+++ b/application/Espo/Classes/FieldValidators/Webhook/Url/NotInternal.php@@ -62,7 +62,7 @@ class NotInternal implements Validatorreturn null;}- if (!$this->urlCheck->isNotInternalUrl($value)) {+ if (!$this->urlCheck->isUrlAndNotIternal($value)) {return Failure::create();}diff --git a/application/Espo/Classes/RecordHooks/EmailAccount/BeforeSaveValidateHosts.php b/application/Espo/Classes/RecordHooks/EmailAccount/BeforeSaveValidateHosts.phpindex 70871645f2..30dc77502d 100644--- a/application/Espo/Classes/RecordHooks/EmailAccount/BeforeSaveValidateHosts.php+++ b/application/Espo/Classes/RecordHooks/EmailAccount/BeforeSaveValidateHosts.php@@ -76,7 +76,7 @@ class BeforeSaveValidateHosts implements SaveHookreturn;}- if (!$this->hostCheck->isNotInternalHost($host)) {+ if (!$this->hostCheck->isHostAndNotInternal($host)) {$message = $this->composeErrorMessage($host, $address);throw new Forbidden($message);@@ -101,7 +101,7 @@ class BeforeSaveValidateHosts implements SaveHookreturn;}- if (!$this->hostCheck->isNotInternalHost($host)) {+ if (!$this->hostCheck->isHostAndNotInternal($host)) {$message = $this->composeErrorMessage($host, $address);throw new Forbidden($message);diff --git a/application/Espo/Core/Mail/Account/GroupAccount/Service.php b/application/Espo/Core/Mail/Account/GroupAccount/Service.phpindex ec1ada0730..b6115de154 100644--- a/application/Espo/Core/Mail/Account/GroupAccount/Service.php+++ b/application/Espo/Core/Mail/Account/GroupAccount/Service.php@@ -89,7 +89,7 @@ class Serviceif ($params->getHost() &&!$this->addressUtil->isAllowedAddress($params) &&- !$this->hostCheck->isNotInternalHost($params->getHost())+ !$this->hostCheck->isHostAndNotInternal($params->getHost())) {throw new Forbidden("Not allowed internal host.");}@@ -124,7 +124,7 @@ class Serviceif ($params->getHost() &&!$this->addressUtil->isAllowedAddress($params) &&- !$this->hostCheck->isNotInternalHost($params->getHost())+ !$this->hostCheck->isHostAndNotInternal($params->getHost())) {throw new Forbidden("Not allowed internal host.");}diff --git a/application/Espo/Core/Mail/Account/PersonalAccount/Service.php b/application/Espo/Core/Mail/Account/PersonalAccount/Service.phpindex 3e3712df29..89a747ee7f 100644--- a/application/Espo/Core/Mail/Account/PersonalAccount/Service.php+++ b/application/Espo/Core/Mail/Account/PersonalAccount/Service.php@@ -103,7 +103,7 @@ class Serviceif ($params->getHost() &&!$this->addressUtil->isAllowedAddress($params) &&- !$this->hostCheck->isNotInternalHost($params->getHost())+ !$this->hostCheck->isHostAndNotInternal($params->getHost())) {throw new Forbidden("Not allowed internal host.");}@@ -144,7 +144,7 @@ class Serviceif ($params->getHost() &&!$this->addressUtil->isAllowedAddress($params) &&- !$this->hostCheck->isNotInternalHost($params->getHost())+ !$this->hostCheck->isHostAndNotInternal($params->getHost())) {throw new Forbidden("Not allowed host.");}diff --git a/application/Espo/Core/Utils/Security/HostCheck.php b/application/Espo/Core/Utils/Security/HostCheck.phpindex 74e82644fb..0bbc8f3677 100644--- a/application/Espo/Core/Utils/Security/HostCheck.php+++ b/application/Espo/Core/Utils/Security/HostCheck.php@@ -32,18 +32,30 @@ namespace Espo\Core\Utils\Security;use const DNS_A;use const FILTER_FLAG_NO_PRIV_RANGE;use const FILTER_FLAG_NO_RES_RANGE;+use const FILTER_FLAG_HOSTNAME;+use const FILTER_VALIDATE_DOMAIN;use const FILTER_VALIDATE_IP;class HostCheck{- public function isNotInternalHost(string $host): bool+ /**+ * Validates the string is a host and it's not internal.+ * If not a host, returns false.+ *+ * @since 9.3.4+ */+ public function isHostAndNotInternal(string $host): bool{- $records = dns_get_record($host, DNS_A);-if (filter_var($host, FILTER_VALIDATE_IP)) {return $this->ipAddressIsNotInternal($host);}+ if (!filter_var($host, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)) {+ return false;+ }++ $records = dns_get_record($host, DNS_A);+if (!$records) {return true;}@@ -72,4 +84,13 @@ class HostCheckFILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE);}++ /**+ * @deprecated Since 9.3.4. Use `isHostAndNotInternal`.+ * @todo Remove in 9.4.0.+ */+ public function isNotInternalHost(string $host): bool+ {+ return $this->isHostAndNotInternal($host);+ }}diff --git a/application/Espo/Core/Utils/Security/UrlCheck.php b/application/Espo/Core/Utils/Security/UrlCheck.phpindex 2fe60b70f4..9a89787d2f 100644--- a/application/Espo/Core/Utils/Security/UrlCheck.php+++ b/application/Espo/Core/Utils/Security/UrlCheck.php@@ -46,7 +46,7 @@ class UrlCheck/*** Checks whether a URL does not follow to an internal host.*/- public function isNotInternalUrl(string $url): bool+ public function isUrlAndNotIternal(string $url): bool{if (!$this->isUrl($url)) {return false;@@ -58,6 +58,6 @@ class UrlCheckreturn false;}- return $this->hostCheck->isNotInternalHost($host);+ return $this->hostCheck->isHostAndNotInternal($host);}}diff --git a/application/Espo/Core/Webhook/Sender.php b/application/Espo/Core/Webhook/Sender.phpindex 23c3b1cac3..b810449033 100644--- a/application/Espo/Core/Webhook/Sender.php+++ b/application/Espo/Core/Webhook/Sender.php@@ -95,7 +95,7 @@ class Senderif (!$this->addressUtil->isAllowedUrl($url) &&- !$this->urlCheck->isNotInternalUrl($url)+ !$this->urlCheck->isUrlAndNotIternal($url)) {throw new Error("URL '$url' points to an internal host, not allowed.");}diff --git a/application/Espo/Tools/Attachment/UploadUrlService.php b/application/Espo/Tools/Attachment/UploadUrlService.phpindex 567db3b700..e0d73b7f3a 100644--- a/application/Espo/Tools/Attachment/UploadUrlService.php+++ b/application/Espo/Tools/Attachment/UploadUrlService.php@@ -72,7 +72,7 @@ class UploadUrlService*/public function uploadImage(string $url, FieldData $data): Attachment{- if (!$this->urlCheck->isNotInternalUrl($url)) {+ if (!$this->urlCheck->isUrlAndNotIternal($url)) {throw new ForbiddenSilent("Not allowed URL.");}diff --git a/application/Espo/Tools/Email/Api/PostSendTest.php b/application/Espo/Tools/Email/Api/PostSendTest.phpindex 4c1f5998b9..320a39968f 100644--- a/application/Espo/Tools/Email/Api/PostSendTest.php+++ b/application/Espo/Tools/Email/Api/PostSendTest.php@@ -115,7 +115,7 @@ class PostSendTest implements Actionif (!$this->addressUtil->isAllowedAddress($smtpParams) &&- !$this->hostCheck->isNotInternalHost($server)+ !$this->hostCheck->isHostAndNotInternal($server)) {throw new Forbidden("Not allowed internal host.");}