fix ip validation rule when querying an IPv6 target

This commit is contained in:
thatmattlove 2024-03-19 23:27:38 -04:00
parent a8476f2ea9
commit 5d39ff054f

View file

@ -91,7 +91,7 @@ class Rule(HyperglassModel):
class RuleWithIP(Rule): class RuleWithIP(Rule):
"""Base IP-based rule.""" """Base IP-based rule."""
condition: IPvAnyNetwork condition: t.Union[IPv4Network, IPv6Network]
allow_reserved: bool = False allow_reserved: bool = False
allow_unspecified: bool = False allow_unspecified: bool = False
allow_loopback: bool = False allow_loopback: bool = False
@ -140,6 +140,10 @@ class RuleWithIP(Rule):
except ValueError as err: except ValueError as err:
raise InputValidationError(error=str(err), target=target) from err raise InputValidationError(error=str(err), target=target) from err
if valid_target.version != self.condition.version:
log.debug("{!s} is not the same IP version as {!s}", target, self.condition)
return False
is_member = self.membership(valid_target, self.condition) is_member = self.membership(valid_target, self.condition)
in_range = self.in_range(valid_target) in_range = self.in_range(valid_target)