Skip to content

Commit 425cb9d

Browse files
Fix IPv4 private IP detection with CIDR notation
- Extract IP address part from CIDR notation before checking if private - Fixes validation of addresses like "192.168.1.0/24" with private parameter - Prevents incorrect private/public detection when subnet mask is included
1 parent 78dee18 commit 425cb9d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/validators/ip_address.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ def ipv4(
8888
if cidr:
8989
if strict and value.count("/") != 1:
9090
raise ValueError("IPv4 address was expected in CIDR notation")
91-
return IPv4Network(value, strict=not host_bit) and _check_private_ip(value, private)
91+
# Extract IP part for private check when using CIDR notation
92+
ip_part = value.split('/')[0] if '/' in value else value
93+
return IPv4Network(value, strict=not host_bit) and _check_private_ip(ip_part, private)
9294
return IPv4Address(value) and _check_private_ip(value, private)
9395
except (ValueError, AddressValueError, NetmaskValueError):
9496
return False

0 commit comments

Comments
 (0)