EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
forbid only digits host names
Yurii3fcb5bb2f414
diff --git a/application/Espo/Core/Utils/Security/HostCheck.php b/application/Espo/Core/Utils/Security/HostCheck.phpindex 6297293300..111420819d 100644--- a/application/Espo/Core/Utils/Security/HostCheck.php+++ b/application/Espo/Core/Utils/Security/HostCheck.php@@ -60,6 +60,10 @@ class HostCheckreturn false;}+ if (!$this->hasNoNumericItem($host)) {+ return false;+ }+$records = dns_get_record($host, DNS_A);if (!$records) {@@ -155,4 +159,20 @@ class HostCheckreturn long2ip($num);}+++ private function hasNoNumericItem(string $host): bool+ {+ $hasNoNumeric = false;++ foreach (explode('.', $host) as $it) {+ if (!is_numeric($it)) {+ $hasNoNumeric = true;++ break;+ }+ }++ return $hasNoNumeric;+ }}diff --git a/tests/unit/Espo/Core/Utils/Security/HostCheckTest.php b/tests/unit/Espo/Core/Utils/Security/HostCheckTest.phpindex 7ebd448b67..666fc3f713 100644--- a/tests/unit/Espo/Core/Utils/Security/HostCheckTest.php+++ b/tests/unit/Espo/Core/Utils/Security/HostCheckTest.php@@ -50,13 +50,17 @@ class HostCheckTest extends TestCase$hostCheck->isHostAndNotInternal('0177.0.0.1'));- /*$this->assertFalse(+ $this->assertFalse($hostCheck->isHostAndNotInternal('127.1'));$this->assertFalse($hostCheck->isHostAndNotInternal('127.0.1')- );*/+ );++ $this->assertFalse(+ $hostCheck->isHostAndNotInternal('2130706433')+ );$this->assertFalse($hostCheck->isHostAndNotInternal('0x7f000001')