Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions lib/Cleantalk/Common/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,33 @@ public static function ipResolve($ip)
*/
public static function dnsResolve($host, $out = false)
{
// Check if the $url is set and it is an url
if ( ! $host || ! filter_var($host, FILTER_VALIDATE_URL)) {
// Validate/normalize host (accept hostname or IP; URLs and host:port are also supported)
if ( ! $host || ! is_string($host) ) {
return $out;
}

if ( strpos($host, '://') !== false ) {
$parsed_host = parse_url($host, PHP_URL_HOST);
if ( is_string($parsed_host) && $parsed_host !== '' ) {
$host = $parsed_host;
}
}

if ( strpos($host, ':') !== false && ! filter_var($host, FILTER_VALIDATE_IP) ) {
$host = strstr($host, ':', true);
}

$is_ip = filter_var($host, FILTER_VALIDATE_IP);

if ( ! filter_var($host, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME)
&& ! $is_ip ) {
return $out;
}
Comment thread
alexander-b-clean marked this conversation as resolved.

if ( $is_ip ) {
return $host;
}

// Get DNS records about URL
if (function_exists('dns_get_record')) {
$records = dns_get_record($host, DNS_A);
Expand Down
Loading