Overview
TheValidResourceAddress validation rule ensures that resource addresses are valid and do not include dangerous or blocked address ranges. This rule accepts:
- Valid IPv4 addresses
- Valid IPv6 addresses
- Valid CIDR notation (IPv4 and IPv6)
- Valid domain names (including wildcard domains like
*.example.com)
Blocked CIDR Ranges
The following CIDR ranges are explicitly blocked for security reasons:All IPv4 traffic - blocks the entire IPv4 address space
All IPv6 traffic - blocks the entire IPv6 address space
Half of all IPv4 traffic (0.0.0.0 - 127.255.255.255)
Other half of all IPv4 traffic (128.0.0.0 - 255.255.255.255)
Private network (Class A) - RFC 1918
Private network (Class B) - RFC 1918
Private network (Class C) - RFC 1918
Loopback addresses
Link-local addresses
Multicast addresses
Reserved addresses
Broadcast address
Blocked Wildcard Patterns
The following wildcard patterns are also blocked:**.*.**.*.**.*.*.*
These wildcards would match everything and are therefore considered dangerous.
Validation Methods
isValidIpv4()
Validates IPv4 addresses using PHP’sfilter_var() with FILTER_VALIDATE_IP and FILTER_FLAG_IPV4.
192.0.2.18.8.8.8203.0.113.42
isValidIpv6()
Validates IPv6 addresses using PHP’sfilter_var() with FILTER_VALIDATE_IP and FILTER_FLAG_IPV6.
2001:db8::12001:0db8:85a3::8a2e:0370:7334fe80::1
isValidCidr()
Validates CIDR notation for both IPv4 and IPv6 addresses. Ensures:- The value contains a
/separator - The prefix is numeric
- IPv4 CIDR prefixes are between 0 and 32
- IPv6 CIDR prefixes are between 0 and 128
192.0.2.0/24203.0.113.0/252001:db8::/32
isValidDomain()
Validates domain names with the following rules:- Allows wildcard domains (e.g.,
*.example.com) - Must contain at least one dot
- Only alphanumeric characters, hyphens, and dots allowed
- No double dots (
..) - Maximum length of 253 characters
- Each label (part between dots) maximum 63 characters
- Must end with a valid TLD (minimum 2 characters)
example.comsubdomain.example.com*.example.comapi-v2.service.example.com
isBlockedAddress()
Checks if the provided address matches any blocked CIDR range or wildcard pattern. The comparison is case-insensitive.Usage in Laravel Validation
Basic Usage
Multiple Addresses
Example Validation Scenarios
Valid Addresses
| Address | Type | Description |
|---|---|---|
8.8.8.8 | IPv4 | Google DNS |
2001:4860:4860::8888 | IPv6 | Google DNS IPv6 |
203.0.113.0/24 | CIDR | Documentation network |
example.com | Domain | Standard domain |
*.example.com | Wildcard Domain | Wildcard subdomain |
Invalid Addresses
| Address | Reason |
|---|---|
0.0.0.0/0 | Blocked CIDR (all IPv4 traffic) |
10.0.0.1 | Valid IPv4 but in private range |
10.0.0.0/8 | Blocked CIDR (private network) |
192.168.1.1 | Valid IPv4 but in private range |
127.0.0.1 | Valid IPv4 but loopback address |
* | Blocked wildcard |
*.*.*.* | Blocked wildcard |
invalid..com | Double dots in domain |
256.1.1.1 | Invalid IPv4 (out of range) |
192.0.2.0/33 | Invalid CIDR prefix (>32) |
-example.com | Invalid domain (starts with hyphen) |
Error Messages
The validation rule returns the following error messages:Message:
The :attribute is required.Returned when the value is empty or contains only whitespace.Message:
The :attribute contains a blocked or dangerous address range.Returned when the address matches a blocked CIDR range or wildcard pattern.Message:
The :attribute must be a valid IP address, CIDR notation, or domain name.Returned when the value is not a valid IPv4, IPv6, CIDR, or domain name.Security Rationale
Why Block Private Networks?
Private network ranges (RFC 1918) are blocked to prevent:- Access to internal infrastructure
- Routing to local network resources
- Potential network scanning or reconnaissance
- Bypassing network security controls
Why Block Loopback and Link-Local?
- Loopback (127.0.0.0/8): Prevents access to localhost services
- Link-local (169.254.0.0/16): Prevents access to auto-configured network interfaces
Why Block Broadcast and Multicast?
- Broadcast (255.255.255.255/32): Would send traffic to all devices
- Multicast (224.0.0.0/4): Could affect multiple network hosts
Why Block Wide-Ranging CIDRs?
Blocking 0.0.0.0/0, ::/0, and other extremely broad ranges prevents:- Routing all traffic through a single resource
- Unintentional network-wide impact
- Denial of service scenarios
- Resource exhaustion
This validation rule is specifically designed for NetBird resources where precision is critical. Only publicly routable, specific addresses should be allowed.
Implementation Details
The validation rule implements Laravel’sValidationRule interface: