Skip to content

Commit

Permalink
fixed ipv6 validation error
Browse files Browse the repository at this point in the history
  • Loading branch information
ph0llux committed Jul 19, 2023
1 parent b036987 commit e7757b1
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/Ravada/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,24 @@ Mandatory arguments: one of those must be passed:
=cut


sub is_valid_ip {
my ($ip) = @_;

# Check for IPv4 address
if ($ip =~ /^(localhost|\d+\.\d+\.\d+\.\d+)$/) {
return 1;
}

# Check for IPv6 address
if ($ip =~ /^(?:(?:(?:[0-9A-Fa-f]{1,4}:){6}(?:[0-9A-Fa-f]{1,4})?|(?=(?:[0-9A-Fa-f]{0,4}:){0,6}(?:[0-9A-Fa-f]{0,4})?$)(?:(?:(?!0000:)[0-9A-Fa-f]{1,4}:?){0,5}[0-9A-Fa-f]{0,4})?::(?:[0-9A-Fa-f]{1,4}:?){0,5}[0-9A-Fa-f]{0,4}|(?:[0-9A-Fa-f]{1,4}:){0,5}:|[0-9A-Fa-f]{1,4}:){1,7}:[0-9A-Fa-f]{0,4})$/i) {
return 1;
}

return 0;
}


sub start_domain {
my $proto = shift;
my $class=ref($proto) || $proto;
Expand All @@ -443,7 +461,7 @@ sub start_domain {
if $args->{id_domain} && $args->{name};

confess "Error: remote ip invalid '$args->{remote_ip}'"
if $args->{remote_ip} && $args->{remote_ip} !~ /^(localhost|\d+\.\d+\.\d+\.\d+)$/;
if ($args->{remote_ip} && !is_valid_ip($args->{remote_ip}));

_remove_low_priority_requests($args->{id_domain} or $args->{name});

Expand Down

0 comments on commit e7757b1

Please sign in to comment.