failIfDisallowedRange($trimmed, $fail); return; } if (filter_var($trimmed, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) { $this->failIfDisallowedRange($trimmed, $fail); return; } // Delegate hostname validation to ValidHostname $hostnameRule = new ValidHostname; $failed = false; $hostnameRule->validate($attribute, $trimmed, function () use (&$failed) { $failed = true; }); if ($failed) { $fail('The :attribute must be a valid IPv4 address, IPv6 address, or hostname.'); } } /** * Reject IPs in private/reserved ranges unless the operator has explicitly * opted in. The IP is already known to be a valid literal here. */ private function failIfDisallowedRange(string $ip, Closure $fail): void { if (config('coold.allow_private_server_ips')) { return; } $isPublic = filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ); if ($isPublic === false) { $fail('The :attribute must not be a private or reserved IP address.'); } } }