Skip to main content

httpx-secure

PyPI - Python Version

Drop-in SSRF protection for httpx.

Why Use This?

  • SSRF Protection: Block requests to private/internal IP addresses
  • Custom Validation: Extend with your own validation logic
  • Minimal Overhead: Efficient implementation with built-in DNS caching
  • Broad Python Support: Compatible with Python 3.9+
  • Semantic Versioning: Predictable, reliable updates
  • Zero-Clause BSD: Public domain, use freely anywhere

Installation

pip install httpx-secure

Quick Start

import httpx
from httpx_secure import httpx_ssrf_protection

client = httpx_ssrf_protection(
    httpx.AsyncClient(),
    dns_cache_size=1000,  # Cache up to 1000 DNS resolutions
    dns_cache_ttl=600,    # Cache for 10 minutes
)

await client.get("https://public.domain")   # Allowed
await client.get("https://private.domain")  # Blocked

Custom Validation

For example, implement a simple domain whitelist to restrict requests to specific hosts:

import httpx
from httpx_secure import httpx_ssrf_protection
from ipaddress import IPv4Address, IPv6Address

def custom_validator(
    hostname: str,
    ip: IPv4Address | IPv6Address,
    port: int
) -> bool:
    return hostname in {
        "whitelisted.domain",
        "webhook.partner.com",
    }

client = httpx_ssrf_protection(
    httpx.AsyncClient(),
    custom_validator=custom_validator,
)

await client.get("https://whitelisted.domain")  # Allowed
await client.get("https://unknown.domain")      # Blocked

How It Works

  1. Cache Lookup: First checks if the host has been recently validated and cached
  2. DNS Resolution: If not cached, resolves the hostname to an IP address
  3. Validation: Verifies the IP is globally routable, blocking private/internal addresses
  4. Custom Validation: If provided, your custom validator is called for additional checks
  5. Request Modification: Rewrites the request to use the validated IP directly

The DNS cache significantly reduces latency for repeated requests, while per-host locking ensures efficient concurrent resolution of parallel requests.

[!TIP] The SSRF protection applies to all HTTP methods (GET, POST, PUT, DELETE, etc.) and automatically validates redirects to prevent SSRF attacks through redirect chains.

Metadata

Release files for httpx-secure 1.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for httpx-secure 1.3.0
File Size Uploaded
httpx_secure-1.3.0.tar.gz 9.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for httpx-secure 1.3.0
File Interpreter ABI Platform
httpx_secure-1.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.6 kB

Release files / httpx_secure-1.3.0.tar.gz

Download URL httpx_secure-1.3.0.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b076ab3551c5e7f7b92d092c234e010e230832800ec4142d4186666fb88bb449
BLAKE2b-256 checksum
How to use checksums
ee112586dd9ce949839544416b8e047b87e1ab4349e5a460711c396a61e74f4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 19, 2026.

Transparency log

Release files / httpx_secure-1.3.0-py3-none-any.whl

Download URL httpx_secure-1.3.0-py3-none-any.whl
Size 5.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
913478890e086a2fd14b80e603116ace22e229d88562b82314a3be76d5c38279
BLAKE2b-256 checksum
How to use checksums
5e44c14ee9449b1c09e0d5e1014a90ad2cf3b6feeb3d56887acde5370ce3821e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 19, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.3.0 This release

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page