LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-core_security_ssrf_protectionvalidate_safe_url
    Functionā—Since v1.2

    validate_safe_url

    Copy
    validate_safe_url(
      url: str | AnyHttpUrl,
      *,
      allow_private: bool = False,
      allow_http: bool
    View source on GitHub
    =
    True
    )
    ->
    str

    Parameters

    NameTypeDescription
    url*str | AnyHttpUrl
    allow_privatebool
    Default:False
    allow_httpbool
    Default:True

    Validate a URL for SSRF protection.

    This function validates URLs to prevent Server-Side Request Forgery (SSRF) attacks by blocking requests to private networks and cloud metadata endpoints.

    The URL to validate (string or Pydantic HttpUrl).

    If True, allows private IPs and localhost (for development). Cloud metadata endpoints are ALWAYS blocked.

    If True, allows both HTTP and HTTPS. If False, only HTTPS.