Description
For a maintenance mode whitelist I would need to set also a subnet IP
A normal IP, like 5.146.197.42, represents one single device or host.
5.146.197.0/24 represents a range of IP addresses — specifically, all IPs from:
=> 5.146.197.0 to 5.146.197.255
Existing Validation:ip() would fail here for that.
We can either
- add a new rule for subnet/mask alone
- adjust the existing rule to allow subnets with feature flag toggle
maybe?
$type could be used to be set to subnet, or an additional bool flag.
Something along the lines of
// Check for plain IP first (IPv4 or IPv6)
if (filter_var($input, FILTER_VALIDATE_IP)) {
return true;
}
// Check for CIDR format
if (str_contains($input, '/')) {
[$ip, $mask] = explode('/', $input, 2);
// Validate IP part
if (!filter_var($ip, FILTER_VALIDATE_IP)) {
return false;
}
// Validate mask part (IPv4: 0-32, IPv6: 0-128)
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
return is_numeric($mask) && $mask >= 0 && $mask <= 32;
}
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
return is_numeric($mask) && $mask >= 0 && $mask <= 128;
}
}
return false;
CakePHP Version
5.2
Description
For a maintenance mode whitelist I would need to set also a subnet IP
A normal IP, like 5.146.197.42, represents one single device or host.
5.146.197.0/24 represents a range of IP addresses — specifically, all IPs from:
=> 5.146.197.0 to 5.146.197.255
Existing Validation:ip() would fail here for that.
We can either
maybe?
$type could be used to be set to
subnet, or an additional bool flag.Something along the lines of
CakePHP Version
5.2