Firewall - Aliases : tighten fqdn validation to avoid mistypes as 192.168.01.1 from being accepted as domain name.

This commit is contained in:
Ad Schellevis 2022-03-18 17:26:21 +01:00
parent 56bd1c33c2
commit 0ac674ceac

View File

@ -242,7 +242,13 @@ class Util
public static function isDomain($domain)
{
$pattern = '/^(?:(?:[a-z\pL0-9]|[a-z\pL0-9][a-z\pL0-9\-]*[a-z\pL0-9])\.)*(?:[a-z\pL0-9]|[a-z\pL0-9][a-z\pL0-9\-]*[a-z\pL0-9])$/iu';
if (preg_match($pattern, $domain)) {
$parts = explode(".", $domain);
if (ctype_digit($parts[0]) && ctype_digit($parts[count($parts)-1])) {
// according to rfc1123 2.1
// a valid host name can never have the dotted-decimal form #.#.#.#, since at least the highest-level
// component label will be alphabetic.
return false;
} elseif (preg_match($pattern, $domain)) {
return true;
}
return false;