"""Security utility functions."""

import ipaddress

import structlog

logger = structlog.get_logger()


def is_internal_request(client_ip: str, internal_cidrs: list[str]) -> bool:
    """Check if request comes from internal network"""
    try:
        client_addr = ipaddress.ip_address(client_ip)
        for cidr in internal_cidrs:
            if client_addr in ipaddress.ip_network(cidr):
                return True
        return False
    except ValueError:
        logger.warning("Invalid client IP address", client_ip=client_ip)
        return False
