isBlockedAddress function

bool isBlockedAddress(
  1. String address
)

Returns true if the address is in a range that HTTP hooks should not reach. Loopback (127.0.0.0/8, ::1) is intentionally ALLOWED for local dev hooks.

Implementation

bool isBlockedAddress(String address) {
  // Simple IPv4 check
  final v4Parts = address.split('.');
  if (v4Parts.length == 4) {
    final nums = v4Parts.map(int.tryParse).toList();
    if (nums.every((n) => n != null)) {
      return _isBlockedV4(nums.cast<int>());
    }
  }

  // IPv6 check
  final lower = address.toLowerCase();
  if (lower == '::1') return false; // loopback allowed
  if (lower == '::') return true; // unspecified

  // fc00::/7 unique local
  if (lower.startsWith('fc') || lower.startsWith('fd')) return true;

  // fe80::/10 link-local
  final firstHextet = lower.split(':').first;
  if (firstHextet.length == 4) {
    final val = int.tryParse(firstHextet, radix: 16);
    if (val != null && val >= 0xfe80 && val <= 0xfebf) return true;
  }

  return false;
}