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

    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.

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

    Parameters

    NameTypeDescription
    url*str | AnyHttpUrl

    The URL to validate (string or Pydantic HttpUrl)

    allow_privatebool
    Default:False

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

    allow_httpbool
    Default:True

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

    View source on GitHub