Home / Function/ is_localhost() — langchain Function Reference

is_localhost() — langchain Function Reference

Architecture documentation for the is_localhost() function in _ssrf_protection.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  1360012e_a2fc_367c_8e20_7b85ad1e7484["is_localhost()"]
  76eef743_34da_b2b6_eda1_09a024269dbd["_ssrf_protection.py"]
  1360012e_a2fc_367c_8e20_7b85ad1e7484 -->|defined in| 76eef743_34da_b2b6_eda1_09a024269dbd
  6c828a82_ad0c_f5f1_d776_92c196a03eaf["validate_safe_url()"]
  6c828a82_ad0c_f5f1_d776_92c196a03eaf -->|calls| 1360012e_a2fc_367c_8e20_7b85ad1e7484
  style 1360012e_a2fc_367c_8e20_7b85ad1e7484 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/core/langchain_core/_security/_ssrf_protection.py lines 108–135

def is_localhost(hostname: str, ip_str: str | None = None) -> bool:
    """Check if hostname or IP is localhost.

    Args:
        hostname: Hostname to check
        ip_str: Optional IP address to check

    Returns:
        True if hostname or IP is localhost
    """
    # Check hostname
    if hostname.lower() in LOCALHOST_NAMES:
        return True

    # Check IP
    if ip_str:
        try:
            ip = ipaddress.ip_address(ip_str)
            # Check if loopback
            if ip.is_loopback:
                return True
            # Also check common localhost IPs
            if ip_str in ("127.0.0.1", "::1", "0.0.0.0"):  # noqa: S104
                return True
        except ValueError:
            pass

    return False

Domain

Subdomains

Frequently Asked Questions

What does is_localhost() do?
is_localhost() is a function in the langchain codebase, defined in libs/core/langchain_core/_security/_ssrf_protection.py.
Where is is_localhost() defined?
is_localhost() is defined in libs/core/langchain_core/_security/_ssrf_protection.py at line 108.
What calls is_localhost()?
is_localhost() is called by 1 function(s): validate_safe_url.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free